[Git][NTPsec/ntpsec][master] Restored previously removed tests, fixed math problem.

Ian Bruene gitlab at mg.gitlab.com
Fri Oct 6 02:41:05 UTC 2017


Ian Bruene pushed to branch master at NTPsec / ntpsec


Commits:
b6ac6f61 by Ian Bruene at 2017-10-05T21:40:25-05:00
Restored previously removed tests, fixed math problem.

- - - - -


2 changed files:

- pylib/packet.py
- tests/pylib/test_packet.py


Changes:

=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -445,7 +445,7 @@ class SyncPacket(Packet):
     def ntp_to_posix(t):
         "Scale from NTP time to POSIX time"
         # Note: assumes we're in the same NTP era as the transmitter...
-        return (t / (2**32)) - SyncPacket.UNIX_EPOCH
+        return (t >> 32) - SyncPacket.UNIX_EPOCH
 
     @staticmethod
     def posix_to_ntp(t):


=====================================
tests/pylib/test_packet.py
=====================================
--- a/tests/pylib/test_packet.py
+++ b/tests/pylib/test_packet.py
@@ -322,6 +322,8 @@ class TestSyncPacket(unittest.TestCase):
 
     def test_ntp_to_posix(self):
         f = self.target.ntp_to_posix
+        # Test the Timeless Void Before Existence
+        self.assertEqual(f(-1), -2208988801)  # NTP can see the Timeless Void
         # Test beginning of NTP epoch
         self.assertEqual(f(0), -2208988800)
         # Test just before the Age of Unix
@@ -330,6 +332,8 @@ class TestSyncPacket(unittest.TestCase):
         self.assertEqual(f(2208988800 * 2**32), 0)
         # Test the End of Time
         self.assertEqual(f(0xFFFFFFFF00000000), 2085978495)
+        # Test the Timeless Void Beyond Existence
+        self.assertEqual(f(0x10000000000000000), 2085978496)  # It doesn't clip
 
     def test_posix_to_ntp(self):
         f = self.target.posix_to_ntp



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

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/b6ac6f61c2be433a3627c07edb4eac87dd76e5b8
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/9aac127e/attachment.html>


More information about the vc mailing list