From eaa5362a6068f45fc98a9200dac807e7f74a4c1a Mon Sep 17 00:00:00 2001 From: Fanwang Meng Date: Sat, 17 Aug 2024 23:28:28 -0400 Subject: [PATCH] Add tests for invalid `ref_index` for `MaxSum` and `MaxMin` --- selector/methods/tests/test_distance.py | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/selector/methods/tests/test_distance.py b/selector/methods/tests/test_distance.py index 3a2e8df9..7c1eb32a 100644 --- a/selector/methods/tests/test_distance.py +++ b/selector/methods/tests/test_distance.py @@ -126,6 +126,21 @@ def test_maxmin(): assert_equal(selected_mocked, [0, 1, 2, 3, 4, 5, 6, 7, 8, 16, 15, 10, 13, 9, 18]) +def test_maxmin_invalid_input(): + """Testing MaxMin class with invalid input.""" + # case when the distance matrix is not square + x_dist = np.array([[0, 1], [1, 0], [4, 9]]) + with pytest.raises(ValueError): + collector = MaxMin(ref_index=0) + _ = collector.select(x_dist, size=2) + + # case when the distance matrix is not symmetric + x_dist = np.array([[0, 1, 2], [1, 0, 3], [4, 9, 0], [5, 6, 7]]) + with pytest.raises(ValueError): + collector = MaxMin(ref_index=0) + _ = collector.select(x_dist, size=2) + + def test_maxsum_clustered_data(): """Testing MaxSum class.""" # generate random data points belonging to multiple clusters - coordinates and class labels @@ -206,6 +221,21 @@ def test_maxsum_non_clustered_data(): selected_ids = collector.select(coords, size=12) +def test_maxsum_invalid_input(): + """Testing MaxSum class with invalid input.""" + # case when the distance matrix is not square + x_dist = np.array([[0, 1], [1, 0], [4, 9]]) + with pytest.raises(ValueError): + collector = MaxSum(ref_index=0) + _ = collector.select(x_dist, size=2) + + # case when the distance matrix is not symmetric + x_dist = np.array([[0, 1, 2], [1, 0, 3], [4, 9, 0], [5, 6, 7]]) + with pytest.raises(ValueError): + collector = MaxSum(ref_index=0) + _ = collector.select(x_dist, size=2) + + def test_optisim(): """Testing OptiSim class.""" # generate random data points belonging to one cluster - coordinates and pairwise distance matrix