diff options
author | Eike Rathke <erack@redhat.com> | 2018-08-29 10:44:53 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2018-08-29 17:30:28 +0200 |
commit | 5f352a7289786e9648d0aca61a8ec867be4f4aa4 (patch) | |
tree | 6984359ccfee1e2f59d0bf519a025e10eee0fd47 /tools/qa | |
parent | ff1dd003b7094594d0b8d799d56546005e9094f2 (diff) |
Round fraction if possible, else truncate; tools::Time::GetClock()
With this also some test cases can be narrowed.
Change-Id: Ic754baf135dbd362b80fac1cf080758f46017e01
Reviewed-on: https://gerrit.libreoffice.org/59753
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
Diffstat (limited to 'tools/qa')
-rw-r--r-- | tools/qa/cppunit/test_time.cxx | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/tools/qa/cppunit/test_time.cxx b/tools/qa/cppunit/test_time.cxx index 0de7190bf354..39c8476bce75 100644 --- a/tools/qa/cppunit/test_time.cxx +++ b/tools/qa/cppunit/test_time.cxx @@ -96,24 +96,42 @@ void TimeTest::testClockValues() CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(0), nHour); CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(0), nMinute); CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(0), nSecond); - // Last digit may differ. - CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.999, fFractionOfSecond, 1.1e-3); + // Expect this to be a truncated 0.999999 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.999, fFractionOfSecond, 0.0); fTime = 0.524268391203704; Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 3); CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(12), nHour); CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(34), nMinute); CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(56), nSecond); - // Last digit may differ. - CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.789, fFractionOfSecond, 1.1e-3); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.789, fFractionOfSecond, 0.0); fTime = -0.000001; - Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 9); + Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 13); CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(23), nHour); CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(59), nMinute); CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(59), nSecond); // Expect this to be exact within floating point accuracy. - CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.913599999, fFractionOfSecond, 1e-15); + // This is a hairy rounding condition, if it yields problems on any + // platform feel free to disable the test for that platform. + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.9135999999999, fFractionOfSecond, + 1e-14); + + fTime = -0.000001; + Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 4); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(23), nHour); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(59), nMinute); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(59), nSecond); + // Expect this to be rounded. + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.9136, fFractionOfSecond, 0.0); + + fTime = -0.00000000001; + Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 4); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(23), nHour); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(59), nMinute); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(59), nSecond); + // Expect this to be a truncated 0.999999 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.9999, fFractionOfSecond, 0.0); fTime = -1e-24; // value insignificant for time Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 0); |