| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 main() { | 7 main() { |
| 8 Duration d; | 8 Duration d; |
| 9 d = new Duration(days: 1); | 9 d = new Duration(days: 1); |
| 10 Expect.equals(86400000000, d.inMicroseconds); | 10 Expect.equals(86400000000, d.inMicroseconds); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 Expect.equals(1, d.inMilliseconds); | 54 Expect.equals(1, d.inMilliseconds); |
| 55 d = const Duration(seconds: 1, milliseconds: 999); | 55 d = const Duration(seconds: 1, milliseconds: 999); |
| 56 Expect.equals(1999, d.inMilliseconds); | 56 Expect.equals(1999, d.inMilliseconds); |
| 57 Expect.equals(1, d.inSeconds); | 57 Expect.equals(1, d.inSeconds); |
| 58 d = new Duration(minutes: 1, seconds: 59); | 58 d = new Duration(minutes: 1, seconds: 59); |
| 59 Expect.equals(119, d.inSeconds); | 59 Expect.equals(119, d.inSeconds); |
| 60 Expect.equals(1, d.inMinutes); | 60 Expect.equals(1, d.inMinutes); |
| 61 d = const Duration(hours: 1, minutes: 59); | 61 d = const Duration(hours: 1, minutes: 59); |
| 62 Expect.equals(119, d.inMinutes); | 62 Expect.equals(119, d.inMinutes); |
| 63 Expect.equals(1, d.inHours); | 63 Expect.equals(1, d.inHours); |
| 64 d = new Duration(days: 1, hours:23); | 64 d = new Duration(days: 1, hours: 23); |
| 65 Expect.equals(47, d.inHours); | 65 Expect.equals(47, d.inHours); |
| 66 Expect.equals(1, d.inDays); | 66 Expect.equals(1, d.inDays); |
| 67 d = const Duration( | 67 d = const Duration( |
| 68 days: 0, hours: 23, minutes: 59, seconds: 59, milliseconds: 999, | 68 days: 0, |
| 69 hours: 23, |
| 70 minutes: 59, |
| 71 seconds: 59, |
| 72 milliseconds: 999, |
| 69 microseconds: 999); | 73 microseconds: 999); |
| 70 Expect.equals(0, d.inDays); | 74 Expect.equals(0, d.inDays); |
| 71 | 75 |
| 72 d = new Duration(days: -1); | 76 d = new Duration(days: -1); |
| 73 Expect.equals(-86400000000, d.inMicroseconds); | 77 Expect.equals(-86400000000, d.inMicroseconds); |
| 74 Expect.equals(-86400000, d.inMilliseconds); | 78 Expect.equals(-86400000, d.inMilliseconds); |
| 75 Expect.equals(-86400, d.inSeconds); | 79 Expect.equals(-86400, d.inSeconds); |
| 76 Expect.equals(-1440, d.inMinutes); | 80 Expect.equals(-1440, d.inMinutes); |
| 77 Expect.equals(-24, d.inHours); | 81 Expect.equals(-24, d.inHours); |
| 78 Expect.equals(-1, d.inDays); | 82 Expect.equals(-1, d.inDays); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 d = d1 ~/ -3600000001; | 198 d = d1 ~/ -3600000001; |
| 195 Expect.equals(0, d.inMicroseconds); | 199 Expect.equals(0, d.inMicroseconds); |
| 196 d = d1 ~/ 3599999999; | 200 d = d1 ~/ 3599999999; |
| 197 Expect.equals(1, d.inMicroseconds); | 201 Expect.equals(1, d.inMicroseconds); |
| 198 d = d1 ~/ -3599999999; | 202 d = d1 ~/ -3599999999; |
| 199 Expect.equals(-1, d.inMicroseconds); | 203 Expect.equals(-1, d.inMicroseconds); |
| 200 d = d1 ~/ -1; | 204 d = d1 ~/ -1; |
| 201 Expect.equals(-3600000000, d.inMicroseconds); | 205 Expect.equals(-3600000000, d.inMicroseconds); |
| 202 d = d1 * 0; | 206 d = d1 * 0; |
| 203 Expect.equals(0, d.inMicroseconds); | 207 Expect.equals(0, d.inMicroseconds); |
| 204 Expect.throws(() => d1 ~/ 0, | 208 Expect.throws(() => d1 ~/ 0, (e) => e is IntegerDivisionByZeroException); |
| 205 (e) => e is IntegerDivisionByZeroException); | |
| 206 | 209 |
| 207 d = new Duration(microseconds: 0); | 210 d = new Duration(microseconds: 0); |
| 208 Expect.isTrue(d < new Duration(microseconds: 1)); | 211 Expect.isTrue(d < new Duration(microseconds: 1)); |
| 209 Expect.isTrue(d <= new Duration(microseconds: 1)); | 212 Expect.isTrue(d <= new Duration(microseconds: 1)); |
| 210 Expect.isTrue(d <= d); | 213 Expect.isTrue(d <= d); |
| 211 Expect.isTrue(d > new Duration(microseconds: -1)); | 214 Expect.isTrue(d > new Duration(microseconds: -1)); |
| 212 Expect.isTrue(d >= new Duration(microseconds: -1)); | 215 Expect.isTrue(d >= new Duration(microseconds: -1)); |
| 213 Expect.isTrue(d >= d); | 216 Expect.isTrue(d >= d); |
| 214 | 217 |
| 215 d = const Duration(days: 1, hours: 3, minutes: 17, seconds: 42, | 218 d = const Duration( |
| 216 milliseconds: 823, microseconds: 127); | 219 days: 1, |
| 220 hours: 3, |
| 221 minutes: 17, |
| 222 seconds: 42, |
| 223 milliseconds: 823, |
| 224 microseconds: 127); |
| 217 Expect.equals("27:17:42.823127", d.toString()); | 225 Expect.equals("27:17:42.823127", d.toString()); |
| 218 | 226 |
| 219 d = const Duration(hours: 1999, minutes: 17, seconds: 42); | 227 d = const Duration(hours: 1999, minutes: 17, seconds: 42); |
| 220 Expect.equals("1999:17:42.000000", d.toString()); | 228 Expect.equals("1999:17:42.000000", d.toString()); |
| 221 | 229 |
| 222 d = const Duration(days: -1, hours: -3, minutes: -17, seconds: -42, | 230 d = const Duration( |
| 223 milliseconds: -823, microseconds: -127); | 231 days: -1, |
| 232 hours: -3, |
| 233 minutes: -17, |
| 234 seconds: -42, |
| 235 milliseconds: -823, |
| 236 microseconds: -127); |
| 224 Expect.equals("-27:17:42.823127", d.toString()); | 237 Expect.equals("-27:17:42.823127", d.toString()); |
| 225 | 238 |
| 226 d = const Duration(hours: -1999, minutes: -17, seconds: -42); | 239 d = const Duration(hours: -1999, minutes: -17, seconds: -42); |
| 227 Expect.equals("-1999:17:42.000000", d.toString()); | 240 Expect.equals("-1999:17:42.000000", d.toString()); |
| 228 | 241 |
| 229 // Edge conditions for toString of microseconds. | 242 // Edge conditions for toString of microseconds. |
| 230 // Regression test for http://dartbug.com/15678 | 243 // Regression test for http://dartbug.com/15678 |
| 231 | 244 |
| 232 d = const Duration(microseconds: 1); | 245 d = const Duration(microseconds: 1); |
| 233 Expect.equals("0:00:00.000001", d.toString()); | 246 Expect.equals("0:00:00.000001", d.toString()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 d1 = const Duration(hours: 1); | 284 d1 = const Duration(hours: 1); |
| 272 d2 = const Duration(hours: -1); | 285 d2 = const Duration(hours: -1); |
| 273 Expect.isFalse(d1.isNegative); | 286 Expect.isFalse(d1.isNegative); |
| 274 Expect.isTrue(d2.isNegative); | 287 Expect.isTrue(d2.isNegative); |
| 275 Expect.equals(d1, d1.abs()); | 288 Expect.equals(d1, d1.abs()); |
| 276 Expect.equals(d1, d2.abs()); | 289 Expect.equals(d1, d2.abs()); |
| 277 | 290 |
| 278 Expect.equals(d2, -d1); | 291 Expect.equals(d2, -d1); |
| 279 Expect.equals(d1, -d2); | 292 Expect.equals(d1, -d2); |
| 280 } | 293 } |
| OLD | NEW |