main() { tryIt("goodFile.txt"); tryIt("badAccess.txt"); tryIt("badName.txt"); }
void IntlTestNumberFormat::testFormat(/* char* par */) { if (U_FAILURE(fStatus)) { dataerrln((UnicodeString)"**** FAIL: createXxxInstance failed. - " + u_errorName(fStatus)); if (fFormat != 0) errln("**** FAIL: Non-null format returned by createXxxInstance upon failure."); delete fFormat; fFormat = 0; return; } if (fFormat == 0) { errln((UnicodeString)"**** FAIL: Null format returned by createXxxInstance."); return; } UnicodeString str; // Assume it's a DecimalFormat and get some info DecimalFormat *s = (DecimalFormat*)fFormat; logln((UnicodeString)" Pattern " + s->toPattern(str)); #if defined(OS390) || defined(OS400) tryIt(-2.02147304840132e-68); tryIt(3.88057859588817e-68); // Test rounding when only some digits are shown because exponent is close to -maxfrac tryIt(-2.64651110485945e+65); // Overflows to +INF when shown as a percent tryIt(9.29526819488338e+64); // Ok -- used to fail? #else tryIt(-2.02147304840132e-100); tryIt(3.88057859588817e-096); // Test rounding when only some digits are shown because exponent is close to -maxfrac tryIt(-2.64651110485945e+306); // Overflows to +INF when shown as a percent tryIt(9.29526819488338e+250); // Ok -- used to fail? #endif // These PASS now, with the sprintf/atof based format-parse. // These fail due to round-off // The least significant digit drops by one during each format-parse cycle. // Both numbers DON'T have a round-off problem when multiplied by 100! (shown as %) #ifdef OS390 tryIt(-9.18228054496402e+64); tryIt(-9.69413034454191e+64); #else tryIt(-9.18228054496402e+255); tryIt(-9.69413034454191e+273); #endif #ifndef OS390 tryIt(1.234e-200); tryIt(-2.3e-168); tryIt(uprv_getNaN()); tryIt(uprv_getInfinity()); tryIt(-uprv_getInfinity()); #endif tryIt((int32_t)251887531); tryIt(5e-20 / 9); tryIt(5e20 / 9); tryIt(1.234e-50); tryIt(9.99999999999996); tryIt(9.999999999999996); tryIt((int32_t)INT32_MIN); tryIt((int32_t)INT32_MAX); tryIt((double)INT32_MIN); tryIt((double)INT32_MAX); tryIt((double)INT32_MIN - 1.0); tryIt((double)INT32_MAX + 1.0); tryIt(5.0 / 9.0 * 1e-20); tryIt(4.0 / 9.0 * 1e-20); tryIt(5.0 / 9.0 * 1e+20); tryIt(4.0 / 9.0 * 1e+20); tryIt(2147483647.); tryIt((int32_t)0); tryIt(0.0); tryIt((int32_t)1); tryIt((int32_t)10); tryIt((int32_t)100); tryIt((int32_t)-1); tryIt((int32_t)-10); tryIt((int32_t)-100); tryIt((int32_t)-1913860352); for (int32_t z=0; z<10; ++z) { double d = randFraction() * 2e10 - 1e10; tryIt(d); } double it = getSafeDouble(100000.0); tryIt(0.0); tryIt(it); tryIt((int32_t)0); tryIt(uprv_floor(it)); tryIt((int32_t)randLong()); // try again it = getSafeDouble(100.0); tryIt(it); tryIt(uprv_floor(it)); tryIt((int32_t)randLong()); // try again with very large numbers it = getSafeDouble(100000000000.0); tryIt(it); // try again with very large numbers // and without going outside of the int32_t range it = randFraction() * INT32_MAX; tryIt(it); tryIt((int32_t)uprv_floor(it)); delete fFormat; }