aboutsummaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-10-21 09:00:16 +0300
committerFrederick Muriuki Muriithi2021-10-21 09:35:52 +0300
commitcad4649d19001f62ef592dedf09f3ac53744962a (patch)
tree6a94f1d57d91807699281aaa7d3e6320b5620960 /tests/unit
parent6818670686de86c86b6c1aa372135ab6c22af156 (diff)
downloadgenenetwork3-cad4649d19001f62ef592dedf09f3ac53744962a.tar.gz
Implement `find_identical_traits` function
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi * gn3/partial_correlations.py: implement function `find_identical_traits` * tests/unit/test_partial_correlations.py: implement tests for function `find_identical_traits` Migrate `web.webqtl.correlation.correlationFunction.findIdenticalTraits` function in GN1 to here, adding in tests to ensure the migration works in a bug-compatible version with the original.
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/test_partial_correlations.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/unit/test_partial_correlations.py b/tests/unit/test_partial_correlations.py
index c591c8f..60e54c1 100644
--- a/tests/unit/test_partial_correlations.py
+++ b/tests/unit/test_partial_correlations.py
@@ -4,7 +4,8 @@ from unittest import TestCase
from gn3.partial_correlations import (
fix_samples,
control_samples,
- dictify_by_samples)
+ dictify_by_samples,
+ find_identical_traits)
sampleslist = ["B6cC3-1", "BXD1", "BXD12", "BXD16", "BXD19", "BXD2"]
control_traits = (
@@ -178,3 +179,33 @@ class TestPartialCorrelations(TestCase):
(None,),
(None, None, None, None, None, None, None, None, None, None, None,
None, None)))
+
+ def test_find_identical_traits(self):
+ """
+ Test `gn3.partial_correlations.find_identical_traits`.
+
+ Given:
+ - the name of a primary trait
+ - the value of a primary trait
+ - a sequence of names of control traits
+ - a sequence of values of control traits
+ When:
+ - the arguments above are passed to the `find_identical_traits`
+ function
+ Then:
+ - Return ALL trait names that have the same value when up to three
+ decimal places are considered
+ """
+ for primn, primv, contn, contv, expected in (
+ ("pt", 12.98395, ("ct0", "ct1", "ct2"),
+ (0.1234, 2.3456, 3.4567), tuple()),
+ ("pt", 12.98395, ("ct0", "ct1", "ct2"),
+ (12.98354, 2.3456, 3.4567), ("pt", "ct0")),
+ ("pt", 12.98395, ("ct0", "ct1", "ct2", "ct3"),
+ (0.1234, 2.3456, 0.1233, 4.5678), ("ct0", "ct2"))
+ ):
+ with self.subTest(
+ primary_name=primn, primary_value=primv,
+ control_names=contn, control_values=contv):
+ self.assertEqual(
+ find_identical_traits(primn, primv, contn, contv), expected)