Commit a757a2ae authored by abolz's avatar abolz

Add more tests

Some more need to be fixed.
parent 17927781
......@@ -410,13 +410,11 @@ static void TestParseDouble() {
TEST_DOUBLE(fullPrecision, "0e-9223372036854775808", 0.0);
#endif
#if 0
if (fullPrecision)
{
// Slightly above max-normal
// Fails with "normal" precision
TEST_DOUBLE(fullPrecision, "1.7976931348623158e+308", 1.7976931348623158e+308);
#endif
#if 0
TEST_DOUBLE(fullPrecision,
"17976931348623157081452742373170435679807056752584499659891747680315726"
"07800285387605895586327668781715404589535143824642343213268894641827684"
......@@ -424,6 +422,7 @@ static void TestParseDouble() {
"30458323690322294816580855933212334827479782620414472316873817718091929"
"9881250404026184124858368",
std::numeric_limits<double>::max());
TEST_DOUBLE(fullPrecision,
"243546080556034731077856379609316893158278902575447060151047"
"212703405344938119816206067372775299130836050315842578309818"
......@@ -432,6 +431,8 @@ static void TestParseDouble() {
"828481044358810649108367633313557305310641892225870327827273"
"41408256.000000",
2.4354608055603473e+307);
}
// 9007199254740991 * 2^971 (max normal)
TEST_DOUBLE(fullPrecision,
"1.797693134862315708145274237317043567980705675258449965989174768031572607800285"
......@@ -440,6 +441,9 @@ static void TestParseDouble() {
"9332123348274797826204144723168738177180919299881250404026184124858368e+308",
1.797693134862315708e+308 // 0x1.fffffffffffffp1023
);
#if 0
// TODO:
// Should work at least in full-precision mode...
TEST_DOUBLE(fullPrecision,
"0.00000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000"
......@@ -460,6 +464,7 @@ static void TestParseDouble() {
"9083625477918694866799496832404970582102851318545139621383772"
"2826145437693412532098591327667236328125",
0.0);
#endif
// 9007199254740991 * 2^-1074 = (2^53 - 1) * 2^-1074
TEST_DOUBLE(fullPrecision,
"4.450147717014402272114819593418263951869639092703291296046852219449644444042153"
......@@ -518,7 +523,10 @@ static void TestParseDouble() {
"00000000000000000000000000000000000000000000000000000000000000000000000000000000e-308",
4.450147717014401778e-308 // 0x1.ffffffffffffep-1022
);
#if 0
// ... round up
// TODO:
// Should work at least in full-precision mode...
TEST_DOUBLE(fullPrecision,
"4.450147717014402025081996672794991863585242658592605113516950912287262231249312"
"64069530541271189424317838013700808305231545782515453032382772695923684574304409"
......@@ -534,6 +542,7 @@ static void TestParseDouble() {
"00000000000000000000000000000000000000000000000000000000000000000000000000000001e-308",
4.450147717014402272e-308 // 0x1.fffffffffffffp-1022
);
#endif
// ... round down
TEST_DOUBLE(fullPrecision,
"4.450147717014402025081996672794991863585242658592605113516950912287262231249312"
......@@ -571,7 +580,6 @@ static void TestParseDouble() {
"99999999999999999999999999999999999999999999999999999999999999999999999999999999e+308",
1.797693134862315708e+308 // 0x1.fffffffffffffp1023
);
#endif
#undef TEST_DOUBLE
}
......@@ -618,7 +626,8 @@ TEST(Reader, ParseNumber_NormalPrecisionError) {
printf("ULP Average = %g, Max = %g \n", ulpSum / count, ulpMax);
}
TEST(Reader, ParseNumber_Error) {
template<bool fullPrecision>
static void TestParseNumberError() {
#define TEST_NUMBER_ERROR(errorCode, str, errorOffset, streamPos) \
{ \
char buffer[2048]; \
......@@ -627,7 +636,7 @@ TEST(Reader, ParseNumber_Error) {
InsituStringStream s(buffer); \
BaseReaderHandler<> h; \
Reader reader; \
EXPECT_FALSE(reader.Parse(s, h)); \
EXPECT_FALSE(reader.Parse<fullPrecision ? kParseFullPrecisionFlag : 0>(s, h)); \
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
EXPECT_EQ(errorOffset, reader.GetErrorOffset());\
EXPECT_EQ(streamPos, s.Tell());\
......@@ -686,7 +695,10 @@ TEST(Reader, ParseNumber_Error) {
"76789342486548527630221960124609411945308295208500576883815068234246288147391311"
"0540827237163350510684586298239947245938479716304835356329624224137216e+308", 0, 315);
#if 0
// TODO:
// These tests (currently) fail in normal-precision mode
if (fullPrecision)
{
// Half way between max-normal and infinity
// Should round to infinity in nearest-even mode.
TEST_NUMBER_ERROR(kParseErrorNumberTooBig,
......@@ -720,11 +732,26 @@ TEST(Reader, ParseNumber_Error) {
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000001e+308", 0, 1125);
#endif
"00000000000000000000000000000000000000000000000000000000000000000000000000000001e+308", 0, 1205);
}
TEST_NUMBER_ERROR(kParseErrorNumberTooBig,
"10000000000000000000000000000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000000001", 0, 310);
#undef TEST_NUMBER_ERROR
}
TEST(Reader, ParseNumberError_NormalPrecisionDouble) {
TestParseNumberError<false>();
}
TEST(Reader, ParseNumberError_FullPrecisionDouble) {
TestParseNumberError<true>();
}
template <typename Encoding>
struct ParseStringHandler : BaseReaderHandler<Encoding, ParseStringHandler<Encoding> > {
ParseStringHandler() : str_(0), length_(0), copy_() {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment