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

Side by Side Diff: tests/corelib/src/MathParseDoubleTest.dart

Issue 10244009: test rename overhaul: step 7 - corelib tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
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.
4
5
6 bool parseDoubleThrowsBadNumberFormatException(str) {
7 try {
8 Math.parseDouble(str);
9 return false;
10 } catch (BadNumberFormatException e) {
11 return true;
12 }
13 }
14
15 void main() {
16 Expect.equals(499.0, Math.parseDouble("499"));
17 Expect.equals(499.0, Math.parseDouble("499.0"));
18 Expect.equals(499.0, Math.parseDouble("499.0"));
19 Expect.equals(499.0, Math.parseDouble("+499"));
20 Expect.equals(-499.0, Math.parseDouble("-499"));
21 Expect.equals(499.0, Math.parseDouble(" 499 "));
22 Expect.equals(499.0, Math.parseDouble(" +499 "));
23 Expect.equals(-499.0, Math.parseDouble(" -499 "));
24 Expect.equals(0.0, Math.parseDouble("0"));
25 Expect.equals(0.0, Math.parseDouble("+0"));
26 Expect.equals(-0.0, Math.parseDouble("-0"));
27 Expect.equals(true, Math.parseDouble("-0").isNegative());
28 Expect.equals(0.0, Math.parseDouble(" 0 "));
29 Expect.equals(0.0, Math.parseDouble(" +0 "));
30 Expect.equals(-0.0, Math.parseDouble(" -0 "));
31 Expect.equals(true, Math.parseDouble(" -0 ").isNegative());
32 Expect.equals(1.0 * 0x1234567890, Math.parseDouble("0x1234567890"));
33 Expect.equals(1.0 * 0x1234567890, Math.parseDouble("+0x1234567890"));
34 Expect.equals(1.0 * -0x1234567890, Math.parseDouble("-0x1234567890"));
35 Expect.equals(1.0 * 0x1234567890, Math.parseDouble(" 0x1234567890 "));
36 Expect.equals(1.0 * 0x1234567890, Math.parseDouble(" +0x1234567890 "));
37 Expect.equals(1.0 * -0x1234567890, Math.parseDouble(" -0x1234567890 "));
38 Expect.equals(256.0, Math.parseDouble("0x100"));
39 Expect.equals(256.0, Math.parseDouble("+0x100"));
40 Expect.equals(-256.0, Math.parseDouble("-0x100"));
41 Expect.equals(256.0, Math.parseDouble(" 0x100 "));
42 Expect.equals(256.0, Math.parseDouble(" +0x100 "));
43 Expect.equals(-256.0, Math.parseDouble(" -0x100 "));
44 Expect.equals(1.0 * 0xabcdef, Math.parseDouble("0xabcdef"));
45 Expect.equals(1.0 * 0xABCDEF, Math.parseDouble("0xABCDEF"));
46 Expect.equals(1.0 * 0xabcdef, Math.parseDouble("0xabCDEf"));
47 Expect.equals(1.0 * -0xabcdef, Math.parseDouble("-0xabcdef"));
48 Expect.equals(1.0 * -0xABCDEF, Math.parseDouble("-0xABCDEF"));
49 Expect.equals(1.0 * 0xabcdef, Math.parseDouble(" 0xabcdef "));
50 Expect.equals(1.0 * 0xABCDEF, Math.parseDouble(" 0xABCDEF "));
51 Expect.equals(1.0 * -0xabcdef, Math.parseDouble(" -0xabcdef "));
52 Expect.equals(1.0 * -0xABCDEF, Math.parseDouble(" -0xABCDEF "));
53 Expect.equals(1.0 * 0xabcdef, Math.parseDouble("0x00000abcdef"));
54 Expect.equals(1.0 * 0xABCDEF, Math.parseDouble("0x00000ABCDEF"));
55 Expect.equals(1.0 * -0xabcdef, Math.parseDouble("-0x00000abcdef"));
56 Expect.equals(1.0 * -0xABCDEF, Math.parseDouble("-0x00000ABCDEF"));
57 Expect.equals(1.0 * 0xabcdef, Math.parseDouble(" 0x00000abcdef "));
58 Expect.equals(1.0 * 0xABCDEF, Math.parseDouble(" 0x00000ABCDEF "));
59 Expect.equals(1.0 * -0xabcdef, Math.parseDouble(" -0x00000abcdef "));
60 Expect.equals(1.0 * -0xABCDEF, Math.parseDouble(" -0x00000ABCDEF "));
61 Expect.equals(10.0, Math.parseDouble("010"));
62 Expect.equals(-10.0, Math.parseDouble("-010"));
63 Expect.equals(10.0, Math.parseDouble(" 010 "));
64 Expect.equals(-10.0, Math.parseDouble(" -010 "));
65 Expect.equals(0.1, Math.parseDouble("0.1"));
66 Expect.equals(0.1, Math.parseDouble(" 0.1 "));
67 Expect.equals(0.1, Math.parseDouble(" +0.1 "));
68 Expect.equals(-0.1, Math.parseDouble(" -0.1 "));
69 Expect.equals(0.1, Math.parseDouble(".1"));
70 Expect.equals(0.1, Math.parseDouble(" .1 "));
71 Expect.equals(0.1, Math.parseDouble(" +.1 "));
72 Expect.equals(-0.1, Math.parseDouble(" -.1 "));
73 Expect.equals(1234567.89, Math.parseDouble("1234567.89"));
74 Expect.equals(1234567.89, Math.parseDouble(" 1234567.89 "));
75 Expect.equals(1234567.89, Math.parseDouble(" +1234567.89 "));
76 Expect.equals(-1234567.89, Math.parseDouble(" -1234567.89 "));
77 Expect.equals(1234567e89, Math.parseDouble("1234567e89"));
78 Expect.equals(1234567e89, Math.parseDouble(" 1234567e89 "));
79 Expect.equals(1234567e89, Math.parseDouble(" +1234567e89 "));
80 Expect.equals(-1234567e89, Math.parseDouble(" -1234567e89 "));
81 Expect.equals(1234567.89e2, Math.parseDouble("1234567.89e2"));
82 Expect.equals(1234567.89e2, Math.parseDouble(" 1234567.89e2 "));
83 Expect.equals(1234567.89e2, Math.parseDouble(" +1234567.89e2 "));
84 Expect.equals(-1234567.89e2, Math.parseDouble(" -1234567.89e2 "));
85 Expect.equals(1234567.89e2, Math.parseDouble("1234567.89E2"));
86 Expect.equals(1234567.89e2, Math.parseDouble(" 1234567.89E2 "));
87 Expect.equals(1234567.89e2, Math.parseDouble(" +1234567.89E2 "));
88 Expect.equals(-1234567.89e2, Math.parseDouble(" -1234567.89E2 "));
89 Expect.equals(1234567.89e-2, Math.parseDouble("1234567.89e-2"));
90 Expect.equals(1234567.89e-2, Math.parseDouble(" 1234567.89e-2 "));
91 Expect.equals(1234567.89e-2, Math.parseDouble(" +1234567.89e-2 "));
92 Expect.equals(-1234567.89e-2, Math.parseDouble(" -1234567.89e-2 "));
93 // TODO(floitsch): add tests for NaN and Infinity.
94 Expect.equals(false, parseDoubleThrowsBadNumberFormatException("1.5"));
95 Expect.equals(true, parseDoubleThrowsBadNumberFormatException("1b"));
96 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" 1b "));
97 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" 1 b "));
98 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" e3 "));
99 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" .e3 "));
100 Expect.equals(true, parseDoubleThrowsBadNumberFormatException("00x12"));
101 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" 00x12 "));
102 Expect.equals(true, parseDoubleThrowsBadNumberFormatException("-1b"));
103 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" -1b "));
104 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" -1 b "));
105 Expect.equals(true, parseDoubleThrowsBadNumberFormatException("-00x12"));
106 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" -00x12 "));
107 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" -00x12 "));
108 Expect.equals(true, parseDoubleThrowsBadNumberFormatException("0x0x12"));
109 Expect.equals(true, parseDoubleThrowsBadNumberFormatException("+ 1.5"));
110 Expect.equals(true, parseDoubleThrowsBadNumberFormatException("- 1.5"));
111 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(""));
112 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" "));
113 Expect.equals(true, parseDoubleThrowsBadNumberFormatException("5."));
114 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" 5. "));
115 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" +5. "));
116 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" -5. "));
117 Expect.equals(true, parseDoubleThrowsBadNumberFormatException("1234567.e2"));
118 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" 1234567.e2 ")) ;
119 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" +1234567.e2 ") );
120 Expect.equals(true, parseDoubleThrowsBadNumberFormatException(" -1234567.e2 ") );
121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698