Skip to content

Commit e0248ce

Browse files
committed
add tests classification
1 parent 40e03f2 commit e0248ce

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/test_classification.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
import xarray as xr
77

8-
from pydepsi.classification import _nad_block, _nmad_block, ps_selection
8+
from pydepsi.classification import _idx_within_distance, _nad_block, _nmad_block, ps_selection
99

1010
# Create a random number generator
1111
rng = np.random.default_rng(42)
@@ -121,3 +121,27 @@ def test_nmad_block_select_two():
121121
res = ps_selection(slcs, 1e-10, method="nmad", output_chunks=5) # Select pixels with dispersion lower than 0.00001
122122
assert res.sizes["time"] == 10
123123
assert res.sizes["space"] == 2
124+
125+
126+
def test__idx_within_distance():
127+
coords_include = np.array([[1, 1]])
128+
coords_remain = np.array([[0, 0], [1, 1], [2, 2], [3, 3]])
129+
idx_within = _idx_within_distance(coords_include, coords_remain, 1)
130+
assert np.all(idx_within == np.array([1]))
131+
132+
coords_include = np.array([[1, 1], [2, 2]])
133+
coords_remain = np.array([[0, 0], [1.1, 1], [2.2, 2], [3, 3]])
134+
idx_within = _idx_within_distance(coords_include, coords_remain, 1)
135+
assert np.all(idx_within == np.array([1, 2]))
136+
137+
coords_include = np.array([[1, 1]])
138+
coords_remain = np.array([[0, 0], [1, 1], [2, 2], [3, 3]])
139+
idx_within = _idx_within_distance(coords_include, coords_remain, 2)
140+
assert np.all(idx_within == np.array([0, 1, 2]))
141+
142+
143+
def test__idx_within_distance_no_drop():
144+
coords_include = np.array([[100, 100]])
145+
coords_remain = np.array([[0, 0], [1, 1], [2, 2], [3, 3]])
146+
idx_within = _idx_within_distance(coords_include, coords_remain, 1)
147+
assert idx_within is None

0 commit comments

Comments
 (0)