mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
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:
parent
875f143d74
commit
1003ba507d
|
@ -29,6 +29,7 @@ class numeric_test_suite : public test_suite
|
||||||
public:
|
public:
|
||||||
numeric_test_suite()
|
numeric_test_suite()
|
||||||
{
|
{
|
||||||
|
register_test(test_serialise_number);
|
||||||
register_test(test_float_equals_zero);
|
register_test(test_float_equals_zero);
|
||||||
register_test(test_float_equals_large);
|
register_test(test_float_equals_large);
|
||||||
register_test(test_float_equals_fairness);
|
register_test(test_float_equals_fairness);
|
||||||
|
@ -37,6 +38,22 @@ public:
|
||||||
register_test(test_abs);
|
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()
|
void test_float_equals_zero()
|
||||||
{
|
{
|
||||||
// comparing relatively small numbers (2.3e-6) with 0 will be true by default
|
// comparing relatively small numbers (2.3e-6) with 0 will be true by default
|
||||||
|
|
Loading…
Reference in New Issue
Block a user