[Git][NTPsec/ntpsec][master] Decouple some tests from the representation of l_fp.

Eric S. Raymond gitlab at mg.gitlab.com
Tue Jan 3 01:03:29 UTC 2017


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
46442bfc by Eric S. Raymond at 2017-01-02T20:02:49-05:00
Decouple some tests from the representation of l_fp.

- - - - -


2 changed files:

- tests/libntp/lfptostr.c
- tests/libntp/prettydate.c


Changes:

=====================================
tests/libntp/lfptostr.c
=====================================
--- a/tests/libntp/lfptostr.c
+++ b/tests/libntp/lfptostr.c
@@ -28,65 +28,72 @@ static const int THREE_FOURTH = -1073741824;
 static const int HALF_PROMILLE_UP = 2147484; // slightly more than 0.0005
 static const int HALF_PROMILLE_DOWN = 2147483; // slightly less than 0.0005
 
+static l_fp lfpinit(int32_t hi, uint32_t lo)
+{
+    l_fp tmp;
+    setlfpsint(tmp, hi);
+    setlfpfrac(tmp, lo);
+    return tmp;
+}
 
 TEST(lfptostr, PositiveInteger) {
-	l_fp test = {{200}, 0}; // exact 200.0000000000
+    l_fp test = lfpinit(200, 0); // exact 200.0000000000
 
 	TEST_ASSERT_EQUAL_STRING("200.0000000000", mfptoa(test, LFP_MAX_PRECISION));
 	TEST_ASSERT_EQUAL_STRING("200000.0000000", mfptoms(test, LFP_MAX_PRECISION_MS));
 }
 
 TEST(lfptostr, NegativeInteger) {
-	l_fp test = {{-100}, 0}; // -100
+    l_fp test = lfpinit(-100, 0); // -100
 
 	TEST_ASSERT_EQUAL_STRING("-100.0000000000", lfptoa(test, LFP_MAX_PRECISION));
 	TEST_ASSERT_EQUAL_STRING("-100000.0000000", lfptoms(test, LFP_MAX_PRECISION_MS));
 }
 
 TEST(lfptostr, PositiveIntegerWithFraction) {
-	l_fp test = {{200}, ONE_FOURTH}; // 200.25
+	l_fp test = lfpinit(200, ONE_FOURTH); // 200.25
 
 	TEST_ASSERT_EQUAL_STRING("200.2500000000", lfptoa(test, LFP_MAX_PRECISION));
 	TEST_ASSERT_EQUAL_STRING("200250.0000000", lfptoms(test, LFP_MAX_PRECISION_MS));
 }
 
 TEST(lfptostr, NegativeIntegerWithFraction) {
-	l_fp test = {{-100}, ONE_FOURTH}; // -99.75
+	l_fp test = lfpinit(-100, ONE_FOURTH); // -99.75
 
 	TEST_ASSERT_EQUAL_STRING("-99.7500000000", lfptoa(test, LFP_MAX_PRECISION));
 	TEST_ASSERT_EQUAL_STRING("-99750.0000000", lfptoms(test, LFP_MAX_PRECISION_MS));
 }
 
 TEST(lfptostr, RoundingDownToInteger) {
-	l_fp test = {{10}, ONE_FOURTH}; // 10.25
+	l_fp test = lfpinit(10, ONE_FOURTH); // 10.25
 
 	TEST_ASSERT_EQUAL_STRING("10", lfptoa(test, 0));
 	TEST_ASSERT_EQUAL_STRING("10250", lfptoms(test, 0));
 }
 
 TEST(lfptostr, RoundingMiddleToInteger) {
-	l_fp test = {{10}, HALF}; // 10.5
+	l_fp test = lfpinit(10, HALF); // 10.5
 
 	TEST_ASSERT_EQUAL_STRING("11", lfptoa(test, 0));
 	TEST_ASSERT_EQUAL_STRING("10500", lfptoms(test, 0));
 }
 
 TEST(lfptostr, RoundingUpToInteger) {
-	l_fp test = {{5}, THREE_FOURTH}; // 5.75
+	l_fp test = lfpinit(5, THREE_FOURTH); // 5.75
 
 	TEST_ASSERT_EQUAL_STRING("6", lfptoa(test, 0));
 	TEST_ASSERT_EQUAL_STRING("5750", lfptoms(test, 0));
 }
 
 TEST(lfptostr, SingleDecimal) {
-	l_fp test = {{8}, ONE_FOURTH}; // 8.25
+	l_fp test = lfpinit(8, ONE_FOURTH); // 8.25
 
 	TEST_ASSERT_EQUAL_STRING("8.3", lfptoa(test, 1));
 	TEST_ASSERT_EQUAL_STRING("8250.0", lfptoms(test, 1));
 }
 
 TEST(lfptostr, MillisecondsRoundingUp) {
-	l_fp test = {{1}, HALF_PROMILLE_UP}; //slightly more than 1.0005
+	l_fp test = lfpinit(1, HALF_PROMILLE_UP); //slightly more than 1.0005
 
 	TEST_ASSERT_EQUAL_STRING("1.0", lfptoa(test, 1));
 
@@ -95,7 +102,7 @@ TEST(lfptostr, MillisecondsRoundingUp) {
 }
 
 TEST(lfptostr, MillisecondsRoundingDown) {
-	l_fp test = {{1}, HALF_PROMILLE_DOWN}; // slightly less than 1.0005
+	l_fp test = lfpinit(1, HALF_PROMILLE_DOWN); // slightly less than 1.0005
 
 	TEST_ASSERT_EQUAL_STRING("1.0", lfptoa(test, 1));
 
@@ -104,17 +111,17 @@ TEST(lfptostr, MillisecondsRoundingDown) {
 }
 
 TEST(lfptostr, UnsignedInteger) {
-	l_fp test1 = {{3000000000UL}, 0};
-	l_fp test2 = {{3000000UL}, 0x80000000};
-	l_fp test3 = {{13UL}, 0xC0000000};
-	l_fp test4 = {{13UL}, 0x028F5C28};
-
-	l_fp test5 = {{4212665562UL}, 0x3C6BE7E6};
-	l_fp test6 = {{4212665562UL}, 0x36222683};
-	l_fp test7 = {{4212665562UL}, 0xBD3F2F5A};
-	l_fp test8a = {{1444359386UL}, 0x2E0C7582};
-	l_fp test8b = {{1444359386UL}, 0x2E0C7583};
-	l_fp test9 = {{3660323067UL}, 0x1CD3101C};
+	l_fp test1 = lfpinit(3000000000UL, 0);
+	l_fp test2 = lfpinit(3000000UL, 0x80000000);
+	l_fp test3 = lfpinit(13UL, 0xC0000000);
+	l_fp test4 = lfpinit(13UL, 0x028F5C28);
+
+	l_fp test5 = lfpinit(4212665562UL, 0x3C6BE7E6);
+	l_fp test6 = lfpinit(4212665562UL, 0x36222683);
+	l_fp test7 = lfpinit(4212665562UL, 0xBD3F2F5A);
+	l_fp test8a = lfpinit(1444359386UL, 0x2E0C7582);
+	l_fp test8b = lfpinit(1444359386UL, 0x2E0C7583);
+	l_fp test9 = lfpinit(3660323067UL, 0x1CD3101C);
 
 	TEST_ASSERT_EQUAL_STRING("3000000000.0", ulfptoa(test1, 1));
 	TEST_ASSERT_EQUAL_STRING("3000000000.000000", ulfptoa(test1, 6));


=====================================
tests/libntp/prettydate.c
=====================================
--- a/tests/libntp/prettydate.c
+++ b/tests/libntp/prettydate.c
@@ -15,8 +15,16 @@ TEST_TEAR_DOWN(prettydate) {}
 
 static const u_int32_t HALF = 2147483648UL;
 
+static l_fp lfpinit(int32_t hi, uint32_t lo)
+{
+    l_fp tmp;
+    setlfpsint(tmp, hi);
+    setlfpfrac(tmp, lo);
+    return tmp;
+}
+
 TEST(prettydate, ConstantDate) {
-	l_fp time = {{3485080800UL}, HALF}; // 2010-06-09 14:00:00.5
+    l_fp time = lfpinit(3485080800UL, HALF); // 2010-06-09 14:00:00.5
 
 	TEST_ASSERT_EQUAL_STRING("cfba1ce0.80000000 2010-06-09T14:00:00.500Z", gmprettydate(&time));
 }



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/46442bfccfca4491e236f8097bfe360f256aec00
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170103/effe8ad3/attachment.html>


More information about the vc mailing list