[Git][NTPsec/ntpsec][master] test_util: add more tests. Several fail the existing util.py

Gary E. Miller gitlab at mg.gitlab.com
Mon Apr 3 19:14:30 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
67e0b20d by Gary E. Miller at 2017-04-03T12:01:32-07:00
test_util: add more tests.  Several fail the existing util.py

- - - - -


1 changed file:

- tests/pylib/test_util.py


Changes:

=====================================
tests/pylib/test_util.py
=====================================
--- a/tests/pylib/test_util.py
+++ b/tests/pylib/test_util.py
@@ -95,14 +95,45 @@ class TestPylibUtilMethods(unittest.TestCase):
     def test_unitformatter(self):
         f = ntp.util.unitformatter
         usec = ntp.util.UNITS_SEC
-        self.assertEqual(f(0.0000000005, usec, ntp.util.UNIT_MS),
+
+        # 1.0000000005 s rounds to 1s
+        self.assertEqual(f(1.0000000005, usec, ntp.util.UNIT_S),
+                         "1.00000s")  # Checking timefuzz
+
+        # -1.0000000005 s rounds to 1s
+        self.assertEqual(f(-1.0000000005, usec, ntp.util.UNIT_S),
+                         "-1.0000s")  # Checking timefuzz
+
+        # 0.999999 s round to 1s
+        self.assertEqual(f(0.999999, usec, ntp.util.UNIT_S),
+                         "1.00000s")  # Checking timefuzz
+
+        # 0.00000000049 s rounds to 0ns
+        self.assertEqual(f(0.00000000049, usec, ntp.util.UNIT_S),
                          "     0ns")  # Checking timefuzz
-        self.assertEqual(f(0.0000000005, usec, ntp.util.UNIT_MS, strip=True),
+        # 0.0000000005 s rounds to 1ns
+        self.assertEqual(f(0.0000000005, usec, ntp.util.UNIT_S),
+                         "     1ns")  # Checking timefuzz
+
+        # 0.4 ms rounds to 0ns
+        self.assertEqual(f(0.0000004, usec, ntp.util.UNIT_MS),
+                         "     0ns")  # Checking timefuzz
+        # 0.5 ms rounds to 1ns
+        self.assertEqual(f(0.0000005, usec, ntp.util.UNIT_MS),
+                         "     1ns")  # Checking timefuzz
+        # 0.5 ms rounds to 1ns
+        self.assertEqual(f(0.0000005, usec, ntp.util.UNIT_MS, strip=True),
                          "0ns")  # Checking timefuzz, strip
         self.assertEqual(f(12.45, usec, ntp.util.UNIT_MS),
                          " 12.45ms")  # Checking normal
         self.assertEqual(f(12.45, usec, ntp.util.UNIT_MS, strip=True),
                          "12.45ms")  # Checking normal, strip
+        # 12.499999 ms rounds to 12.45 ms
+        self.assertEqual(f(12.499999, usec, ntp.util.UNIT_MS, strip=True),
+                         "12.45ms")  # Checking normal, strip
+        # 12.451 ms rounds to 12.45 ms
+        self.assertEqual(f(12.451, usec, ntp.util.UNIT_MS, strip=True),
+                         "12.45ms")  # Checking normal, strip
         self.assertEqual(f(123456789.1234, usec, ntp.util.UNIT_MS, width=None),
                          "123.4567891234ks")  # Checking normal, no width
         self.assertEqual(f(0.000005, usec, ntp.util.UNIT_MS),



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/67e0b20d53e67a30171fbc74810763a30eaeba0b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170403/81394d36/attachment.html>


More information about the vc mailing list