]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Fixed floating point test errors.
authorLinux Karlsson <karlsson@ntp.org>
Fri, 29 Oct 2010 18:13:53 +0000 (20:13 +0200)
committerLinux Karlsson <karlsson@ntp.org>
Fri, 29 Oct 2010 18:13:53 +0000 (20:13 +0200)
bk: 4ccb0ee1igDj5zZ0vXVnqpX-WjHUSA

tests/libntp/buftvtots.cpp
tests/libntp/tvtots.cpp

index 3bfa575bee48109c93535789f986609597b0621f..09c9e709d6c4c4b9309cacabace876c775701034 100644 (file)
@@ -18,14 +18,23 @@ TEST_F(buftvtotsTest, ZeroBuffer) {
        EXPECT_TRUE(IsEqual(expected, actual));
 }
 
-TEST_F(buftvtotsTest, DISABLED_IntegerAndFractionalBuffer) {
+TEST_F(buftvtotsTest, IntegerAndFractionalBuffer) {
        const timeval input = {5, 500000}; // 5.5
        const l_fp expected = {5 + JAN_1970, HALF};
 
        l_fp actual;
 
        ASSERT_TRUE(buftvtots((const char*)(&input), &actual));
-       EXPECT_TRUE(IsEqual(expected, actual));
+
+       // Compare the fractional part with an absolute error given.
+       EXPECT_EQ(expected.l_ui, actual.l_ui);
+
+       double expectedDouble, actualDouble;
+       M_LFPTOD(0, expected.l_uf, expectedDouble);
+       M_LFPTOD(0, actual.l_uf, actualDouble);
+
+       // The error should be less than 0.5 us
+       EXPECT_NEAR(expectedDouble, actualDouble, 0.0000005);
 }
 
 TEST_F(buftvtotsTest, IllegalMicroseconds) {
index cad22aebb244129308b4adfbd890321a8e986a12..06a4323382e2570bdb3ae1511766993583e2334c 100644 (file)
@@ -31,13 +31,21 @@ TEST_F(tvtotsTest, MicrosecondsRounded) {
        EXPECT_TRUE(IsEqual(expected, actual));
 }
 
-TEST_F(tvtotsTest, DISABLED_MicrosecondsExact) {
+TEST_F(tvtotsTest, MicrosecondsExact) {
        // 0.5 can be represented exact in both l_fp and timeval.
-
-       timeval input = {10, 500000}; // 0.5 exact
-       l_fp expected = {10, HALF}; // 0.5 exact
+       const timeval input = {10, 500000}; // 0.5 exact
+       const l_fp expected = {10, HALF}; // 0.5 exact
        l_fp actual;
 
        TVTOTS(&input, &actual);
-       EXPECT_TRUE(IsEqual(expected, actual));
+
+       // Compare the fractional part with an absolute error given.
+       EXPECT_EQ(expected.l_ui, actual.l_ui);
+
+       double expectedDouble, actualDouble;
+       M_LFPTOD(0, expected.l_uf, expectedDouble);
+       M_LFPTOD(0, actual.l_uf, actualDouble);
+
+       // The error should be less than 0.5 us
+       EXPECT_NEAR(expectedDouble, actualDouble, 0.0000005);
 }