diff --git a/lexical_cast_test.cpp b/lexical_cast_test.cpp index 506e975..436f599 100644 --- a/lexical_cast_test.cpp +++ b/lexical_cast_test.cpp @@ -67,6 +67,9 @@ void test_conversion_from_ulong(); void test_conversion_from_longlong(); void test_conversion_from_ulonglong(); #endif +void test_round_conversion_float(); +void test_round_conversion_double(); +void test_round_conversion_long_double(); unit_test::test_suite *init_unit_test_suite(int, char *[]) { @@ -97,6 +100,8 @@ unit_test::test_suite *init_unit_test_suite(int, char *[]) suite->add(BOOST_TEST_CASE(&test_conversion_from_longlong)); suite->add(BOOST_TEST_CASE(&test_conversion_from_ulonglong)); #endif + suite->add(BOOST_TEST_CASE(&test_round_conversion_float)); + suite->add(BOOST_TEST_CASE(&test_round_conversion_double)); return suite; } @@ -606,3 +611,42 @@ void test_conversion_from_ulonglong() #endif +template +void test_round_conversion() +{ + T v1 = std::numeric_limits::epsilon(); + std::string s1 = boost::lexical_cast(v1); + BOOST_CHECK(v1 == lexical_cast(s1)); + + T v2 = (std::numeric_limits::max)(); + std::string s2 = boost::lexical_cast(v2); + BOOST_CHECK(v2 == lexical_cast(s2)); + + T v3 = (std::numeric_limits::min)(); + std::string s3 = boost::lexical_cast(v3); + BOOST_CHECK(v3 == lexical_cast(s3)); + + T v4 = v2 / 137; + std::string s4 = boost::lexical_cast(v4); + BOOST_CHECK(v4 == lexical_cast(s4)); + + T v5 = v1 * 137; + std::string s5 = boost::lexical_cast(v5); + BOOST_CHECK(v5 == lexical_cast(s5)); +} + +void test_round_conversion_float() +{ + test_round_conversion(); +} + +void test_round_conversion_double() +{ + test_round_conversion(); +} + +void test_round_conversion_long_double() +{ + test_round_conversion(); +} +