-
Notifications
You must be signed in to change notification settings - Fork 131
/
test_collection_inputs.py
145 lines (112 loc) · 3.49 KB
/
test_collection_inputs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import numpy as np # only run this test suite if numpy is installed
import pytest
from h3.api import (
basic_int,
numpy_int,
memview_int,
)
# todo: check when a copy is made, and when it isn't
def test_set():
ints = {
619056821839331327,
619056821839593471,
619056821839855615,
619056821840117759,
619056821840379903,
619056821840642047,
619056821840904191,
}
h = 614553222213795839
assert basic_int.compact_cells(ints) == [h]
with pytest.raises(TypeError):
# numpy can't convert from a set
numpy_int.compact_cells(ints)
with pytest.raises(TypeError):
# set isn't a memoryview
memview_int.compact_cells(ints)
def test_list():
ints = [
619056821839331327,
619056821839593471,
619056821839855615,
619056821840117759,
619056821840379903,
619056821840642047,
619056821840904191,
]
h = 614553222213795839
assert basic_int.compact_cells(ints) == [h]
# numpy can convert from a list OK
# (numpy knows to convert it to uint64)
assert numpy_int.compact_cells(ints) == np.array([h], dtype='uint64')
# little weird that numpy comparisons don't consider dtype
assert numpy_int.compact_cells(ints) == np.array([h])
assert not numpy_int.compact_cells(ints).dtype == np.array([h]).dtype
with pytest.raises(TypeError):
# list isn't a memoryview
memview_int.compact_cells(ints)
def test_np_array():
ints = np.array(
[
619056821839331327,
619056821839593471,
619056821839855615,
619056821840117759,
619056821840379903,
619056821840642047,
619056821840904191,
],
dtype='uint64',
)
h = 614553222213795839
assert basic_int.compact_cells(ints) == [h]
assert numpy_int.compact_cells(ints) == np.array([h], dtype='uint64')
assert numpy_int.compact_cells(ints).dtype == np.dtype('uint64')
out = memview_int.compact_cells(ints)
assert len(out) == 1
assert out[0] == h
def test_list_to_array():
ints0 = [
619056821839331327,
619056821839593471,
619056821839855615,
619056821840117759,
619056821840379903,
619056821840642047,
619056821840904191,
]
ints = np.array(ints0)
h = 614553222213795839
assert basic_int.compact_cells(ints) == [h]
assert numpy_int.compact_cells(ints) == np.array([h], dtype='uint64')
with pytest.raises(ValueError):
# Without the explicit dtype given above, the array
# assumes it has *signed* integers
# The `memview_int` interface requires a dtype match
# with uint64.
memview_int.compact_cells(ints)
def test_iterator():
def foo():
ints = iter(
[
619056821839331327,
619056821839593471,
619056821839855615,
619056821840117759,
619056821840379903,
619056821840642047,
619056821840904191,
]
)
return ints
h = 614553222213795839
ints = foo()
assert basic_int.compact_cells(ints) == [h]
ints = foo()
with pytest.raises(TypeError):
# numpy can't create an array from an iterator
numpy_int.compact_cells(ints)
ints = foo()
with pytest.raises(TypeError):
# requires a bytes-like input
memview_int.compact_cells(ints)