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

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

Issue 2987793002: Migrate test block 7 to Dart 2.0. (Closed)
Patch Set: Final review comment, dropping static multitest Created 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 import "package:expect/expect.dart";
6
7 main() {
8 Duration d;
9 d = new Duration(days: 1);
10 Expect.equals(86400000000, d.inMicroseconds);
11 Expect.equals(86400000, d.inMilliseconds);
12 Expect.equals(86400, d.inSeconds);
13 Expect.equals(1440, d.inMinutes);
14 Expect.equals(24, d.inHours);
15 Expect.equals(1, d.inDays);
16 d = const Duration(hours: 1);
17 Expect.equals(3600000000, d.inMicroseconds);
18 Expect.equals(3600000, d.inMilliseconds);
19 Expect.equals(3600, d.inSeconds);
20 Expect.equals(60, d.inMinutes);
21 Expect.equals(1, d.inHours);
22 Expect.equals(0, d.inDays);
23 d = new Duration(minutes: 1);
24 Expect.equals(60000000, d.inMicroseconds);
25 Expect.equals(60000, d.inMilliseconds);
26 Expect.equals(60, d.inSeconds);
27 Expect.equals(1, d.inMinutes);
28 Expect.equals(0, d.inHours);
29 Expect.equals(0, d.inDays);
30 d = const Duration(seconds: 1);
31 Expect.equals(1000000, d.inMicroseconds);
32 Expect.equals(1000, d.inMilliseconds);
33 Expect.equals(1, d.inSeconds);
34 Expect.equals(0, d.inMinutes);
35 Expect.equals(0, d.inHours);
36 Expect.equals(0, d.inDays);
37 d = new Duration(milliseconds: 1);
38 Expect.equals(1000, d.inMicroseconds);
39 Expect.equals(1, d.inMilliseconds);
40 Expect.equals(0, d.inSeconds);
41 Expect.equals(0, d.inMinutes);
42 Expect.equals(0, d.inHours);
43 Expect.equals(0, d.inDays);
44 d = new Duration(microseconds: 1);
45 Expect.equals(1, d.inMicroseconds);
46 Expect.equals(0, d.inMilliseconds);
47 Expect.equals(0, d.inSeconds);
48 Expect.equals(0, d.inMinutes);
49 Expect.equals(0, d.inHours);
50 Expect.equals(0, d.inDays);
51
52 d = const Duration(milliseconds: 1, microseconds: 999);
53 Expect.equals(1999, d.inMicroseconds);
54 Expect.equals(1, d.inMilliseconds);
55 d = const Duration(seconds: 1, milliseconds: 999);
56 Expect.equals(1999, d.inMilliseconds);
57 Expect.equals(1, d.inSeconds);
58 d = new Duration(minutes: 1, seconds: 59);
59 Expect.equals(119, d.inSeconds);
60 Expect.equals(1, d.inMinutes);
61 d = const Duration(hours: 1, minutes: 59);
62 Expect.equals(119, d.inMinutes);
63 Expect.equals(1, d.inHours);
64 d = new Duration(days: 1, hours: 23);
65 Expect.equals(47, d.inHours);
66 Expect.equals(1, d.inDays);
67 d = const Duration(
68 days: 0,
69 hours: 23,
70 minutes: 59,
71 seconds: 59,
72 milliseconds: 999,
73 microseconds: 999);
74 Expect.equals(0, d.inDays);
75
76 d = new Duration(days: -1);
77 Expect.equals(-86400000000, d.inMicroseconds);
78 Expect.equals(-86400000, d.inMilliseconds);
79 Expect.equals(-86400, d.inSeconds);
80 Expect.equals(-1440, d.inMinutes);
81 Expect.equals(-24, d.inHours);
82 Expect.equals(-1, d.inDays);
83 d = const Duration(hours: -1);
84 Expect.equals(-3600000000, d.inMicroseconds);
85 Expect.equals(-3600000, d.inMilliseconds);
86 Expect.equals(-3600, d.inSeconds);
87 Expect.equals(-60, d.inMinutes);
88 Expect.equals(-1, d.inHours);
89 Expect.equals(0, d.inDays);
90 d = new Duration(minutes: -1);
91 Expect.equals(-60000000, d.inMicroseconds);
92 Expect.equals(-60000, d.inMilliseconds);
93 Expect.equals(-60, d.inSeconds);
94 Expect.equals(-1, d.inMinutes);
95 Expect.equals(0, d.inHours);
96 Expect.equals(0, d.inDays);
97 d = const Duration(seconds: -1);
98 Expect.equals(-1000000, d.inMicroseconds);
99 Expect.equals(-1000, d.inMilliseconds);
100 Expect.equals(-1, d.inSeconds);
101 Expect.equals(0, d.inMinutes);
102 Expect.equals(0, d.inHours);
103 Expect.equals(0, d.inDays);
104 d = new Duration(milliseconds: -1);
105 Expect.equals(-1000, d.inMicroseconds);
106 Expect.equals(-1, d.inMilliseconds);
107 Expect.equals(0, d.inSeconds);
108 Expect.equals(0, d.inMinutes);
109 Expect.equals(0, d.inHours);
110 Expect.equals(0, d.inDays);
111 d = new Duration(microseconds: -1);
112 Expect.equals(-1, d.inMicroseconds);
113 Expect.equals(0, d.inMilliseconds);
114 Expect.equals(0, d.inSeconds);
115 Expect.equals(0, d.inMinutes);
116 Expect.equals(0, d.inHours);
117 Expect.equals(0, d.inDays);
118
119 d = const Duration(days: 1, hours: -24);
120 Expect.equals(0, d.inMicroseconds);
121 d = new Duration(hours: 1, minutes: -60);
122 Expect.equals(0, d.inMicroseconds);
123 d = const Duration(minutes: 1, seconds: -60);
124 Expect.equals(0, d.inMicroseconds);
125 d = new Duration(seconds: 1, milliseconds: -1000);
126 Expect.equals(0, d.inMicroseconds);
127 d = new Duration(milliseconds: 1, microseconds: -1000);
128 Expect.equals(0, d.inMicroseconds);
129
130 d = const Duration(hours: 25);
131 Expect.equals(1, d.inDays);
132 Expect.equals(25, d.inHours);
133 Expect.equals(1500, d.inMinutes);
134 Expect.equals(90000, d.inSeconds);
135 Expect.equals(90000000, d.inMilliseconds);
136 Expect.equals(90000000000, d.inMicroseconds);
137 d = new Duration(minutes: 61);
138 Expect.equals(0, d.inDays);
139 Expect.equals(1, d.inHours);
140 Expect.equals(61, d.inMinutes);
141 Expect.equals(3660, d.inSeconds);
142 Expect.equals(3660000, d.inMilliseconds);
143 Expect.equals(3660000000, d.inMicroseconds);
144 d = const Duration(seconds: 61);
145 Expect.equals(0, d.inDays);
146 Expect.equals(0, d.inHours);
147 Expect.equals(1, d.inMinutes);
148 Expect.equals(61, d.inSeconds);
149 Expect.equals(61000, d.inMilliseconds);
150 Expect.equals(61000000, d.inMicroseconds);
151 d = new Duration(milliseconds: 1001);
152 Expect.equals(0, d.inDays);
153 Expect.equals(0, d.inHours);
154 Expect.equals(0, d.inMinutes);
155 Expect.equals(1, d.inSeconds);
156 Expect.equals(1001, d.inMilliseconds);
157 Expect.equals(1001000, d.inMicroseconds);
158 d = new Duration(microseconds: 1001);
159 Expect.equals(0, d.inDays);
160 Expect.equals(0, d.inHours);
161 Expect.equals(0, d.inMinutes);
162 Expect.equals(0, d.inSeconds);
163 Expect.equals(1, d.inMilliseconds);
164 Expect.equals(1001, d.inMicroseconds);
165
166 var d1 = const Duration(milliseconds: 1000);
167 var d2 = const Duration(seconds: 1);
168 Expect.identical(d1, d2);
169
170 d1 = const Duration(microseconds: 1000);
171 d2 = const Duration(milliseconds: 1);
172 Expect.identical(d1, d2);
173
174 d1 = new Duration(hours: 1);
175 d2 = new Duration(hours: -1);
176 d = d1 + d2;
177 Expect.equals(0, d.inMicroseconds);
178 d = d1 - d2;
179 Expect.equals(3600000000 * 2, d.inMicroseconds);
180
181 d2 = new Duration(hours: 1);
182 d = d1 + d2;
183 Expect.equals(3600000000 * 2, d.inMicroseconds);
184 d = d1 - d2;
185 Expect.equals(0, d.inMicroseconds);
186
187 d = d1 * 2;
188 Expect.equals(3600000000 * 2, d.inMicroseconds);
189 d = d1 * -1;
190 Expect.equals(-3600000000, d.inMicroseconds);
191 d = d1 * 0;
192 Expect.equals(0, d.inMicroseconds);
193
194 d = d1 ~/ 2;
195 Expect.equals(1800000000, d.inMicroseconds);
196 d = d1 ~/ 3600000001;
197 Expect.equals(0, d.inMicroseconds);
198 d = d1 ~/ -3600000001;
199 Expect.equals(0, d.inMicroseconds);
200 d = d1 ~/ 3599999999;
201 Expect.equals(1, d.inMicroseconds);
202 d = d1 ~/ -3599999999;
203 Expect.equals(-1, d.inMicroseconds);
204 d = d1 ~/ -1;
205 Expect.equals(-3600000000, d.inMicroseconds);
206 d = d1 * 0;
207 Expect.equals(0, d.inMicroseconds);
208 Expect.throws(() => d1 ~/ 0, (e) => e is IntegerDivisionByZeroException);
209
210 d = new Duration(microseconds: 0);
211 Expect.isTrue(d < new Duration(microseconds: 1));
212 Expect.isTrue(d <= new Duration(microseconds: 1));
213 Expect.isTrue(d <= d);
214 Expect.isTrue(d > new Duration(microseconds: -1));
215 Expect.isTrue(d >= new Duration(microseconds: -1));
216 Expect.isTrue(d >= d);
217
218 d = const Duration(
219 days: 1,
220 hours: 3,
221 minutes: 17,
222 seconds: 42,
223 milliseconds: 823,
224 microseconds: 127);
225 Expect.equals("27:17:42.823127", d.toString());
226
227 d = const Duration(hours: 1999, minutes: 17, seconds: 42);
228 Expect.equals("1999:17:42.000000", d.toString());
229
230 d = const Duration(
231 days: -1,
232 hours: -3,
233 minutes: -17,
234 seconds: -42,
235 milliseconds: -823,
236 microseconds: -127);
237 Expect.equals("-27:17:42.823127", d.toString());
238
239 d = const Duration(hours: -1999, minutes: -17, seconds: -42);
240 Expect.equals("-1999:17:42.000000", d.toString());
241
242 // Edge conditions for toString of microseconds.
243 // Regression test for http://dartbug.com/15678
244
245 d = const Duration(microseconds: 1);
246 Expect.equals("0:00:00.000001", d.toString());
247
248 d = const Duration(microseconds: 9);
249 Expect.equals("0:00:00.000009", d.toString());
250
251 d = const Duration(microseconds: 10);
252 Expect.equals("0:00:00.000010", d.toString());
253
254 d = const Duration(microseconds: 99);
255 Expect.equals("0:00:00.000099", d.toString());
256
257 d = const Duration(microseconds: 100);
258 Expect.equals("0:00:00.000100", d.toString());
259
260 d = const Duration(microseconds: 999);
261 Expect.equals("0:00:00.000999", d.toString());
262
263 d = const Duration(microseconds: 1000);
264 Expect.equals("0:00:00.001000", d.toString());
265
266 d = const Duration(microseconds: 9999);
267 Expect.equals("0:00:00.009999", d.toString());
268
269 d = const Duration(microseconds: 10000);
270 Expect.equals("0:00:00.010000", d.toString());
271
272 d = const Duration(microseconds: 99999);
273 Expect.equals("0:00:00.099999", d.toString());
274
275 d = const Duration(microseconds: 100000);
276 Expect.equals("0:00:00.100000", d.toString());
277
278 d = const Duration(microseconds: 999999);
279 Expect.equals("0:00:00.999999", d.toString());
280
281 d = const Duration(microseconds: 1000000);
282 Expect.equals("0:00:01.000000", d.toString());
283
284 d1 = const Duration(hours: 1);
285 d2 = const Duration(hours: -1);
286 Expect.isFalse(d1.isNegative);
287 Expect.isTrue(d2.isNegative);
288 Expect.equals(d1, d1.abs());
289 Expect.equals(d1, d2.abs());
290
291 Expect.equals(d2, -d1);
292 Expect.equals(d1, -d2);
293 }
OLDNEW
« no previous file with comments | « tests/corelib/duration_double_multiplication_test.dart ('k') | tests/corelib/error_stack_trace1_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698