| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- #include "_atof.h"
- #include "../../Source/NumberToString.h"
- #ifdef JSON_SAFE
- #define assertNaN(one) assertNAN(json_number, one)
- #else
- #define assertNaN(one)
- #endif
- testNumberToString__atof::testNumberToString__atof(const std::string & name) : BaseTest(name){
- //ScopeCoverageHeap(_atof, 14);
- }
- testNumberToString__atof::~testNumberToString__atof(){
- //AssertScopeCoverageHeap(_atof);
- }
- /**
- * Tests regular positive numbers in various forms
- */
- void testNumberToString__atof::testPositive(void){
- #ifdef JSON_STRICT
- assertFloatEquals(123, NumberToString::_atof(JSON_TEXT("123")));
- assertFloatEquals(12.3, NumberToString::_atof(JSON_TEXT("12.3")));
- assertFloatEquals(0.123, NumberToString::_atof(JSON_TEXT("0.123")));
- assertFloatEquals(0, NumberToString::_atof(JSON_TEXT("0")));
- assertFloatEquals(0, NumberToString::_atof(JSON_TEXT("0.")));
- assertFloatEquals(1, NumberToString::_atof(JSON_TEXT("1.")));
- assertFloatEquals(1, NumberToString::_atof(JSON_TEXT("1")));
- assertFloatEquals(0, NumberToString::_atof(JSON_TEXT("0.0")));
- assertFloatEquals(1, NumberToString::_atof(JSON_TEXT("1.0")));
- assertFloatEquals(1.01, NumberToString::_atof(JSON_TEXT("1.01")));
- #endif
- }
- /**
- * Tests negative numbers with regular scientifc notation
- */
- void testNumberToString__atof::testNegative(void){
- #ifdef JSON_STRICT
- assertFloatEquals(-123, NumberToString::_atof(JSON_TEXT("-123")));
- assertFloatEquals(-12.3, NumberToString::_atof(JSON_TEXT("-12.3")));
- assertFloatEquals(-.123, NumberToString::_atof(JSON_TEXT("-0.123")));
- assertFloatEquals(0, NumberToString::_atof(JSON_TEXT("-0")));
- assertFloatEquals(0, NumberToString::_atof(JSON_TEXT("-0.")));
- assertFloatEquals(-1, NumberToString::_atof(JSON_TEXT("-1")));
- assertFloatEquals(-1, NumberToString::_atof(JSON_TEXT("-1.")));
- assertFloatEquals(0, NumberToString::_atof(JSON_TEXT("-0.0")));
- assertFloatEquals(-1, NumberToString::_atof(JSON_TEXT("-1.0")));
- #endif
- }
- /**
- * Tests positive numbers with scientific notiation that has a sign in it
- */
- void testNumberToString__atof::testPositive_ScientificNotation(void){
- #ifdef JSON_STRICT
- assertNAN(json_number, std::numeric_limits<json_number>::signaling_NaN()); //sanity check
- assertFloatEquals(0e3, NumberToString::_atof(JSON_TEXT("0e3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("0e3.3")));
- assertFloatEquals(1e3, NumberToString::_atof(JSON_TEXT("1.e3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("1.e3.3")));
- assertFloatEquals(1e3, NumberToString::_atof(JSON_TEXT("1.0e3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("1.0e3.3")));
-
- assertFloatEquals(0e2, NumberToString::_atof(JSON_TEXT("0e2")));
- assertFloatEquals(1e2, NumberToString::_atof(JSON_TEXT("1e2")));
- assertFloatEquals(0e2, NumberToString::_atof(JSON_TEXT("0.e2")));
- assertFloatEquals(1e2, NumberToString::_atof(JSON_TEXT("1.e2")));
- assertFloatEquals(0e2, NumberToString::_atof(JSON_TEXT("0.0e2")));
- assertFloatEquals(1e2, NumberToString::_atof(JSON_TEXT("1.0e2")));
- #endif
- }
- /**
- * Tests negative numbers with regular scientifc notation
- */
- void testNumberToString__atof::testNegative_ScientificNotation(void){
- #ifdef JSON_STRICT
- assertFloatEquals(0e3, NumberToString::_atof(JSON_TEXT("-0e3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("-0e3.3")));
- assertFloatEquals(-1e3, NumberToString::_atof(JSON_TEXT("-1.e3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("-1.e3.3")));
- assertFloatEquals(-1e3, NumberToString::_atof(JSON_TEXT("-1.0e3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("-1.0e3.3")));
-
- assertFloatEquals(0e2, NumberToString::_atof(JSON_TEXT("-0e2")));
- assertFloatEquals(-1e2, NumberToString::_atof(JSON_TEXT("-1e2")));
- assertFloatEquals(0e2, NumberToString::_atof(JSON_TEXT("-0.e2")));
- assertFloatEquals(-1e2, NumberToString::_atof(JSON_TEXT("-1.e2")));
- assertFloatEquals(0e2, NumberToString::_atof(JSON_TEXT("-0.0e2")));
- assertFloatEquals(-1e2, NumberToString::_atof(JSON_TEXT("-1.0e2")));
- #endif
- }
- /**
- * Tests positive numbers with scientific notiation that has a sign in it
- */
- void testNumberToString__atof::testPositive_SignedScientificNotation(void){
- #ifdef JSON_STRICT
- assertFloatEquals(0e-3, NumberToString::_atof(JSON_TEXT("0e-3")));
- assertFloatEquals(0e+3, NumberToString::_atof(JSON_TEXT("0e+3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("0e-3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("0e+3.3")));
- assertFloatEquals(1e-3, NumberToString::_atof(JSON_TEXT("1.e-3")));
- assertFloatEquals(1e3, NumberToString::_atof(JSON_TEXT("1.e+3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("1.e-3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("1.e+3.3")));
- assertFloatEquals(1e-3, NumberToString::_atof(JSON_TEXT("1.0e-3")));
- assertFloatEquals(1e3, NumberToString::_atof(JSON_TEXT("1.0e+3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("1.0e-3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("1.0e+3.3")));
-
- assertFloatEquals(0e2, NumberToString::_atof(JSON_TEXT("0e2")));
- assertFloatEquals(1e2, NumberToString::_atof(JSON_TEXT("1e2")));
- assertFloatEquals(0e2, NumberToString::_atof(JSON_TEXT("0.e2")));
- assertFloatEquals(1e2, NumberToString::_atof(JSON_TEXT("1.e2")));
- assertFloatEquals(0e2, NumberToString::_atof(JSON_TEXT("0.0e2")));
- assertFloatEquals(1e2, NumberToString::_atof(JSON_TEXT("1.0e2")));
- #endif
- }
- /**
- * Tests negative numbers with scientific notiation that has a sign in it
- */
- void testNumberToString__atof::testNegative_SignedScientificNotation(void){
- #ifdef JSON_STRICT
- assertFloatEquals(0e-3, NumberToString::_atof(JSON_TEXT("-0e-3")));
- assertFloatEquals(0e3, NumberToString::_atof(JSON_TEXT("-0e+3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("-0.e-3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("-0.e+3.3")));
- assertFloatEquals(-1e-3, NumberToString::_atof(JSON_TEXT("-1.e-3")));
- assertFloatEquals(-1e3, NumberToString::_atof(JSON_TEXT("-1.e+3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("-1.e-3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("-1.e+3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("-0.0e-3.3")));
- assertNaN( NumberToString::_atof(JSON_TEXT("-0.0e+3.3")));
- assertFloatEquals(-1e-3, NumberToString::_atof(JSON_TEXT("-1.0e-3")));
- assertFloatEquals(-1e3, NumberToString::_atof(JSON_TEXT("-1.0e+3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("-1.0e-3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("-1.0e+3.3")));
-
- assertFloatEquals(0e-2, NumberToString::_atof(JSON_TEXT("-0e-2")));
- assertFloatEquals(-1e-2, NumberToString::_atof(JSON_TEXT("-1e-2")));
- assertFloatEquals(0e-2, NumberToString::_atof(JSON_TEXT("-0.e-2")));
- assertFloatEquals(-1e-2, NumberToString::_atof(JSON_TEXT("-1.e-2")));
- assertFloatEquals(0e-2, NumberToString::_atof(JSON_TEXT("-0.0e-2")));
- assertFloatEquals(-1e-2, NumberToString::_atof(JSON_TEXT("-1.0e-2")));
- assertFloatEquals(0e2, NumberToString::_atof(JSON_TEXT("-0e+2")));
- assertFloatEquals(-1e2, NumberToString::_atof(JSON_TEXT("-1e+2")));
- assertFloatEquals(0e2, NumberToString::_atof(JSON_TEXT("-0.e+2")));
- assertFloatEquals(-1e2, NumberToString::_atof(JSON_TEXT("-1.e+2")));
- assertFloatEquals(0e2, NumberToString::_atof(JSON_TEXT("-0.0e+2")));
- assertFloatEquals(-1e2, NumberToString::_atof(JSON_TEXT("-1.0e+2")));
-
- assertNaN(NumberToString::_atof(JSON_TEXT("1e-0123"))); //not valid because of negative and leading zero
- #endif
- }
- void testNumberToString__atof::testStrict(void){
- #if defined(JSON_SAFE) || defined(JSON_DEBUG)
- #ifdef JSON_STRICT
- assertNaN(NumberToString::_atof(JSON_TEXT("00")));
- assertNaN(NumberToString::_atof(JSON_TEXT("00.01")));
- assertNaN(NumberToString::_atof(JSON_TEXT(".01")));
- assertNaN(NumberToString::_atof(JSON_TEXT("-.01")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+123")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+12.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0.123")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0.")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0e3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0e-3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0e+3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.e3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.e-3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.e+3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.0e3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.0e-3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.0e+3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.e3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0e3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0e-3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0e+3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.e3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.e-3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.e+3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.0e3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.0e-3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.0e+3.3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.e3.3")));
-
- assertNaN(NumberToString::_atof(JSON_TEXT("0x12FF")));
- assertNaN(NumberToString::_atof(JSON_TEXT("0128")));
- assertNaN(NumberToString::_atof(JSON_TEXT("0123")));
- assertNaN(NumberToString::_atof(JSON_TEXT("-0123")));
-
- assertNaN(NumberToString::_atof(JSON_TEXT("0xABCD")));
- assertNaN(NumberToString::_atof(JSON_TEXT("0124")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0.0")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.0")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0e2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1e2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0.e2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.e2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0.0e2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.0e2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0e-2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1e-2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0.e-2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.e-2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0.0e-2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.0e-2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0e+2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1e+2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0.e+2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.e+2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+0.0e+2")));
- assertNaN(NumberToString::_atof(JSON_TEXT("+1.0e+2")));
- #endif
- #endif
- }
- void testNumberToString__atof::testNotNumbers(void){
- #if defined(JSON_SAFE) || defined(JSON_DEBUG)
- #ifdef JSON_STRICT
- assertNaN(NumberToString::_atof(JSON_TEXT("-.")));
- assertNaN(NumberToString::_atof(JSON_TEXT("-e3")));
- assertNaN(NumberToString::_atof(JSON_TEXT("0xABCDv")));
- assertNaN(NumberToString::_atof(JSON_TEXT("00124")));
- assertNaN(NumberToString::_atof(JSON_TEXT("09124")));
- assertNaN(NumberToString::_atof(JSON_TEXT("0no")));
- assertNaN(NumberToString::_atof(JSON_TEXT("no")));
- assertNaN(NumberToString::_atof(JSON_TEXT("n1234")));
- assertNaN(NumberToString::_atof(JSON_TEXT("12no")));
- assertNaN(NumberToString::_atof(JSON_TEXT("0en5")));
- assertNaN(NumberToString::_atof(JSON_TEXT("0e")));
- assertNaN(NumberToString::_atof(JSON_TEXT("0E")));
- #endif
- #endif
- }
|