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

Side by Side Diff: tests/lib/math/math_parse_double_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // We temporarily test both the new math library and the old Math 5 // We temporarily test both the new math library and the old Math
6 // class. This can easily be simplified once we get rid of the Math 6 // class. This can easily be simplified once we get rid of the Math
7 // class entirely. 7 // class entirely.
8 library math_parse_double_test; 8 library math_parse_double_test;
9
9 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
10 11
11 void parseDoubleThrowsFormatException(str) { 12 void parseDoubleThrowsFormatException(str) {
12 Expect.throws(() => double.parse(str), (e) => e is FormatException); 13 Expect.throws(() => double.parse(str), (e) => e is FormatException);
13 } 14 }
14 15
15 void runTest(double expected, String input) { 16 void runTest(double expected, String input) {
16 Expect.equals(expected, double.parse(input)); 17 Expect.equals(expected, double.parse(input));
17 Expect.equals(expected, double.parse(" $input ")); 18 Expect.equals(expected, double.parse(" $input "));
18 Expect.equals(expected, double.parse(" $input")); 19 Expect.equals(expected, double.parse(" $input"));
(...skipping 11 matching lines...) Expand all
30 Expect.equals(expected, double.parse("\u1680 +$input\u1680 ")); 31 Expect.equals(expected, double.parse("\u1680 +$input\u1680 "));
31 Expect.equals(-expected, double.parse("-$input")); 32 Expect.equals(-expected, double.parse("-$input"));
32 Expect.equals(-expected, double.parse(" -$input ")); 33 Expect.equals(-expected, double.parse(" -$input "));
33 Expect.equals(-expected, double.parse("-$input ")); 34 Expect.equals(-expected, double.parse("-$input "));
34 Expect.equals(-expected, double.parse("\xA0 -$input\xA0 ")); 35 Expect.equals(-expected, double.parse("\xA0 -$input\xA0 "));
35 Expect.equals(-expected, double.parse("-$input\xA0 ")); 36 Expect.equals(-expected, double.parse("-$input\xA0 "));
36 Expect.equals(-expected, double.parse("\u1680 -$input\u1680 ")); 37 Expect.equals(-expected, double.parse("\u1680 -$input\u1680 "));
37 } 38 }
38 39
39 final TESTS = [ 40 final TESTS = [
40 [ 499.0, "499" ], 41 [499.0, "499"],
41 [ 499.0, "499." ], 42 [499.0, "499."],
42 [ 499.0, "499.0" ], 43 [499.0, "499.0"],
43 [ 0.0, "0" ], 44 [0.0, "0"],
44 [ 0.0, ".0" ], 45 [0.0, ".0"],
45 [ 0.0, "0." ], 46 [0.0, "0."],
46 [ 0.1, "0.1" ], 47 [0.1, "0.1"],
47 [ 0.1, ".1" ], 48 [0.1, ".1"],
48 [ 10.0, "010" ], 49 [10.0, "010"],
49 [ 1.5, "1.5" ], 50 [1.5, "1.5"],
50 [ 1.5, "001.5" ], 51 [1.5, "001.5"],
51 [ 1.5, "1.500" ], 52 [1.5, "1.500"],
52 [ 1234567.89, "1234567.89" ], 53 [1234567.89, "1234567.89"],
53 [ 1234567e89, "1234567e89" ], 54 [1234567e89, "1234567e89"],
54 [ 1234567.89e2, "1234567.89e2" ], 55 [1234567.89e2, "1234567.89e2"],
55 [ 1234567.89e2, "1234567.89e+2" ], 56 [1234567.89e2, "1234567.89e+2"],
56 [ 1234567.89e-2, "1234567.89e-2" ], 57 [1234567.89e-2, "1234567.89e-2"],
57 [ 5.0, "5" ], 58 [5.0, "5"],
58 [ 123456700.0, "1234567.e2" ], 59 [123456700.0, "1234567.e2"],
59 [ 123456700.0, "1234567.e+2" ], 60 [123456700.0, "1234567.e+2"],
60 [ double.INFINITY, "Infinity" ], 61 [double.INFINITY, "Infinity"],
61 [ 5e-324, "5e-324" ], // min-pos. 62 [5e-324, "5e-324"], // min-pos.
62 // Same, without exponential. 63 // Same, without exponential.
63 [ 0.00000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000049406564584124654417656879286822137236505980261432476442558568250067550 72702087518652998363616359923797965646954457177309266567103559397963987747960107 81878126300713190311404527845817167848982103688718636056998730723050006387409153 56498438731247339727316961514003171538539807412623856559117102665855668676818703 95603106249319452715914924553293054565444011274801297099995419319894090804165633 24524757147869014726780159355238611550134803526493472019379026810710749170333222 68447533357208324319360923828934583680601060115061698097530783422773183292479049 82524730776375927247874656084778203734469699533647017972677717585125660551199131 50489110145103786273816725095583738973359899366480994116420570263709027924276754 4565229087538682506419718265533447265625, 64 [
64 "0.0000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000004940656458412465441765687928682213723650598026143247644255856825006755 07270208751865299836361635992379796564695445717730926656710355939796398774796010 78187812630071319031140452784581716784898210368871863605699873072305000638740915 35649843873124733972731696151400317153853980741262385655911710266585566867681870 39560310624931945271591492455329305456544401127480129709999541931989409080416563 32452475714786901472678015935523861155013480352649347201937902681071074917033322 26844753335720832431936092382893458368060106011506169809753078342277318329247904 98252473077637592724787465608477820373446969953364701797267771758512566055119913 15048911014510378627381672509558373897335989936648099411642057026370902792427675 44565229087538682506419718265533447265625" ], 65 0.00000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000049406564584124654417656879286822137236505980261432476442558568250067550 72702087518652998363616359923797965646954457177309266567103559397963987747960107 81878126300713190311404527845817167848982103688718636056998730723050006387409153 56498438731247339727316961514003171538539807412623856559117102665855668676818703 95603106249319452715914924553293054565444011274801297099995419319894090804165633 24524757147869014726780159355238611550134803526493472019379026810710749170333222 68447533357208324319360923828934583680601060115061698097530783422773183292479049 82524730776375927247874656084778203734469699533647017972677717585125660551199131 50489110145103786273816725095583738973359899366480994116420570263709027924276754 4565229087538682506419718265533447265625,
65 [ 0.0, "2e-324" ], // underflow 0.0 66 "0.0000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000004940656458412465441765687928682213723650598026143247644255856825006755 07270208751865299836361635992379796564695445717730926656710355939796398774796010 78187812630071319031140452784581716784898210368871863605699873072305000638740915 35649843873124733972731696151400317153853980741262385655911710266585566867681870 39560310624931945271591492455329305456544401127480129709999541931989409080416563 32452475714786901472678015935523861155013480352649347201937902681071074917033322 26844753335720832431936092382893458368060106011506169809753078342277318329247904 98252473077637592724787465608477820373446969953364701797267771758512566055119913 15048911014510378627381672509558373897335989936648099411642057026370902792427675 44565229087538682506419718265533447265625"
66 [ 0.9999999999999999, "0.9999999999999999" ], // max below 1 67 ],
67 [ 1.0, "1.00000000000000005" ], // 1.0 68 [0.0, "2e-324"], // underflow 0.0
68 [ 1.0000000000000002, "1.0000000000000002" ], // min above 1 69 [0.9999999999999999, "0.9999999999999999"], // max below 1
69 [ 2147483647.0, "2147483647" ], // max int32 70 [1.0, "1.00000000000000005"], // 1.0
70 [ 2147483647.0000002, "2147483647.0000002" ], // min not int32 71 [1.0000000000000002, "1.0000000000000002"], // min above 1
71 [ 2147483648.0, "2147483648" ], // min int not int32 72 [2147483647.0, "2147483647"], // max int32
72 [ 4295967295.0, "4295967295" ], // max uint32 73 [2147483647.0000002, "2147483647.0000002"], // min not int32
73 [ 4295967295.000001, "4295967295.000001" ], // min not uint-32 74 [2147483648.0, "2147483648"], // min int not int32
74 [ 4295967296.0, "4295967296" ], // min int not-uint32 75 [4295967295.0, "4295967295"], // max uint32
75 [ 1.7976931348623157e+308, "1.7976931348623157e+308" ], // Max finit 76 [4295967295.000001, "4295967295.000001"], // min not uint-32
76 [ 1.7976931348623157e+308, "1.7976931348623158e+308" ], // Max finit 77 [4295967296.0, "4295967296"], // min int not-uint32
77 [ double.INFINITY, "1.7976931348623159e+308" ], // Infinity 78 [1.7976931348623157e+308, "1.7976931348623157e+308"], // Max finit
78 [ .049999999999999994, ".049999999999999994" ], // not 0.5 79 [1.7976931348623157e+308, "1.7976931348623158e+308"], // Max finit
79 [ .05, ".04999999999999999935" ], 80 [double.INFINITY, "1.7976931348623159e+308"], // Infinity
80 [ 4503599627370498.0, "4503599627370497.5" ], 81 [.049999999999999994, ".049999999999999994"], // not 0.5
81 [ 1.2345678901234568e+39, "1234567890123456898981341324213421342134" ], 82 [.05, ".04999999999999999935"],
82 [ 9.87291183742987e+24, "9872911837429871193379121" ], 83 [4503599627370498.0, "4503599627370497.5"],
83 [ 1e21, "1e+21" ], 84 [1.2345678901234568e+39, "1234567890123456898981341324213421342134"],
85 [9.87291183742987e+24, "9872911837429871193379121"],
86 [1e21, "1e+21"],
84 ]; 87 ];
85 88
86
87 void main() { 89 void main() {
88 for (var test in TESTS) { 90 for (var test in TESTS) {
89 runTest(test[0], test[1]); 91 runTest(test[0], test[1]);
90 } 92 }
91 93
92 Expect.equals(true, double.parse("-0").isNegative); 94 Expect.equals(true, double.parse("-0").isNegative);
93 Expect.equals(true, double.parse(" -0 ").isNegative); 95 Expect.equals(true, double.parse(" -0 ").isNegative);
94 Expect.equals(true, double.parse("\xA0 -0 \xA0").isNegative); 96 Expect.equals(true, double.parse("\xA0 -0 \xA0").isNegative);
95 Expect.isTrue(double.parse("NaN").isNaN); 97 Expect.isTrue(double.parse("NaN").isNaN);
96 Expect.isTrue(double.parse("-NaN").isNaN); 98 Expect.isTrue(double.parse("-NaN").isNaN);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 parseDoubleThrowsFormatException("-0x00000ABCDEF"); 161 parseDoubleThrowsFormatException("-0x00000ABCDEF");
160 parseDoubleThrowsFormatException(" 0x00000abcdef "); 162 parseDoubleThrowsFormatException(" 0x00000abcdef ");
161 parseDoubleThrowsFormatException(" 0x00000ABCDEF "); 163 parseDoubleThrowsFormatException(" 0x00000ABCDEF ");
162 parseDoubleThrowsFormatException(" -0x00000abcdef "); 164 parseDoubleThrowsFormatException(" -0x00000abcdef ");
163 parseDoubleThrowsFormatException(" -0x00000ABCDEF "); 165 parseDoubleThrowsFormatException(" -0x00000ABCDEF ");
164 parseDoubleThrowsFormatException(" -INFINITY "); 166 parseDoubleThrowsFormatException(" -INFINITY ");
165 parseDoubleThrowsFormatException(" NAN "); 167 parseDoubleThrowsFormatException(" NAN ");
166 parseDoubleThrowsFormatException(" inf "); 168 parseDoubleThrowsFormatException(" inf ");
167 parseDoubleThrowsFormatException(" nan "); 169 parseDoubleThrowsFormatException(" nan ");
168 } 170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698