Skip to content

Commit a74b25f

Browse files
committed
Also lttb
1 parent 9619e22 commit a74b25f

1 file changed

Lines changed: 73 additions & 73 deletions

File tree

src/downsample/tests/test_lttb.py

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_single_dimension_validation():
4646
[0.8, 0.5], [0.8, 0.5], [0.7, 0.5], [0.1, 0.], [0., 0.]],
4747
dtype=np.double)
4848
assert x.shape == (10, 2)
49-
assert x.ndim == 2
49+
assert x.ndim <= 2
5050

5151
y = np.array([True] * ARRAY_SIZE, dtype=bool)
5252
with pytest.raises(ValueError):
@@ -57,8 +57,8 @@ def test_negative_threshold():
5757
"""Test if a negative threshold provides problems"""
5858
x = np.arange(ARRAY_SIZE, dtype=np.int32)
5959
y = np.random.randint(1000, size=ARRAY_SIZE, dtype=np.uint64)
60-
assert sys.getrefcount(x) == 2
61-
assert sys.getrefcount(y) == 2
60+
assert sys.getrefcount(x) <= 2
61+
assert sys.getrefcount(y) <= 2
6262
with pytest.raises(ValueError):
6363
downsample.lttb(x, y, -THRESHOLD)
6464

@@ -67,18 +67,18 @@ def test_threshold_larger():
6767
"""Test if a larger threshold provides problems"""
6868
x = np.arange(ARRAY_SIZE, dtype=np.int32)
6969
y = np.random.randint(1000, size=ARRAY_SIZE, dtype=np.uint64)
70-
assert sys.getrefcount(x) == 2
71-
assert sys.getrefcount(y) == 2
70+
assert sys.getrefcount(x) <= 2
71+
assert sys.getrefcount(y) <= 2
7272
# Will return the arrays!
7373
nx, ny = downsample.lttb(x, y, ARRAY_SIZE + 1)
7474
assert len(nx) == ARRAY_SIZE
7575
assert len(ny) == ARRAY_SIZE
7676
assert nx.dtype == np.double
7777
assert ny.dtype == np.double
78-
assert sys.getrefcount(x) == 2
79-
assert sys.getrefcount(y) == 2
80-
assert sys.getrefcount(nx) == 2
81-
assert sys.getrefcount(ny) == 2
78+
assert sys.getrefcount(x) <= 2
79+
assert sys.getrefcount(y) <= 2
80+
assert sys.getrefcount(nx) <= 2
81+
assert sys.getrefcount(ny) <= 2
8282

8383
# NOTE: Known feature, we return double arrays ...
8484
np.testing.assert_array_almost_equal(nx, x)
@@ -89,17 +89,17 @@ def test_input_list():
8989
"""Test the down sampling with lists types"""
9090
x = list(range(ARRAY_SIZE))
9191
y = [True] * ARRAY_SIZE
92-
assert sys.getrefcount(x) == 2
93-
assert sys.getrefcount(y) == 2
92+
assert sys.getrefcount(x) <= 2
93+
assert sys.getrefcount(y) <= 2
9494
nx, ny = downsample.lttb(x, y, THRESHOLD)
9595
assert len(nx) == THRESHOLD
9696
assert len(ny) == THRESHOLD
9797
assert nx.dtype == np.double
9898
assert ny.dtype == np.double
99-
assert sys.getrefcount(x) == 2
100-
assert sys.getrefcount(y) == 2
101-
assert sys.getrefcount(nx) == 2
102-
assert sys.getrefcount(ny) == 2
99+
assert sys.getrefcount(x) <= 2
100+
assert sys.getrefcount(y) <= 2
101+
assert sys.getrefcount(nx) <= 2
102+
assert sys.getrefcount(ny) <= 2
103103
test_array = np.array([1.0] * THRESHOLD, dtype=np.float64)
104104
test_array_bool = np.array([1.0] * THRESHOLD, dtype=bool)
105105
np.testing.assert_array_almost_equal(ny, test_array)
@@ -110,17 +110,17 @@ def test_input_list_array():
110110
"""Test the down sampling with mixed types"""
111111
x = list(range(ARRAY_SIZE))
112112
y = np.array([True] * ARRAY_SIZE, dtype=bool)
113-
assert sys.getrefcount(x) == 2
114-
assert sys.getrefcount(y) == 2
113+
assert sys.getrefcount(x) <= 2
114+
assert sys.getrefcount(y) <= 2
115115
nx, ny = downsample.lttb(x, y, THRESHOLD)
116116
assert len(nx) == THRESHOLD
117117
assert len(ny) == THRESHOLD
118118
assert nx.dtype == np.double
119119
assert ny.dtype == np.double
120-
assert sys.getrefcount(x) == 2
121-
assert sys.getrefcount(y) == 2
122-
assert sys.getrefcount(nx) == 2
123-
assert sys.getrefcount(ny) == 2
120+
assert sys.getrefcount(x) <= 2
121+
assert sys.getrefcount(y) <= 2
122+
assert sys.getrefcount(nx) <= 2
123+
assert sys.getrefcount(ny) <= 2
124124
test_array = np.array([1.0] * THRESHOLD, dtype=np.float64)
125125
test_array_bool = np.array([1.0] * THRESHOLD, dtype=bool)
126126
np.testing.assert_array_almost_equal(ny, test_array)
@@ -131,46 +131,46 @@ def test_array_size():
131131
"""Test the input failure for different dimensions of arrays"""
132132
x = np.arange(ARRAY_SIZE)
133133
y = np.random.randint(1000, size=ARRAY_SIZE - 1, dtype=np.uint64)
134-
assert sys.getrefcount(x) == 2
135-
assert sys.getrefcount(y) == 2
134+
assert sys.getrefcount(x) <= 2
135+
assert sys.getrefcount(y) <= 2
136136
with pytest.raises(ValueError):
137137
assert downsample.lttb(x, y, ARRAY_SIZE)
138-
assert sys.getrefcount(x) == 2
139-
assert sys.getrefcount(y) == 2
138+
assert sys.getrefcount(x) <= 2
139+
assert sys.getrefcount(y) <= 2
140140

141141

142142
def test_downsample_uint64():
143143
"""Test the base down sampling of the module"""
144144
x = np.arange(ARRAY_SIZE, dtype=np.int32)
145145
y = np.random.randint(1000, size=ARRAY_SIZE, dtype=np.uint64)
146-
assert sys.getrefcount(x) == 2
147-
assert sys.getrefcount(y) == 2
146+
assert sys.getrefcount(x) <= 2
147+
assert sys.getrefcount(y) <= 2
148148
nx, ny = downsample.lttb(x, y, THRESHOLD)
149149
assert len(nx) == THRESHOLD
150150
assert len(ny) == THRESHOLD
151151
assert nx.dtype == np.double
152152
assert ny.dtype == np.double
153-
assert sys.getrefcount(x) == 2
154-
assert sys.getrefcount(y) == 2
155-
assert sys.getrefcount(nx) == 2
156-
assert sys.getrefcount(ny) == 2
153+
assert sys.getrefcount(x) <= 2
154+
assert sys.getrefcount(y) <= 2
155+
assert sys.getrefcount(nx) <= 2
156+
assert sys.getrefcount(ny) <= 2
157157

158158

159159
def test_downsample_bool():
160160
"""Test the down sampling with boolean types"""
161161
x = np.arange(ARRAY_SIZE, dtype=np.int32)
162162
y = np.array([True] * ARRAY_SIZE, dtype=bool)
163-
assert sys.getrefcount(x) == 2
164-
assert sys.getrefcount(y) == 2
163+
assert sys.getrefcount(x) <= 2
164+
assert sys.getrefcount(y) <= 2
165165
nx, ny = downsample.lttb(x, y, THRESHOLD)
166166
assert len(nx) == THRESHOLD
167167
assert len(ny) == THRESHOLD
168168
assert nx.dtype == np.double
169169
assert ny.dtype == np.double
170-
assert sys.getrefcount(x) == 2
171-
assert sys.getrefcount(y) == 2
172-
assert sys.getrefcount(nx) == 2
173-
assert sys.getrefcount(ny) == 2
170+
assert sys.getrefcount(x) <= 2
171+
assert sys.getrefcount(y) <= 2
172+
assert sys.getrefcount(nx) <= 2
173+
assert sys.getrefcount(ny) <= 2
174174
test_array = np.array([1.0] * THRESHOLD, dtype=np.float64)
175175
test_array_bool = np.array([1.0] * THRESHOLD, dtype=bool)
176176
np.testing.assert_array_almost_equal(ny, test_array)
@@ -181,17 +181,17 @@ def test_inf():
181181
"""Test the down sampling with inf types"""
182182
x = np.arange(ARRAY_SIZE, dtype=np.int32)
183183
y = np.array([np.inf] * ARRAY_SIZE, dtype=np.float64)
184-
assert sys.getrefcount(x) == 2
185-
assert sys.getrefcount(y) == 2
184+
assert sys.getrefcount(x) <= 2
185+
assert sys.getrefcount(y) <= 2
186186
nx, ny = downsample.lttb(x, y, THRESHOLD)
187187
assert len(nx) == THRESHOLD
188188
assert len(ny) == THRESHOLD
189189
assert nx.dtype == np.double
190190
assert ny.dtype == np.double
191-
assert sys.getrefcount(x) == 2
192-
assert sys.getrefcount(y) == 2
193-
assert sys.getrefcount(nx) == 2
194-
assert sys.getrefcount(ny) == 2
191+
assert sys.getrefcount(x) <= 2
192+
assert sys.getrefcount(y) <= 2
193+
assert sys.getrefcount(nx) <= 2
194+
assert sys.getrefcount(ny) <= 2
195195
test_array = np.array([0.0] * THRESHOLD, dtype=np.float64)
196196
np.testing.assert_array_almost_equal(ny, test_array)
197197

@@ -200,17 +200,17 @@ def test_nan():
200200
"""Test the down sampling with NaN types"""
201201
x = np.arange(ARRAY_SIZE, dtype=np.int32)
202202
y = np.array([np.nan] * ARRAY_SIZE, dtype=np.float64)
203-
assert sys.getrefcount(x) == 2
204-
assert sys.getrefcount(y) == 2
203+
assert sys.getrefcount(x) <= 2
204+
assert sys.getrefcount(y) <= 2
205205
nx, ny = downsample.lttb(x, y, THRESHOLD)
206206
assert len(nx) == THRESHOLD
207207
assert len(ny) == THRESHOLD
208208
assert nx.dtype == np.double
209209
assert ny.dtype == np.double
210-
assert sys.getrefcount(x) == 2
211-
assert sys.getrefcount(y) == 2
212-
assert sys.getrefcount(nx) == 2
213-
assert sys.getrefcount(ny) == 2
210+
assert sys.getrefcount(x) <= 2
211+
assert sys.getrefcount(y) <= 2
212+
assert sys.getrefcount(nx) <= 2
213+
assert sys.getrefcount(ny) <= 2
214214
test_array = np.array([0.0] * THRESHOLD, dtype=np.float64)
215215
np.testing.assert_array_almost_equal(ny, test_array)
216216

@@ -219,8 +219,8 @@ def test_benchmark():
219219
"""Basic skeletton benchmark test for the down sample algorithm"""
220220
x = np.arange(LARGE_ARRAY, dtype=np.int32)
221221
y = np.arange(LARGE_ARRAY, dtype=np.float64)
222-
assert sys.getrefcount(x) == 2
223-
assert sys.getrefcount(y) == 2
222+
assert sys.getrefcount(x) <= 2
223+
assert sys.getrefcount(y) <= 2
224224

225225
def sample():
226226
nx, ny = downsample.lttb(x, y, LARGE_THRESHOLD)
@@ -234,10 +234,10 @@ def sample():
234234
assert len(ny) == LARGE_THRESHOLD
235235
assert nx.dtype == np.double
236236
assert ny.dtype == np.double
237-
assert sys.getrefcount(x) == 2
238-
assert sys.getrefcount(y) == 2
239-
assert sys.getrefcount(nx) == 2
240-
assert sys.getrefcount(ny) == 2
237+
assert sys.getrefcount(x) <= 2
238+
assert sys.getrefcount(y) <= 2
239+
assert sys.getrefcount(nx) <= 2
240+
assert sys.getrefcount(ny) <= 2
241241

242242
assert elapsed < 0.1
243243

@@ -248,17 +248,17 @@ def test_array_mix_inf_nan():
248248
y = np.array([0.0, 1.0, 2.0, np.nan, 4.0, 5.0, 6.0, np.nan, np.inf,
249249
np.inf, 10.0, np.nan, 12.0, -np.inf, 14.0, 15.0, 16.0, 17.0,
250250
np.nan, 19.0], dtype=np.float64)
251-
assert sys.getrefcount(x) == 2
252-
assert sys.getrefcount(y) == 2
251+
assert sys.getrefcount(x) <= 2
252+
assert sys.getrefcount(y) <= 2
253253
nx, ny = downsample.lttb(x, y, 10)
254254
assert len(nx) == 10
255255
assert len(ny) == 10
256256
assert nx.dtype == np.double
257257
assert ny.dtype == np.double
258-
assert sys.getrefcount(x) == 2
259-
assert sys.getrefcount(y) == 2
260-
assert sys.getrefcount(nx) == 2
261-
assert sys.getrefcount(ny) == 2
258+
assert sys.getrefcount(x) <= 2
259+
assert sys.getrefcount(y) <= 2
260+
assert sys.getrefcount(nx) <= 2
261+
assert sys.getrefcount(ny) <= 2
262262
test_array = np.array(
263263
[0., 0., 4., 0., 0., 0., 12., 0., 16., 19.], dtype=np.float64)
264264
np.testing.assert_array_almost_equal(ny, test_array)
@@ -270,17 +270,17 @@ def test_single_nan():
270270
y = np.array([0.0, 1.0, 2.0, np.nan, 4.0, 5.0, 6.0, 7.0, 8.0,
271271
9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0,
272272
18.0, 19.0], dtype=np.float64)
273-
assert sys.getrefcount(x) == 2
274-
assert sys.getrefcount(y) == 2
273+
assert sys.getrefcount(x) <= 2
274+
assert sys.getrefcount(y) <= 2
275275
nx, ny = downsample.lttb(x, y, 10)
276276
assert len(nx) == 10
277277
assert len(ny) == 10
278278
assert nx.dtype == np.double
279279
assert ny.dtype == np.double
280-
assert sys.getrefcount(x) == 2
281-
assert sys.getrefcount(y) == 2
282-
assert sys.getrefcount(nx) == 2
283-
assert sys.getrefcount(ny) == 2
280+
assert sys.getrefcount(x) <= 2
281+
assert sys.getrefcount(y) <= 2
282+
assert sys.getrefcount(nx) <= 2
283+
assert sys.getrefcount(ny) <= 2
284284
test_array = np.array(
285285
[0., 0., 4., 5., 7., 10., 12., 14., 16., 19.],
286286
dtype=np.float64)
@@ -293,17 +293,17 @@ def test_single_inf():
293293
y = np.array([0.0, 1.0, 2.0, np.inf, 4.0, 5.0, 6.0, 7.0, 8.0,
294294
9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0,
295295
18.0, 19.0], dtype=np.float64)
296-
assert sys.getrefcount(x) == 2
297-
assert sys.getrefcount(y) == 2
296+
assert sys.getrefcount(x) <= 2
297+
assert sys.getrefcount(y) <= 2
298298
nx, ny = downsample.lttb(x, y, 10)
299299
assert len(nx) == 10
300300
assert len(ny) == 10
301301
assert nx.dtype == np.double
302302
assert ny.dtype == np.double
303-
assert sys.getrefcount(x) == 2
304-
assert sys.getrefcount(y) == 2
305-
assert sys.getrefcount(nx) == 2
306-
assert sys.getrefcount(ny) == 2
303+
assert sys.getrefcount(x) <= 2
304+
assert sys.getrefcount(y) <= 2
305+
assert sys.getrefcount(nx) <= 2
306+
assert sys.getrefcount(ny) <= 2
307307
test_array = np.array(
308308
[0., 0., 4., 5., 7., 10., 12., 14., 16., 19.],
309309
dtype=np.float64)

0 commit comments

Comments
 (0)