aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2021-07-22 13:58:18 +0300
committerMuriithi Frederick Muriuki2021-07-22 13:58:18 +0300
commit0263a7c79e3131d42006a38ac2fbb80556506491 (patch)
tree94c90b9f21c610432a32f457876eea427cd79fff
parent0b71c74992ab1bff82d14902c51f52c3c6fbe4a1 (diff)
downloadgenenetwork3-0263a7c79e3131d42006a38ac2fbb80556506491.tar.gz
Check that given list and both coordinates, we get shortest distance
* gn3/computations/slink.py: Add code to compute the distance given the coordinate of both members on the parent list/tuple * tests/unit/computations/test_slink.py: * Change the name of the tests to more closely correspond to the business requirement the test is checking for * Update the comments to indicate some more things that might need to be done in the future
-rw-r--r--gn3/computations/slink.py2
-rw-r--r--tests/unit/computations/test_slink.py7
2 files changed, 6 insertions, 3 deletions
diff --git a/gn3/computations/slink.py b/gn3/computations/slink.py
index 7d13d91..7b4016a 100644
--- a/gn3/computations/slink.py
+++ b/gn3/computations/slink.py
@@ -71,3 +71,5 @@ This description should be updated once the form/type of 'distance' identified."
raise_valueerror_on_negative_distances(lists)
#### END: Guard Functions ####
return None
+ if type(i) == int and type(j) == int: # From member i to member j
+ return lists[i][j]
diff --git a/tests/unit/computations/test_slink.py b/tests/unit/computations/test_slink.py
index 6be3f33..166eff9 100644
--- a/tests/unit/computations/test_slink.py
+++ b/tests/unit/computations/test_slink.py
@@ -65,9 +65,10 @@ class TestSlink(TestCase):
with self.assertRaises(ValueError, msg="Distances should be positive."):
nearest(lst, 1, 1)
- def test_nearest_with_expected(self):
- # Give this test a better name
- # The lists in this tests are taken from:
+ def test_nearest_returns_shortest_distance_given_coordinates_to_both_group_members(self):
+ # This test is named wrong - at least I think it is, from the expected results
+ # This tests distance when both `i`, and `j` are integers
+ # We still need to add tests for when (either one/both) (is/are) not (an) integer(s)
# https://github.com/genenetwork/genenetwork1/blob/master/web/webqtl/heatmap/slink.py#L39-L40
for lst, i, j, expected 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,0,0],