[Git][NTPsec/ntpsec][master] Added tests for util.py/f8dot4 and f8dot3. Bugfix in f8dot3.

Ian Bruene gitlab at mg.gitlab.com
Sun Aug 27 17:19:18 UTC 2017


Ian Bruene pushed to branch master at NTPsec / ntpsec


Commits:
f9b8c16c by Ian Bruene at 2017-08-27T12:17:57-05:00
Added tests for util.py/f8dot4 and f8dot3. Bugfix in f8dot3.

Adjusted comment in f8dot4.

- - - - -


2 changed files:

- pylib/util.py
- tests/pylib/test_util.py


Changes:

=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -414,7 +414,7 @@ def f8dot4(f):
         # it also catches None, strings, etc.
         return "     nan"
 
-    fmt = "%8d"          # xxxxxxxx
+    fmt = "%8d"          # xxxxxxxx or -xxxxxxx
     if f >= 0:
         if f < 1000.0:
             fmt = "%8.4f"    # xxx.xxxx  normal case
@@ -451,7 +451,7 @@ def f8dot3(f):
         # it also catches None, strings, etc.
         return "     nan"
 
-    fmt = "%8d" % f          # xxxxxxxx or -xxxxxxx
+    fmt = "%8d"          # xxxxxxxx or -xxxxxxx
     if f >= 0:
         if f < 10000.0:
             fmt = "%8.3f"    # xxxx.xxx  normal case


=====================================
tests/pylib/test_util.py
=====================================
--- a/tests/pylib/test_util.py
+++ b/tests/pylib/test_util.py
@@ -311,5 +311,65 @@ class TestPylibUtilMethods(unittest.TestCase):
         # PPM var
         self.assertEqual(f("1.234", "frequency"), "1.234ppm")
 
+    def test_f8dot4(self):
+        f = ntp.util.f8dot4
+
+        # Test signal
+        self.assertEqual(f("foo"), "     foo")
+        # Test bad type
+        self.assertEqual(f({"food": "problematic"}), "       X")
+        # Test not a number
+        self.assertEqual(f(float("nan")), "     nan")
+        # Test Positives
+        # Test xxxxxxxx
+        self.assertEqual(f(12345678.9), "12345678")
+        # Test xxxxxx.x
+        self.assertEqual(f(123456.789), "123456.8")
+        # Test xxxxx.xx
+        self.assertEqual(f(12345.6789), "12345.68")
+        # Test xxxx.xxx
+        self.assertEqual(f(1234.56789), "1234.568")
+        # Test xxx.xxxx
+        self.assertEqual(f(123.456789), "123.4568")
+        # Test Negatives
+        # Test -xxxxxxx
+        self.assertEqual(f(-1234567.89), "-1234567")
+        # Test -xxxxx.x
+        self.assertEqual(f(-12345.6789), "-12345.7")
+        # Test -xxxx.xx
+        self.assertEqual(f(-1234.56789), "-1234.57")
+        # Test -xxx.xxx
+        self.assertEqual(f(-123.456789), "-123.457")
+        # Test -xx.xxxx
+        self.assertEqual(f(-12.3456789), "-12.3457")
+
+    def test_f8dot3(self):
+        f = ntp.util.f8dot3
+
+        # Test signal
+        self.assertEqual(f("foo"), "     foo")
+        # Test bad type
+        self.assertEqual(f({"food": "problematic"}), "       X")
+        # Test not a number
+        self.assertEqual(f(float("nan")), "     nan")
+        # Test Positives
+        # Test xxxxxxxx
+        self.assertEqual(f(12345678.9), "12345678")
+        # Test xxxxxx.x
+        self.assertEqual(f(123456.789), "123456.8")
+        # Test xxxxx.xx
+        self.assertEqual(f(12345.6789), "12345.68")
+        # Test xxxx.xxx
+        self.assertEqual(f(1234.56789), "1234.568")
+        # Test Negatives
+        # Test -xxxxxxx
+        self.assertEqual(f(-1234567.89), "-1234567")
+        # Test -xxxxx.x
+        self.assertEqual(f(-12345.6789), "-12345.7")
+        # Test -xxxx.xx
+        self.assertEqual(f(-1234.56789), "-1234.57")
+        # Test -xxx.xxx
+        self.assertEqual(f(-123.456789), "-123.457")
+
 if __name__ == '__main__':
     unittest.main()



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

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/f9b8c16cd1b1d2b91e6286d4c51316feebd46076
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/20170827/971f42ba/attachment.html>


More information about the vc mailing list