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
This commit is contained in:
Crzyrndm 2018-08-25 13:54:54 +12:00
parent 875f143d74
commit 1003ba507d

View File

@ -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