From 0b71c74992ab1bff82d14902c51f52c3c6fbe4a1 Mon Sep 17 00:00:00 2001 From: Muriithi Frederick Muriuki Date: Thu, 22 Jul 2021 13:16:16 +0300 Subject: Check that all distances are positive or zero Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * gn3/computations/slink.py: check that all distances between the 'somethings' are all either zero or positive. * tests/unit/computations/test_slink.py: * Remove data with all distances positive or zero, since it would fail the test * Change the expected message to more closely correspond to the business logic --- tests/unit/computations/test_slink.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/unit/computations/test_slink.py b/tests/unit/computations/test_slink.py index 207debf..6be3f33 100644 --- a/tests/unit/computations/test_slink.py +++ b/tests/unit/computations/test_slink.py @@ -55,15 +55,14 @@ class TestSlink(TestCase): def test_nearest_expects_zero_or_positive_distances(self): # Based on: # https://github.com/genenetwork/genenetwork1/blob/master/web/webqtl/heatmap/slink.py#L87-L89 - for lst in [[[0,1,2,3],[1,0,3,4],[2,3,0,5],[3,4,5,0]], - [[0,-1,2,3],[-1,0,3,4],[2,3,0,5],[3,4,5,0]], + for lst in [[[0,-1,2,3],[-1,0,3,4],[2,3,0,5],[3,4,5,0]], [[0,1,-2,3],[1,0,3,4],[-2,3,0,5],[3,4,5,0]], [[0,1,2,3],[1,0,-3,4],[2,-3,0,5],[3,4,5,0]], [[0,1,2,-3],[1,0,3,4],[2,3,0,5],[-3,4,5,0]], [[0,1,2,3],[1,0,3,-4],[2,3,0,5],[3,-4,5,0]], [[0,1,2,3],[1,0,3,4],[2,3,0,-5],[3,4,-5,0]]]: with self.subTest(lst=lst): - with self.assertRaises(ValueError, msg="Got an unexpected negative value!"): + with self.assertRaises(ValueError, msg="Distances should be positive."): nearest(lst, 1, 1) def test_nearest_with_expected(self): -- cgit v1.2.3