From 86846034d0bbe681ccffcef279d4e6df49aebf4a Mon Sep 17 00:00:00 2001 From: Marco Paland Date: Tue, 26 Mar 2019 08:50:58 +0100 Subject: test(test_suite): added more float test cases --- test/test_suite.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/test_suite.cpp b/test/test_suite.cpp index dc15321..9a6cf07 100644 --- a/test/test_suite.cpp +++ b/test/test_suite.cpp @@ -31,6 +31,7 @@ #include "catch.hpp" #include +#include #include namespace test { @@ -1189,6 +1190,28 @@ TEST_CASE("float", "[]" ) { // out of range for float: should switch to exp notation test::sprintf(buffer, "%.1f", 1E20); REQUIRE(!strcmp(buffer, "1.0e+20")); + + // brute force float + bool fail = false; + std::stringstream str; + str.precision(5); + for (float i = -100000; i < 100000; i += 1) { + test::sprintf(buffer, "%.5f", i / 10000); + str.str(""); + str << std::fixed << i / 10000; + fail = fail || !!strcmp(buffer, str.str().c_str()); + } + REQUIRE(!fail); + + // brute force exp + str.setf(std::ios::scientific, std::ios::floatfield); + for (float i = -1e20; i < 1e20; i += 1e15) { + test::sprintf(buffer, "%.5f", i); + str.str(""); + str << i; + fail = fail || !!strcmp(buffer, str.str().c_str()); + } + REQUIRE(!fail); } -- cgit v1.2.3