From 08c81b8892060353bb7fb15555875f03bbdcb46e Mon Sep 17 00:00:00 2001
From: Frederick Muriuki Muriithi
Date: Fri, 19 Nov 2021 10:56:35 +0300
Subject: 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.
---
 tests/unit/computations/test_partial_correlations.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

(limited to 'tests/unit')

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):
-- 
cgit v1.2.3