[Git][NTPsec/ntpsec][master] Added documentation and fixes for float tests

Ian Bruene gitlab at mg.gitlab.com
Fri Oct 6 16:47:18 UTC 2017


Ian Bruene pushed to branch master at NTPsec / ntpsec


Commits:
f459452c by Ian Bruene at 2017-10-06T11:43:31-05:00
Added documentation and fixes for float tests

Tests that deal with floats now use assertAlmostEqual()

Outside-range tests are documented as low-value to be removed if problematic

Test for float-vulnerable function returning an int (posix_to_ntp) is
documented as having potential problems in the future.

- - - - -


2 changed files:

- tests/pylib/test_packet.py
- tests/pylib/test_util.py


Changes:

=====================================
tests/pylib/test_packet.py
=====================================
--- a/tests/pylib/test_packet.py
+++ b/tests/pylib/test_packet.py
@@ -142,7 +142,7 @@ class AuthenticatorJig:
 
 # ==========================================================
 #  Tests
-# =========================================================
+# ==========================================================
 
 
 class TestPacket(unittest.TestCase):
@@ -320,6 +320,12 @@ class TestSyncPacket(unittest.TestCase):
         self.assertEqual(cls.mac, polybytes(mac))
         self.assertEqual(cls.extension, polybytes(ext + mac))
 
+    # ====================================================================
+    # The tests refering to the Timeless Void are testing outside of NTP's
+    # representation range, they are left in on the off chance that they
+    # catch a bug in the future. If they become problematic they can be
+    # removed without loss.
+    # ====================================================================
     def test_ntp_to_posix(self):
         f = self.target.ntp_to_posix
         # Test the Timeless Void Before Existence
@@ -336,6 +342,9 @@ class TestSyncPacket(unittest.TestCase):
         self.assertEqual(f(0x10000000000000000), 2085978496.0)  # Doesn't clip
 
     def test_posix_to_ntp(self):
+        # This function may develop float precision issues, however it
+        # returns an integer so testing for that is complicated. For the
+        # moment the tests are being left as-is until such issues appear.
         f = self.target.posix_to_ntp
         # Test the Timeless Void Before Existence
         self.assertEqual(f(-2208988801), -0x100000000)  # It doesn't clip
@@ -400,11 +409,11 @@ class TestSyncPacket(unittest.TestCase):
         # Test delta
         self.assertEqual(cls.delta(), 2)
         # Test epsilon
-        self.assertEqual(cls.epsilon(), 16.000045)
+        self.assertAlmostEqual(cls.epsilon(), 16.000045)
         # Test synchd
-        self.assertEqual(cls.synchd(), 17.000045)
+        self.assertAlmostEqual(cls.synchd(), 17.000045)
         # Test adjust
-        self.assertEqual(cls.adjust(), 0)
+        self.assertAlmostEqual(cls.adjust(), 0.0)
 
     def test_flatten(self):
         data = "\x5C\x10\x01\xFF" \


=====================================
tests/pylib/test_util.py
=====================================
--- a/tests/pylib/test_util.py
+++ b/tests/pylib/test_util.py
@@ -69,7 +69,8 @@ class TestPylibUtilMethods(unittest.TestCase):
             self.assertEqual(f("42", int, "blah %s", "\nDo the needful\n"), 42)
             self.assertEqual(errjig.data, [])
             # Test successful float
-            self.assertEqual(f("5.23", float, "blah %s", "\nDo the needful\n"),
+            self.assertAlmostEqual(f("5.23", float, "blah %s",
+                                     "\nDo the needful\n"),
                              5.23)
             self.assertEqual(errjig.data, [])
             # Test failure



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/f459452c547e5d41070664a4d30013c8cb23d189

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/f459452c547e5d41070664a4d30013c8cb23d189
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20171006/c1f1692d/attachment.html>


More information about the vc mailing list