[tests, distance] Use AlmostEqual to compare floating numbers
authorSimon Chabot <simon.chabot@logilab.fr>
Tue, 01 Oct 2019 10:04:38 +0200
changeset 566 f6ba33f1779a
parent 565 53defbcde5a5
child 567 d5f2a4fdb810
[tests, distance] Use AlmostEqual to compare floating numbers (and 0.125 is rounded to 0.12 in python3. It was 0.13 in python2)
test/test_distances.py
--- a/test/test_distances.py	Tue Oct 01 10:00:23 2019 +0200
+++ b/test/test_distances.py	Tue Oct 01 10:04:38 2019 +0200
@@ -39,10 +39,10 @@
 class DistancesTest(unittest.TestCase):
 
     def test_difflib_match(self):
-        self.assertEqual(round(difflib_match('Victor Hugo', 'Victor Hugo'), 2), 0.)
-        self.assertEqual(round(difflib_match('Victor Hugo', 'Victor Wugo'), 2), 0.09)
-        self.assertEqual(round(difflib_match('niche', 'chiens'), 2), 0.45)
-        self.assertEqual(round(difflib_match('bonjour', 'bonjour !'), 2), 0.13)
+        self.assertAlmostEqual(round(difflib_match('Victor Hugo', 'Victor Hugo'), 2), 0.)
+        self.assertAlmostEqual(round(difflib_match('Victor Hugo', 'Victor Wugo'), 2), 0.09)
+        self.assertAlmostEqual(round(difflib_match('niche', 'chiens'), 2), 0.45)
+        self.assertAlmostEqual(round(difflib_match('bonjour', 'bonjour !'), 2), 0.12)
 
     def test_levenshtein(self):
         self.assertEqual(levenshtein('niche', 'chiens'), 5)