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

Side by Side Diff: tests/corelib/math_parse_double_test.dart

Issue 10829459: Deprecate Math object in corelib in favor of dart:math library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 8 years, 4 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
« no previous file with comments | « tests/corelib/collection_to_string_test.dart ('k') | tests/corelib/math_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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
7 // class entirely.
8 #library('math_parse_double_test');
9 #import('dart:math', prefix: 'math');
10
11 double parseDouble(String string) {
12 num x = Math.parseDouble(string);
13 num y = math.parseDouble(string);
14 Expect.equals(x, y);
15 return x;
16 }
17
18 void parseDoubleThrowsFormatException(str) {
19 Expect.throws(() => Math.parseDouble(str), (e) => e is FormatException);
20 Expect.throws(() => math.parseDouble(str), (e) => e is FormatException);
21 }
22
23 void main() {
24 Expect.equals(499.0, parseDouble("499"));
25 Expect.equals(499.0, parseDouble("499.0"));
26 Expect.equals(499.0, parseDouble("499.0"));
27 Expect.equals(499.0, parseDouble("+499"));
28 Expect.equals(-499.0, parseDouble("-499"));
29 Expect.equals(499.0, parseDouble(" 499 "));
30 Expect.equals(499.0, parseDouble(" +499 "));
31 Expect.equals(-499.0, parseDouble(" -499 "));
32 Expect.equals(0.0, parseDouble("0"));
33 Expect.equals(0.0, parseDouble("+0"));
34 Expect.equals(-0.0, parseDouble("-0"));
35 Expect.equals(true, parseDouble("-0").isNegative());
36 Expect.equals(0.0, parseDouble(" 0 "));
37 Expect.equals(0.0, parseDouble(" +0 "));
38 Expect.equals(-0.0, parseDouble(" -0 "));
39 Expect.equals(true, parseDouble(" -0 ").isNegative());
40 Expect.equals(1.0 * 0x1234567890, parseDouble("0x1234567890"));
41 Expect.equals(1.0 * -0x1234567890, parseDouble("-0x1234567890"));
42 Expect.equals(1.0 * 0x1234567890, parseDouble(" 0x1234567890 "));
43 Expect.equals(1.0 * -0x1234567890, parseDouble(" -0x1234567890 "));
44 Expect.equals(256.0, parseDouble("0x100"));
45 Expect.equals(-256.0, parseDouble("-0x100"));
46 Expect.equals(256.0, parseDouble(" 0x100 "));
47 Expect.equals(-256.0, parseDouble(" -0x100 "));
48 Expect.equals(1.0 * 0xabcdef, parseDouble("0xabcdef"));
49 Expect.equals(1.0 * 0xABCDEF, parseDouble("0xABCDEF"));
50 Expect.equals(1.0 * 0xabcdef, parseDouble("0xabCDEf"));
51 Expect.equals(1.0 * -0xabcdef, parseDouble("-0xabcdef"));
52 Expect.equals(1.0 * -0xABCDEF, parseDouble("-0xABCDEF"));
53 Expect.equals(1.0 * 0xabcdef, parseDouble(" 0xabcdef "));
54 Expect.equals(1.0 * 0xABCDEF, parseDouble(" 0xABCDEF "));
55 Expect.equals(1.0 * -0xabcdef, parseDouble(" -0xabcdef "));
56 Expect.equals(1.0 * -0xABCDEF, parseDouble(" -0xABCDEF "));
57 Expect.equals(1.0 * 0xabcdef, parseDouble("0x00000abcdef"));
58 Expect.equals(1.0 * 0xABCDEF, parseDouble("0x00000ABCDEF"));
59 Expect.equals(1.0 * -0xabcdef, parseDouble("-0x00000abcdef"));
60 Expect.equals(1.0 * -0xABCDEF, parseDouble("-0x00000ABCDEF"));
61 Expect.equals(1.0 * 0xabcdef, parseDouble(" 0x00000abcdef "));
62 Expect.equals(1.0 * 0xABCDEF, parseDouble(" 0x00000ABCDEF "));
63 Expect.equals(1.0 * -0xabcdef, parseDouble(" -0x00000abcdef "));
64 Expect.equals(1.0 * -0xABCDEF, parseDouble(" -0x00000ABCDEF "));
65 Expect.equals(10.0, parseDouble("010"));
66 Expect.equals(-10.0, parseDouble("-010"));
67 Expect.equals(10.0, parseDouble(" 010 "));
68 Expect.equals(-10.0, parseDouble(" -010 "));
69 Expect.equals(0.1, parseDouble("0.1"));
70 Expect.equals(0.1, parseDouble(" 0.1 "));
71 Expect.equals(0.1, parseDouble(" +0.1 "));
72 Expect.equals(-0.1, parseDouble(" -0.1 "));
73 Expect.equals(0.1, parseDouble(".1"));
74 Expect.equals(0.1, parseDouble(" .1 "));
75 Expect.equals(0.1, parseDouble(" +.1 "));
76 Expect.equals(-0.1, parseDouble(" -.1 "));
77 Expect.equals(1.5, parseDouble("1.5"));
78 Expect.equals(1234567.89, parseDouble("1234567.89"));
79 Expect.equals(1234567.89, parseDouble(" 1234567.89 "));
80 Expect.equals(1234567.89, parseDouble(" +1234567.89 "));
81 Expect.equals(-1234567.89, parseDouble(" -1234567.89 "));
82 Expect.equals(1234567e89, parseDouble("1234567e89"));
83 Expect.equals(1234567e89, parseDouble(" 1234567e89 "));
84 Expect.equals(1234567e89, parseDouble(" +1234567e89 "));
85 Expect.equals(-1234567e89, parseDouble(" -1234567e89 "));
86 Expect.equals(1234567.89e2, parseDouble("1234567.89e2"));
87 Expect.equals(1234567.89e2, parseDouble(" 1234567.89e2 "));
88 Expect.equals(1234567.89e2, parseDouble(" +1234567.89e2 "));
89 Expect.equals(-1234567.89e2, parseDouble(" -1234567.89e2 "));
90 Expect.equals(1234567.89e2, parseDouble("1234567.89E2"));
91 Expect.equals(1234567.89e2, parseDouble(" 1234567.89E2 "));
92 Expect.equals(1234567.89e2, parseDouble(" +1234567.89E2 "));
93 Expect.equals(-1234567.89e2, parseDouble(" -1234567.89E2 "));
94 Expect.equals(1234567.89e-2, parseDouble("1234567.89e-2"));
95 Expect.equals(1234567.89e-2, parseDouble(" 1234567.89e-2 "));
96 Expect.equals(1234567.89e-2, parseDouble(" +1234567.89e-2 "));
97 Expect.equals(-1234567.89e-2, parseDouble(" -1234567.89e-2 "));
98 // TODO(floitsch): add tests for NaN and Infinity.
99 parseDoubleThrowsFormatException("1b");
100 parseDoubleThrowsFormatException(" 1b ");
101 parseDoubleThrowsFormatException(" 1 b ");
102 parseDoubleThrowsFormatException(" e3 ");
103 parseDoubleThrowsFormatException(" .e3 ");
104 parseDoubleThrowsFormatException("00x12");
105 parseDoubleThrowsFormatException(" 00x12 ");
106 parseDoubleThrowsFormatException("-1b");
107 parseDoubleThrowsFormatException(" -1b ");
108 parseDoubleThrowsFormatException(" -1 b ");
109 parseDoubleThrowsFormatException("-00x12");
110 parseDoubleThrowsFormatException(" -00x12 ");
111 parseDoubleThrowsFormatException(" -00x12 ");
112 parseDoubleThrowsFormatException("0x0x12");
113 parseDoubleThrowsFormatException("+ 1.5");
114 parseDoubleThrowsFormatException("- 1.5");
115 parseDoubleThrowsFormatException("");
116 parseDoubleThrowsFormatException(" ");
117 parseDoubleThrowsFormatException("5.");
118 parseDoubleThrowsFormatException(" 5. ");
119 parseDoubleThrowsFormatException(" +5. ");
120 parseDoubleThrowsFormatException(" -5. ");
121 parseDoubleThrowsFormatException("1234567.e2");
122 parseDoubleThrowsFormatException(" 1234567.e2 ");
123 parseDoubleThrowsFormatException(" +1234567.e2 ");
124 parseDoubleThrowsFormatException(" -1234567.e2 ");
125 parseDoubleThrowsFormatException("+0x1234567890");
126 parseDoubleThrowsFormatException(" +0x1234567890 ");
127 parseDoubleThrowsFormatException(" +0x100 ");
128 parseDoubleThrowsFormatException("+0x100");
129 }
OLDNEW
« no previous file with comments | « tests/corelib/collection_to_string_test.dart ('k') | tests/corelib/math_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698