about summary refs log tree commit diff
path: root/tests/unit/computations
diff options
context:
space:
mode:
authorArun Isaac2021-11-11 14:43:37 +0530
committerBonfaceKilz2021-11-11 20:49:30 +0300
commitfb92e75b8e9984fbbf9b26f87b53ea516a8819da (patch)
tree8c54998e266cbcc28481fdf8762334e743e9b6de /tests/unit/computations
parent249b85102063debfeeb1b0565956059b8a3af1cf (diff)
downloadgenenetwork3-fb92e75b8e9984fbbf9b26f87b53ea516a8819da.tar.gz
Compare floats approximately.
Floating point numbers should only be compared approximately. Different
implementations of functions might produce slightly different results.

* tests/unit/computations/test_correlation.py: Import assert_almost_equal from
numpy.testing.
(TestCorrelation.test_compute_correlation): Compare floats using
assert_almost_equal instead of assertEqual.
* tests/unit/test_heatmaps.py: Import assert_allclose from numpy.testing.
(TestHeatmap.test_cluster_traits): Use assert_allclose instead of assertEqual.
Diffstat (limited to 'tests/unit/computations')
-rw-r--r--tests/unit/computations/test_correlation.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/tests/unit/computations/test_correlation.py b/tests/unit/computations/test_correlation.py
index 706520a..e6cf198 100644
--- a/tests/unit/computations/test_correlation.py
+++ b/tests/unit/computations/test_correlation.py
@@ -4,6 +4,7 @@ from unittest import mock
 import unittest
 
 from collections import namedtuple
+from numpy.testing import assert_almost_equal
 
 from gn3.computations.correlations import normalize_values
 from gn3.computations.correlations import compute_sample_r_correlation
@@ -481,5 +482,8 @@ class TestCorrelation(TestCase):
                  [None, None, None, None, 2, None, None, 3, None, None],
                  (0.0, 2)]]:
             with self.subTest(dbdata=dbdata, userdata=userdata):
-                self.assertEqual(compute_correlation(
-                    dbdata, userdata), expected)
+                actual = compute_correlation(dbdata, userdata)
+                with self.subTest("correlation coefficient"):
+                    assert_almost_equal(actual[0], expected[0])
+                with self.subTest("overlap"):
+                    self.assertEqual(actual[1], expected[1])