From 1003ba507db56a0acff8d062da6593b2ae5c3ea6 Mon Sep 17 00:00:00 2001 From: Crzyrndm Date: Sat, 25 Aug 2018 13:54:54 +1200 Subject: [PATCH] Add a test for serialize_number_to_string -- should allow serialisation of up to 15 significant digits -- don't use default stringstreams, typically only get ~6 significant digits --- tests/detail/numeric_util_test_suite.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/detail/numeric_util_test_suite.cpp b/tests/detail/numeric_util_test_suite.cpp index e79d507e..3df14799 100644 --- a/tests/detail/numeric_util_test_suite.cpp +++ b/tests/detail/numeric_util_test_suite.cpp @@ -29,6 +29,7 @@ class numeric_test_suite : public test_suite public: numeric_test_suite() { + register_test(test_serialise_number); register_test(test_float_equals_zero); register_test(test_float_equals_large); register_test(test_float_equals_fairness); @@ -37,6 +38,22 @@ public: register_test(test_abs); } + void test_serialise_number() + { + // excel serialises numbers as floating point values with <= 15 digits of precision + xlnt_assert(xlnt::detail::serialize_number_to_string(1) == "1"); + // trailing zeroes are ignored + xlnt_assert(xlnt::detail::serialize_number_to_string(1.0) == "1"); + xlnt_assert(xlnt::detail::serialize_number_to_string(1.0f) == "1"); + // one to 1 relation + xlnt_assert(xlnt::detail::serialize_number_to_string(1.23456) == "1.23456"); + xlnt_assert(xlnt::detail::serialize_number_to_string(1.23456789012345) == "1.23456789012345"); + xlnt_assert(xlnt::detail::serialize_number_to_string(123456.789012345) == "123456.789012345"); + xlnt_assert(xlnt::detail::serialize_number_to_string(1234567890123.45) == "1234567890123.45"); + // extra precision gets trimmed + xlnt_assert(xlnt::detail::serialize_number_to_string(1.234567890123456) == "1.23456789012345"); + } + void test_float_equals_zero() { // comparing relatively small numbers (2.3e-6) with 0 will be true by default