diff options
Diffstat (limited to 'Build/source/libs/icu/icu-src/source/test/intltest/numbertest_decimalquantity.cpp')
-rw-r--r-- | Build/source/libs/icu/icu-src/source/test/intltest/numbertest_decimalquantity.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/Build/source/libs/icu/icu-src/source/test/intltest/numbertest_decimalquantity.cpp b/Build/source/libs/icu/icu-src/source/test/intltest/numbertest_decimalquantity.cpp index b298b43219e..0cbcc524644 100644 --- a/Build/source/libs/icu/icu-src/source/test/intltest/numbertest_decimalquantity.cpp +++ b/Build/source/libs/icu/icu-src/source/test/intltest/numbertest_decimalquantity.cpp @@ -20,6 +20,7 @@ void DecimalQuantityTest::runIndexedTest(int32_t index, UBool exec, const char * TESTCASE_AUTO(testAppend); TESTCASE_AUTO(testConvertToAccurateDouble); TESTCASE_AUTO(testUseApproximateDoubleWhenAble); + TESTCASE_AUTO(testHardDoubleConversion); TESTCASE_AUTO_END; } @@ -233,7 +234,7 @@ void DecimalQuantityTest::testConvertToAccurateDouble() { } void DecimalQuantityTest::testUseApproximateDoubleWhenAble() { - struct TestCase { + static const struct TestCase { double d; int32_t maxFrac; RoundingMode roundingMode; @@ -264,4 +265,33 @@ void DecimalQuantityTest::testUseApproximateDoubleWhenAble() { } } +void DecimalQuantityTest::testHardDoubleConversion() { + static const struct TestCase { + double input; + const char16_t* expectedOutput; + } cases[] = { + { 512.0000000000017, u"512.0000000000017" }, + { 4095.9999999999977, u"4095.9999999999977" }, + { 4095.999999999998, u"4095.999999999998" }, + { 4095.9999999999986, u"4095.9999999999986" }, + { 4095.999999999999, u"4095.999999999999" }, + { 4095.9999999999995, u"4095.9999999999995" }, + { 4096.000000000001, u"4096.000000000001" }, + { 4096.000000000002, u"4096.000000000002" }, + { 4096.000000000003, u"4096.000000000003" }, + { 4096.000000000004, u"4096.000000000004" }, + { 4096.000000000005, u"4096.000000000005" }, + { 4096.0000000000055, u"4096.0000000000055" }, + { 4096.000000000006, u"4096.000000000006" }, + { 4096.000000000007, u"4096.000000000007" } }; + + for (auto& cas : cases) { + DecimalQuantity q; + q.setToDouble(cas.input); + q.roundToInfinity(); + UnicodeString actualOutput = q.toPlainString(); + assertEquals("", cas.expectedOutput, actualOutput); + } +} + #endif /* #if !UCONFIG_NO_FORMATTING */ |