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

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

Issue 12221087: Add +, - and * to Duration. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added ~/ operator. Created 7 years, 10 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 | « sdk/lib/core/duration.dart ('k') | no next file » | 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) 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 main() {
6 Duration d;
7 d = new Duration(days: 1);
8 Expect.equals(86400000, d.inMilliseconds);
9 Expect.equals(86400, d.inSeconds);
10 Expect.equals(1440, d.inMinutes);
11 Expect.equals(24, d.inHours);
12 Expect.equals(1, d.inDays);
13 d = const Duration(hours: 1);
14 Expect.equals(3600000, d.inMilliseconds);
15 Expect.equals(3600, d.inSeconds);
16 Expect.equals(60, d.inMinutes);
17 Expect.equals(1, d.inHours);
18 Expect.equals(0, d.inDays);
19 d = new Duration(minutes: 1);
20 Expect.equals(60000, d.inMilliseconds);
21 Expect.equals(60, d.inSeconds);
22 Expect.equals(1, d.inMinutes);
23 Expect.equals(0, d.inHours);
24 Expect.equals(0, d.inDays);
25 d = const Duration(seconds: 1);
26 Expect.equals(1000, d.inMilliseconds);
27 Expect.equals(1, d.inSeconds);
28 Expect.equals(0, d.inMinutes);
29 Expect.equals(0, d.inHours);
30 Expect.equals(0, d.inDays);
31 d = new Duration(milliseconds: 1);
32 Expect.equals(1, d.inMilliseconds);
33 Expect.equals(0, d.inSeconds);
34 Expect.equals(0, d.inMinutes);
35 Expect.equals(0, d.inHours);
36 Expect.equals(0, d.inDays);
37
38 d = const Duration(seconds: 1, milliseconds: 999);
39 Expect.equals(1999, d.inMilliseconds);
40 Expect.equals(1, d.inSeconds);
41 d = new Duration(minutes: 1, seconds: 59);
42 Expect.equals(119, d.inSeconds);
43 Expect.equals(1, d.inMinutes);
44 d = const Duration(hours: 1, minutes: 59);
45 Expect.equals(119, d.inMinutes);
46 Expect.equals(1, d.inHours);
47 d = new Duration(days: 1, hours:23);
48 Expect.equals(47, d.inHours);
49 Expect.equals(1, d.inDays);
50 d = const Duration(
51 days: 0, hours: 23, minutes: 59, seconds: 59, milliseconds: 999);
52 Expect.equals(0, d.inDays);
53
54 d = new Duration(days: -1);
55 Expect.equals(-86400000, d.inMilliseconds);
56 Expect.equals(-86400, d.inSeconds);
57 Expect.equals(-1440, d.inMinutes);
58 Expect.equals(-24, d.inHours);
59 Expect.equals(-1, d.inDays);
60 d = const Duration(hours: -1);
61 Expect.equals(-3600000, d.inMilliseconds);
62 Expect.equals(-3600, d.inSeconds);
63 Expect.equals(-60, d.inMinutes);
64 Expect.equals(-1, d.inHours);
65 Expect.equals(0, d.inDays);
66 d = new Duration(minutes: -1);
67 Expect.equals(-60000, d.inMilliseconds);
68 Expect.equals(-60, d.inSeconds);
69 Expect.equals(-1, d.inMinutes);
70 Expect.equals(0, d.inHours);
71 Expect.equals(0, d.inDays);
72 d = const Duration(seconds: -1);
73 Expect.equals(-1000, d.inMilliseconds);
74 Expect.equals(-1, d.inSeconds);
75 Expect.equals(0, d.inMinutes);
76 Expect.equals(0, d.inHours);
77 Expect.equals(0, d.inDays);
78 d = new Duration(milliseconds: -1);
79 Expect.equals(-1, d.inMilliseconds);
80 Expect.equals(0, d.inSeconds);
81 Expect.equals(0, d.inMinutes);
82 Expect.equals(0, d.inHours);
83 Expect.equals(0, d.inDays);
84
85 d = const Duration(days: 1, hours: -24);
86 Expect.equals(0, d.inMilliseconds);
87 d = new Duration(hours: 1, minutes: -60);
88 Expect.equals(0, d.inMilliseconds);
89 d = const Duration(minutes: 1, seconds: -60);
90 Expect.equals(0, d.inMilliseconds);
91 d = new Duration(seconds: 1, milliseconds: -1000);
92 Expect.equals(0, d.inMilliseconds);
93
94 d = const Duration(hours: 25);
95 Expect.equals(1, d.inDays);
96 Expect.equals(25, d.inHours);
97 Expect.equals(1500, d.inMinutes);
98 Expect.equals(90000, d.inSeconds);
99 Expect.equals(90000000, d.inMilliseconds);
100 d = new Duration(minutes: 61);
101 Expect.equals(0, d.inDays);
102 Expect.equals(1, d.inHours);
103 Expect.equals(61, d.inMinutes);
104 Expect.equals(3660, d.inSeconds);
105 Expect.equals(3660000, d.inMilliseconds);
106 d = const Duration(seconds: 61);
107 Expect.equals(0, d.inDays);
108 Expect.equals(0, d.inHours);
109 Expect.equals(1, d.inMinutes);
110 Expect.equals(61, d.inSeconds);
111 Expect.equals(61000, d.inMilliseconds);
112 d = new Duration(milliseconds: 1001);
113 Expect.equals(0, d.inDays);
114 Expect.equals(0, d.inHours);
115 Expect.equals(0, d.inMinutes);
116 Expect.equals(1, d.inSeconds);
117 Expect.equals(1001, d.inMilliseconds);
118
119 var d1 = const Duration(milliseconds: 1000);
120 var d2 = const Duration(seconds: 1);
121 Expect.identical(d1, d2);
122
123 d1 = new Duration(hours: 1);
124 d2 = new Duration(hours: -1);
125 d = d1 + d2;
126 Expect.equals(0, d.inMilliseconds);
127 d = d1 - d2;
128 Expect.equals(3600000 * 2, d.inMilliseconds);
129
130 d2 = new Duration(hours: 1);
131 d = d1 + d2;
132 Expect.equals(3600000 * 2, d.inMilliseconds);
133 d = d1 - d2;
134 Expect.equals(0, d.inMilliseconds);
135
136 d = d1 * 2;
137 Expect.equals(3600000 * 2, d.inMilliseconds);
138 d = d1 * -1;
139 Expect.equals(-3600000, d.inMilliseconds);
140 d = d1 * 0;
141 Expect.equals(0, d.inMilliseconds);
142
143 d = d1 ~/ 2;
144 Expect.equals(1800000, d.inMilliseconds);
145 d = d1 ~/ 3600001;
146 Expect.equals(0, d.inMilliseconds);
147 d = d1 ~/ -3600001;
148 Expect.equals(0, d.inMilliseconds);
149 d = d1 ~/ 3599999;
150 Expect.equals(1, d.inMilliseconds);
151 d = d1 ~/ -3599999;
152 Expect.equals(-1, d.inMilliseconds);
153 d = d1 ~/ -1;
154 Expect.equals(-3600000, d.inMilliseconds);
155 d = d1 * 0;
156 Expect.equals(0, d.inMilliseconds);
157 Expect.throws(() => d1 ~/ 0,
158 (e) => e is IntegerDivisionByZeroException);
159
160 d = new Duration(milliseconds: 0);
161 Expect.isTrue(d < new Duration(milliseconds: 1));
162 Expect.isTrue(d <= new Duration(milliseconds: 1));
163 Expect.isTrue(d <= d);
164 Expect.isTrue(d > new Duration(milliseconds: -1));
165 Expect.isTrue(d >= new Duration(milliseconds: -1));
166 Expect.isTrue(d >= d);
167 }
OLDNEW
« no previous file with comments | « sdk/lib/core/duration.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698