aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/computations
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2021-07-22 15:01:27 +0300
committerMuriithi Frederick Muriuki2021-07-22 15:01:27 +0300
commit5751aa26829fd01b222b658e63c0a6c2214d4c71 (patch)
tree88c40230c6461c39d91f11c10b808b627417cb6c /tests/unit/computations
parent598d17fd415e905ede6ad4457a3283dcf2ef350a (diff)
downloadgenenetwork3-5751aa26829fd01b222b658e63c0a6c2214d4c71.tar.gz
Test for shortest distance between members in a list and coordinate
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * gn3/computations/slink.py: add code to pass new test * tests/unit/computations/test_slink.py: new test Given a list of members in a group, and a coordinate for a member in the same group, find the distance of the closest member from the given coordinate in the group.
Diffstat (limited to 'tests/unit/computations')
-rw-r--r--tests/unit/computations/test_slink.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/unit/computations/test_slink.py b/tests/unit/computations/test_slink.py
index 166eff9..64d123c 100644
--- a/tests/unit/computations/test_slink.py
+++ b/tests/unit/computations/test_slink.py
@@ -172,3 +172,15 @@ class TestSlink(TestCase):
4,4,0]]:
with self.subTest(lst=lst):
self.assertEqual(nearest(lst, i, j), expected)
+
+ def test_given_a_list_or_tuple_of_members_distances_and_a_coordinate_find_closest_member_to_member_at_coordinate(self):
+ for md, ml, mc, ed in [
+ [[[0,9,3,6,11],[9,0,7,5,10],[3,7,0,9,2],[6,5,9,0,8],[11,10,2,8,0]],[0,1,2,3,4],3,0],
+ [[[0,9,3,6,11],[9,0,7,5,10],[3,7,0,9,2],[6,5,9,0,8],[11,10,2,8,0]],[0,1,2,4],3,5],
+ [[[0,9,3,6,11],[9,0,7,5,10],[3,7,0,9,2],[6,5,9,0,8],[11,10,2,8,0]],[0,2,4],3,6],
+ [[[0,9,3,6,11],[9,0,7,5,10],[3,7,0,9,2],[6,5,9,0,8],[11,10,2,8,0]],[2,4],3,8]]:
+ with self.subTest(
+ members_distances=md, members_list=ml, member_coordinate=mc,
+ expected_distance=ed):
+ self.assertEqual(nearest(md, ml, mc), ed)
+ self.assertEqual(nearest(md, mc, ml), ed)