aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2021-07-23 08:11:55 +0300
committerMuriithi Frederick Muriuki2021-07-23 08:11:55 +0300
commiteb5bf7fbd66abfc798bc272a4aefcb972f61c55f (patch)
tree793db40f1dcadd7ede692f2c67279cb953384c5f
parentb08bf586d653d2243d8bc7a321227f287ce99a74 (diff)
downloadgenenetwork3-eb5bf7fbd66abfc798bc272a4aefcb972f61c55f.tar.gz
Fix issue caught in `nearest` while testing `slink`
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * While running tests for slink, to try and understand what it is doing in order to write the appropriate tests for it, an issue arose that pointed a blindspot in the former understanding of now `nearest` should work. This commit fixes the issue found in both the expected data, and the code.
-rw-r--r--gn3/computations/slink.py4
-rw-r--r--tests/unit/computations/test_slink.py3
2 files changed, 4 insertions, 3 deletions
diff --git a/gn3/computations/slink.py b/gn3/computations/slink.py
index 103a853..0c74789 100644
--- a/gn3/computations/slink.py
+++ b/gn3/computations/slink.py
@@ -108,9 +108,9 @@ def nearest(lists, i, j):
if type(i) == int and type(j) == int: # From member i to member j
return lists[i][j]
elif type(i) == int and __is_list_or_tuple(j):
- return min(map(lambda j_new: nearest(lists, i, j_new), j))
+ return min(map(lambda j_new: nearest(lists, i, j_new), j[:-1]))
elif type(j) == int and __is_list_or_tuple(i):
- return min(map(lambda i_new: nearest(lists, i_new, j), i))
+ return min(map(lambda i_new: nearest(lists, i_new, j), i[:-1]))
elif __is_list_or_tuple(i) and __is_list_or_tuple(j):
partial_i = map(lambda x:partial(nearest, lists, x), i[:-1])
ns = list(map(lambda f, x: f(x), partial_i, j[:1]))
diff --git a/tests/unit/computations/test_slink.py b/tests/unit/computations/test_slink.py
index bdfaf6d..8ccbda5 100644
--- a/tests/unit/computations/test_slink.py
+++ b/tests/unit/computations/test_slink.py
@@ -176,10 +176,11 @@ class TestSlink(TestCase):
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],[9,0,7],[3,7,0]],(0,2,3),1,7],
[[[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]]:
+ [[[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,9]]:
with self.subTest(
members_distances=md, members_list=ml, member_coordinate=mc,
expected_distance=ed):