Skip to content

Commit 8684603

Browse files
committed
test(test_suite): added more float test cases
1 parent 1e28894 commit 8684603

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

test/test_suite.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "catch.hpp"
3232

3333
#include <string.h>
34+
#include <sstream>
3435
#include <math.h>
3536

3637
namespace test {
@@ -1189,6 +1190,28 @@ TEST_CASE("float", "[]" ) {
11891190
// out of range for float: should switch to exp notation
11901191
test::sprintf(buffer, "%.1f", 1E20);
11911192
REQUIRE(!strcmp(buffer, "1.0e+20"));
1193+
1194+
// brute force float
1195+
bool fail = false;
1196+
std::stringstream str;
1197+
str.precision(5);
1198+
for (float i = -100000; i < 100000; i += 1) {
1199+
test::sprintf(buffer, "%.5f", i / 10000);
1200+
str.str("");
1201+
str << std::fixed << i / 10000;
1202+
fail = fail || !!strcmp(buffer, str.str().c_str());
1203+
}
1204+
REQUIRE(!fail);
1205+
1206+
// brute force exp
1207+
str.setf(std::ios::scientific, std::ios::floatfield);
1208+
for (float i = -1e20; i < 1e20; i += 1e15) {
1209+
test::sprintf(buffer, "%.5f", i);
1210+
str.str("");
1211+
str << i;
1212+
fail = fail || !!strcmp(buffer, str.str().c_str());
1213+
}
1214+
REQUIRE(!fail);
11921215
}
11931216

11941217

0 commit comments

Comments
 (0)