aboutsummaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-11-19 10:56:35 +0300
committerFrederick Muriuki Muriithi2021-11-19 10:56:35 +0300
commit08c81b8892060353bb7fb15555875f03bbdcb46e (patch)
treeef545062885d08a3425e59e52164b6822cb93b9a /tests/unit
parent6367350202a4a7eb9c6551d01cc1b4543d2529f0 (diff)
downloadgenenetwork3-08c81b8892060353bb7fb15555875f03bbdcb46e.tar.gz
Avoid rounding: compare floats approximately
Notes: https://github.com/genenetwork/genenetwork3/pull/56#issuecomment-973798918 * As mentioned in the notes, rather than rounding to an arbitrary number of decimal places, it is a much better practice to use approximate comparisons of floats for the tests.
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/computations/test_partial_correlations.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/tests/unit/computations/test_partial_correlations.py b/tests/unit/computations/test_partial_correlations.py
index f77a066..3e1b6e1 100644
--- a/tests/unit/computations/test_partial_correlations.py
+++ b/tests/unit/computations/test_partial_correlations.py
@@ -3,6 +3,7 @@
from unittest import TestCase
import pandas
+from numpy.testing import assert_allclose
from gn3.computations.partial_correlations import (
fix_samples,
@@ -250,7 +251,7 @@ class TestPartialCorrelations(TestCase):
with self.assertRaises(error, msg=error_msg):
tissue_correlation(primary, target, method)
- def test_tissue_correlation(self):
+ def test_tissue_correlation(self): # pylint: disable=R0201
"""
Test that the correct correlation values are computed for the given:
- primary trait
@@ -259,11 +260,11 @@ class TestPartialCorrelations(TestCase):
"""
for primary, target, method, expected in (
((12.34, 18.36, 42.51), (37.25, 46.25, 46.56), "pearson",
- (0.6761779253, 0.5272701134)),
+ (0.6761779252651052, 0.5272701133657985)),
((1, 2, 3, 4, 5), (5, 6, 7, 8, 7), "spearman",
- (0.8207826817, 0.0885870053))):
+ (0.8207826816681233, 0.08858700531354381))):
with self.subTest(primary=primary, target=target, method=method):
- self.assertEqual(
+ assert_allclose(
tissue_correlation(primary, target, method), expected)
def test_good_dataset_samples_indexes(self):