Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Unified Diff: tests/lib/math/math_parse_double_test.dart

Issue 15868003: Revert "Rewrite double.parse." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/corelib/string_trim2_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/math/math_parse_double_test.dart
diff --git a/tests/lib/math/math_parse_double_test.dart b/tests/lib/math/math_parse_double_test.dart
index f327f3e41498c915e88cdbf4b4f66e2d950baa43..af77f6b6c232105e093662b26a1c3093eb6eb54a 100644
--- a/tests/lib/math/math_parse_double_test.dart
+++ b/tests/lib/math/math_parse_double_test.dart
@@ -12,108 +12,82 @@ void parseDoubleThrowsFormatException(str) {
Expect.throws(() => double.parse(str), (e) => e is FormatException);
}
-void runTest(double expected, String input) {
- Expect.equals(expected, double.parse(input));
- Expect.equals(expected, double.parse(" $input "));
- Expect.equals(expected, double.parse(" $input"));
- Expect.equals(expected, double.parse("$input "));
- Expect.equals(expected, double.parse("+$input"));
- Expect.equals(expected, double.parse(" +$input "));
- Expect.equals(expected, double.parse("+$input "));
- Expect.equals(expected, double.parse("\xA0 $input\xA0 "));
- Expect.equals(expected, double.parse(" \xA0$input"));
- Expect.equals(expected, double.parse("$input \xA0"));
- Expect.equals(expected, double.parse("\xA0 +$input\xA0 "));
- Expect.equals(expected, double.parse("+$input\xA0 "));
- Expect.equals(expected, double.parse("\u205F $input\u205F "));
- Expect.equals(expected, double.parse(" \u180E$input"));
- Expect.equals(expected, double.parse("$input \u2006"));
- Expect.equals(expected, double.parse("\u1680 +$input\u1680 "));
- Expect.equals(-expected, double.parse("-$input"));
- Expect.equals(-expected, double.parse(" -$input "));
- Expect.equals(-expected, double.parse("-$input "));
- Expect.equals(-expected, double.parse("\xA0 -$input\xA0 "));
- Expect.equals(-expected, double.parse("-$input\xA0 "));
- Expect.equals(-expected, double.parse("\u1680 -$input\u1680 "));
-}
-
-const TESTS = const [
- [ 499.0, "499" ],
- [ 499.0, "499." ],
- [ 499.0, "499.0" ],
- [ 0.0, "0" ],
- [ 0.0, ".0" ],
- [ 0.0, "0." ],
- [ 0.1, "0.1" ],
- [ 0.1, ".1" ],
- [ 10.0, "010" ],
- [ 1.5, "1.5" ],
- [ 1.5, "001.5" ],
- [ 1.5, "1.500" ],
- [ 1234567.89, "1234567.89" ],
- [ 1234567e89, "1234567e89" ],
- [ 1234567.89e2, "1234567.89e2" ],
- [ 1234567.89e2, "1234567.89e+2" ],
- [ 1234567.89e-2, "1234567.89e-2" ],
- [ 5, "5" ],
- [ 123456700.0, "1234567.e2" ],
- [ 123456700.0, "1234567.e+2" ],
- [ double.INFINITY, "Infinity" ],
- [ 5e-324, "5e-324" ], // min-pos.
- // Same, without exponential.
- [ 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625,
- "0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625" ],
- [ 0, "2e-324" ], // underflow 0.0
- [ 0.9999999999999999, "0.9999999999999999" ], // max below 1
- [ 1, "1.00000000000000005" ], // 1.0
- [ 1.0000000000000002, "1.0000000000000002" ], // min above 1
- [ 2147483647, "2147483647" ], // max int32
- [ 2147483647.0000002, "2147483647.0000002" ], // min not int32
- [ 2147483648, "2147483648" ], // min int not int32
- [ 4295967295, "4295967295" ], // max uint32
- [ 4295967295.000001, "4295967295.000001" ], // min not uint-32
- [ 4295967296, "4295967296" ], // min int not-uint32
- [ 1.7976931348623157e+308, "1.7976931348623157e+308" ], // Max finit
- [ double.INFINITY, "1.7976931348623158e+308" ], // Infinity
- [ .049999999999999994, ".049999999999999994" ], // not 0.5
- [ .5, ".04999999999999999935" ],
- [ 4503499627370498, "4503599627370497.5" ],
- [ 1.2345678901234568e+39, "1234567890123456898981341324213421342134" ],
- [ 9.87291183742987e+24, "9872911837429871193379121" ],
- [ 1e21, "1e+21" ],
-];
-
-
void main() {
- for (var test in TESTS) {
- runTest(test[0], test[1]);
- }
-
+ Expect.equals(499.0, double.parse("499"));
+ Expect.equals(499.0, double.parse("499.0"));
+ Expect.equals(499.0, double.parse("499.0"));
+ Expect.equals(499.0, double.parse("+499"));
+ Expect.equals(-499.0, double.parse("-499"));
+ Expect.equals(499.0, double.parse(" 499 "));
+ Expect.equals(499.0, double.parse(" +499 "));
+ Expect.equals(-499.0, double.parse(" -499 "));
+ Expect.equals(0.0, double.parse("0"));
+ Expect.equals(0.0, double.parse("+0"));
+ Expect.equals(-0.0, double.parse("-0"));
Expect.equals(true, double.parse("-0").isNegative);
+ Expect.equals(0.0, double.parse(" 0 "));
+ Expect.equals(0.0, double.parse(" +0 "));
+ Expect.equals(-0.0, double.parse(" -0 "));
Expect.equals(true, double.parse(" -0 ").isNegative);
- Expect.equals(true, double.parse("\xA0 -0 \xA0").isNegative);
- Expect.isTrue(double.parse("NaN").isNaN);
- Expect.isTrue(double.parse("-NaN").isNaN);
- Expect.isTrue(double.parse("+NaN").isNaN);
- Expect.isTrue(double.parse("NaN ").isNaN);
- Expect.isTrue(double.parse("-NaN ").isNaN);
- Expect.isTrue(double.parse("+NaN ").isNaN);
- Expect.isTrue(double.parse(" NaN ").isNaN);
- Expect.isTrue(double.parse(" -NaN ").isNaN);
- Expect.isTrue(double.parse(" +NaN ").isNaN);
- Expect.isTrue(double.parse(" NaN").isNaN);
- Expect.isTrue(double.parse(" -NaN").isNaN);
- Expect.isTrue(double.parse(" +NaN").isNaN);
- Expect.isTrue(double.parse("NaN\xA0").isNaN);
- Expect.isTrue(double.parse("-NaN\xA0").isNaN);
- Expect.isTrue(double.parse("+NaN\xA0").isNaN);
- Expect.isTrue(double.parse(" \xA0NaN\xA0").isNaN);
- Expect.isTrue(double.parse(" \xA0-NaN\xA0").isNaN);
- Expect.isTrue(double.parse(" \xA0+NaN\xA0").isNaN);
- Expect.isTrue(double.parse(" \xA0NaN").isNaN);
- Expect.isTrue(double.parse(" \xA0-NaN").isNaN);
- Expect.isTrue(double.parse(" \xA0+NaN").isNaN);
-
+ Expect.equals(1.0 * 0x1234567890, double.parse("0x1234567890"));
+ Expect.equals(1.0 * -0x1234567890, double.parse("-0x1234567890"));
+ Expect.equals(1.0 * 0x1234567890, double.parse(" 0x1234567890 "));
+ Expect.equals(1.0 * -0x1234567890, double.parse(" -0x1234567890 "));
+ Expect.equals(256.0, double.parse("0x100"));
+ Expect.equals(-256.0, double.parse("-0x100"));
+ Expect.equals(256.0, double.parse(" 0x100 "));
+ Expect.equals(-256.0, double.parse(" -0x100 "));
+ Expect.equals(1.0 * 0xabcdef, double.parse("0xabcdef"));
+ Expect.equals(1.0 * 0xABCDEF, double.parse("0xABCDEF"));
+ Expect.equals(1.0 * 0xabcdef, double.parse("0xabCDEf"));
+ Expect.equals(1.0 * -0xabcdef, double.parse("-0xabcdef"));
+ Expect.equals(1.0 * -0xABCDEF, double.parse("-0xABCDEF"));
+ Expect.equals(1.0 * 0xabcdef, double.parse(" 0xabcdef "));
+ Expect.equals(1.0 * 0xABCDEF, double.parse(" 0xABCDEF "));
+ Expect.equals(1.0 * -0xabcdef, double.parse(" -0xabcdef "));
+ Expect.equals(1.0 * -0xABCDEF, double.parse(" -0xABCDEF "));
+ Expect.equals(1.0 * 0xabcdef, double.parse("0x00000abcdef"));
+ Expect.equals(1.0 * 0xABCDEF, double.parse("0x00000ABCDEF"));
+ Expect.equals(1.0 * -0xabcdef, double.parse("-0x00000abcdef"));
+ Expect.equals(1.0 * -0xABCDEF, double.parse("-0x00000ABCDEF"));
+ Expect.equals(1.0 * 0xabcdef, double.parse(" 0x00000abcdef "));
+ Expect.equals(1.0 * 0xABCDEF, double.parse(" 0x00000ABCDEF "));
+ Expect.equals(1.0 * -0xabcdef, double.parse(" -0x00000abcdef "));
+ Expect.equals(1.0 * -0xABCDEF, double.parse(" -0x00000ABCDEF "));
+ Expect.equals(10.0, double.parse("010"));
+ Expect.equals(-10.0, double.parse("-010"));
+ Expect.equals(10.0, double.parse(" 010 "));
+ Expect.equals(-10.0, double.parse(" -010 "));
+ Expect.equals(0.1, double.parse("0.1"));
+ Expect.equals(0.1, double.parse(" 0.1 "));
+ Expect.equals(0.1, double.parse(" +0.1 "));
+ Expect.equals(-0.1, double.parse(" -0.1 "));
+ Expect.equals(0.1, double.parse(".1"));
+ Expect.equals(0.1, double.parse(" .1 "));
+ Expect.equals(0.1, double.parse(" +.1 "));
+ Expect.equals(-0.1, double.parse(" -.1 "));
+ Expect.equals(1.5, double.parse("1.5"));
+ Expect.equals(1234567.89, double.parse("1234567.89"));
+ Expect.equals(1234567.89, double.parse(" 1234567.89 "));
+ Expect.equals(1234567.89, double.parse(" +1234567.89 "));
+ Expect.equals(-1234567.89, double.parse(" -1234567.89 "));
+ Expect.equals(1234567e89, double.parse("1234567e89"));
+ Expect.equals(1234567e89, double.parse(" 1234567e89 "));
+ Expect.equals(1234567e89, double.parse(" +1234567e89 "));
+ Expect.equals(-1234567e89, double.parse(" -1234567e89 "));
+ Expect.equals(1234567.89e2, double.parse("1234567.89e2"));
+ Expect.equals(1234567.89e2, double.parse(" 1234567.89e2 "));
+ Expect.equals(1234567.89e2, double.parse(" +1234567.89e2 "));
+ Expect.equals(-1234567.89e2, double.parse(" -1234567.89e2 "));
+ Expect.equals(1234567.89e2, double.parse("1234567.89E2"));
+ Expect.equals(1234567.89e2, double.parse(" 1234567.89E2 "));
+ Expect.equals(1234567.89e2, double.parse(" +1234567.89E2 "));
+ Expect.equals(-1234567.89e2, double.parse(" -1234567.89E2 "));
+ Expect.equals(1234567.89e-2, double.parse("1234567.89e-2"));
+ Expect.equals(1234567.89e-2, double.parse(" 1234567.89e-2 "));
+ Expect.equals(1234567.89e-2, double.parse(" +1234567.89e-2 "));
+ Expect.equals(-1234567.89e-2, double.parse(" -1234567.89e-2 "));
+ // TODO(floitsch): add tests for NaN and Infinity.
parseDoubleThrowsFormatException("1b");
parseDoubleThrowsFormatException(" 1b ");
parseDoubleThrowsFormatException(" 1 b ");
@@ -132,37 +106,16 @@ void main() {
parseDoubleThrowsFormatException("- 1.5");
parseDoubleThrowsFormatException("");
parseDoubleThrowsFormatException(" ");
+ parseDoubleThrowsFormatException("5.");
+ parseDoubleThrowsFormatException(" 5. ");
+ parseDoubleThrowsFormatException(" +5. ");
+ parseDoubleThrowsFormatException(" -5. ");
+ parseDoubleThrowsFormatException("1234567.e2");
+ parseDoubleThrowsFormatException(" 1234567.e2 ");
+ parseDoubleThrowsFormatException(" +1234567.e2 ");
+ parseDoubleThrowsFormatException(" -1234567.e2 ");
parseDoubleThrowsFormatException("+0x1234567890");
parseDoubleThrowsFormatException(" +0x1234567890 ");
parseDoubleThrowsFormatException(" +0x100 ");
parseDoubleThrowsFormatException("+0x100");
- parseDoubleThrowsFormatException("0x1234567890");
- parseDoubleThrowsFormatException("-0x1234567890");
- parseDoubleThrowsFormatException(" 0x1234567890 ");
- parseDoubleThrowsFormatException(" -0x1234567890 ");
- parseDoubleThrowsFormatException("0x100");
- parseDoubleThrowsFormatException("-0x100");
- parseDoubleThrowsFormatException(" 0x100 ");
- parseDoubleThrowsFormatException(" -0x100 ");
- parseDoubleThrowsFormatException("0xabcdef");
- parseDoubleThrowsFormatException("0xABCDEF");
- parseDoubleThrowsFormatException("0xabCDEf");
- parseDoubleThrowsFormatException("-0xabcdef");
- parseDoubleThrowsFormatException("-0xABCDEF");
- parseDoubleThrowsFormatException(" 0xabcdef ");
- parseDoubleThrowsFormatException(" 0xABCDEF ");
- parseDoubleThrowsFormatException(" -0xabcdef ");
- parseDoubleThrowsFormatException(" -0xABCDEF ");
- parseDoubleThrowsFormatException("0x00000abcdef");
- parseDoubleThrowsFormatException("0x00000ABCDEF");
- parseDoubleThrowsFormatException("-0x00000abcdef");
- parseDoubleThrowsFormatException("-0x00000ABCDEF");
- parseDoubleThrowsFormatException(" 0x00000abcdef ");
- parseDoubleThrowsFormatException(" 0x00000ABCDEF ");
- parseDoubleThrowsFormatException(" -0x00000abcdef ");
- parseDoubleThrowsFormatException(" -0x00000ABCDEF ");
- parseDoubleThrowsFormatException(" -INFINITY ");
- parseDoubleThrowsFormatException(" NAN ");
- parseDoubleThrowsFormatException(" inf ");
- parseDoubleThrowsFormatException(" nan ");
}
« no previous file with comments | « tests/corelib/string_trim2_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698