aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Paland <marco@paland.com>2019-03-26 08:50:58 +0100
committerMarco Paland <marco@paland.com>2019-03-26 08:50:58 +0100
commit86846034d0bbe681ccffcef279d4e6df49aebf4a (patch)
treec67dfae0df314aec6652ca9b9b83c98f3119f0e6
parent1e288944e4e01d85a007562f5eca458bfcb2f9df (diff)
downloadprintf-86846034d0bbe681ccffcef279d4e6df49aebf4a.tar.gz
printf-86846034d0bbe681ccffcef279d4e6df49aebf4a.tar.bz2
printf-86846034d0bbe681ccffcef279d4e6df49aebf4a.zip
test(test_suite): added more float test cases
-rw-r--r--test/test_suite.cpp23
1 files changed, 23 insertions, 0 deletions
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 <string.h>
+#include <sstream>
#include <math.h>
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);
}