diff options
author | Eike Rathke <erack@redhat.com> | 2017-05-17 19:08:20 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-05-17 19:14:00 +0200 |
commit | 07797559153a330ca66ade146b47f2a2b0657c64 (patch) | |
tree | 7e50d4b5a3fba18bd5caa721eff5d534b7960b6b | |
parent | 8326c48a1ac4855970f9232dba582a51461ac0b2 (diff) |
Add some unit tests for rtl_math_StringFormat_G
Change-Id: I010c35905789d2c5f60f7f1c4d9ad4caf60146ee
-rw-r--r-- | sal/qa/rtl/math/test-rtl-math.cxx | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/sal/qa/rtl/math/test-rtl-math.cxx b/sal/qa/rtl/math/test-rtl-math.cxx index f9f041a17f95..fa118b9f3467 100644 --- a/sal/qa/rtl/math/test-rtl-math.cxx +++ b/sal/qa/rtl/math/test-rtl-math.cxx @@ -203,6 +203,39 @@ public: rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, '.', true); CPPUNIT_ASSERT_EQUAL( OUString("9.00719925474099E+015"), aRes); + + // Test rtl_math_StringFormat_G + + fVal = 0.001234567; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_G, 3, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("0.00123"), aRes); + + fVal = 123.4567; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_G, 3, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("123"), aRes); + + fVal = 123.4567; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_G, 4, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("123.5"), aRes); + + fVal = 99.6; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_G, 3, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("99.6"), aRes); + + // Expected could be 1E+03 (as 999.6 rounded to 3 significant digits + // results in 1000 with an exponent equal to significant digits). + // Currently we don't and output 1000 instead, negligible. + fVal = 999.6; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_G, 3, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1000"), aRes); + + fVal = 9999.6; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_G, 3, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1E+004"), aRes); + + fVal = 12345.6789; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_G, -3, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1.2E+004"), aRes); } void test_approx() { |