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

Side by Side Diff: packages/quiver/test/time/clock_test.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers 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
1 // Copyright 2013 Google Inc. All Rights Reserved. 1 // Copyright 2013 Google Inc. All Rights Reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the 'License'); 3 // Licensed under the Apache License, Version 2.0 (the 'License');
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an 'AS IS' BASIS, 10 // distributed under the License is distributed on an 'AS IS' BASIS,
(...skipping 25 matching lines...) Expand all
36 }); 36 });
37 37
38 // This test may be flaky on certain systems. I ran it over 10 million 38 // This test may be flaky on certain systems. I ran it over 10 million
39 // cycles on my machine without any failures, but that's no guarantee. 39 // cycles on my machine without any failures, but that's no guarantee.
40 test('should be close enough to system clock', () { 40 test('should be close enough to system clock', () {
41 // At 10ms the test doesn't seem to be flaky. 41 // At 10ms the test doesn't seem to be flaky.
42 var epsilon = 10; 42 var epsilon = 10;
43 expect( 43 expect(
44 new DateTime.now().difference(new Clock().now()).inMilliseconds.abs(), 44 new DateTime.now().difference(new Clock().now()).inMilliseconds.abs(),
45 lessThan(epsilon)); 45 lessThan(epsilon));
46 expect(new DateTime.now().difference(const Clock().now()).inMilliseconds 46 expect(
47 .abs(), lessThan(epsilon)); 47 new DateTime.now()
48 .difference(const Clock().now())
49 .inMilliseconds
50 .abs(),
51 lessThan(epsilon));
48 }); 52 });
49 53
50 test('should return time provided by custom TimeFunction', () { 54 test('should return time provided by custom TimeFunction', () {
51 var time = new DateTime(2013); 55 var time = new DateTime(2013);
52 var fixedClock = new Clock(() => time); 56 var fixedClock = new Clock(() => time);
53 expect(fixedClock.now(), new DateTime(2013)); 57 expect(fixedClock.now(), new DateTime(2013));
54 58
55 time = new DateTime(2014); 59 time = new DateTime(2014);
56 expect(fixedClock.now(), new DateTime(2014)); 60 expect(fixedClock.now(), new DateTime(2014));
57 }); 61 });
58 62
59 test('should return fixed time', () { 63 test('should return fixed time', () {
60 expect(new Clock.fixed(new DateTime(2013)).now(), new DateTime(2013)); 64 expect(new Clock.fixed(new DateTime(2013)).now(), new DateTime(2013));
61 }); 65 });
62 66
63 test('should return time Duration ago', () { 67 test('should return time Duration ago', () {
64 expect(subject.agoBy(new Duration(days: 366)), new DateTime(2012)); 68 expect(subject.agoBy(const Duration(days: 366)), new DateTime(2012));
65 }); 69 });
66 70
67 test('should return time Duration from now', () { 71 test('should return time Duration from now', () {
68 expect(subject.fromNowBy(new Duration(days: 365)), new DateTime(2014)); 72 expect(subject.fromNowBy(const Duration(days: 365)), new DateTime(2014));
69 }); 73 });
70 74
71 test('should return time parts ago', () { 75 test('should return time parts ago', () {
72 expect(subject.ago( 76 expect(
73 days: 1, 77 subject.ago(
74 hours: 1, 78 days: 1,
75 minutes: 1, 79 hours: 1,
76 seconds: 1, 80 minutes: 1,
77 milliseconds: 1, 81 seconds: 1,
78 microseconds: 1000), new DateTime(2012, 12, 30, 22, 58, 58, 998)); 82 milliseconds: 1,
83 microseconds: 1000),
84 new DateTime(2012, 12, 30, 22, 58, 58, 998));
79 }); 85 });
80 86
81 test('should return time parts from now', () { 87 test('should return time parts from now', () {
82 expect(subject.fromNow( 88 expect(
83 days: 1, 89 subject.fromNow(
84 hours: 1, 90 days: 1,
85 minutes: 1, 91 hours: 1,
86 seconds: 1, 92 minutes: 1,
87 milliseconds: 1, 93 seconds: 1,
88 microseconds: 1000), new DateTime(2013, 1, 2, 1, 1, 1, 2)); 94 milliseconds: 1,
95 microseconds: 1000),
96 new DateTime(2013, 1, 2, 1, 1, 1, 2));
89 }); 97 });
90 98
91 test('should return time micros ago', () { 99 test('should return time micros ago', () {
92 expect( 100 expect(
93 subject.microsAgo(1000), new DateTime(2012, 12, 31, 23, 59, 59, 999)); 101 subject.microsAgo(1000), new DateTime(2012, 12, 31, 23, 59, 59, 999));
94 }); 102 });
95 103
96 test('should return time micros from now', () { 104 test('should return time micros from now', () {
97 expect(subject.microsFromNow(1000), new DateTime(2013, 1, 1, 0, 0, 0, 1)); 105 expect(subject.microsFromNow(1000), new DateTime(2013, 1, 1, 0, 0, 0, 1));
98 }); 106 });
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 expectDate(subject.yearsFromNow(2), 2015, 1, 1); 218 expectDate(subject.yearsFromNow(2), 2015, 1, 1);
211 expectDate(subject.yearsFromNow(3), 2016, 1, 1); 219 expectDate(subject.yearsFromNow(3), 2016, 1, 1);
212 expectDate(subject.yearsFromNow(4), 2017, 1, 1); 220 expectDate(subject.yearsFromNow(4), 2017, 1, 1);
213 expectDate(subject.yearsFromNow(5), 2018, 1, 1); 221 expectDate(subject.yearsFromNow(5), 2018, 1, 1);
214 expectDate(subject.yearsFromNow(6), 2019, 1, 1); 222 expectDate(subject.yearsFromNow(6), 2019, 1, 1);
215 expectDate(subject.yearsFromNow(30), 2043, 1, 1); 223 expectDate(subject.yearsFromNow(30), 2043, 1, 1);
216 expectDate(subject.yearsFromNow(1000), 3013, 1, 1); 224 expectDate(subject.yearsFromNow(1000), 3013, 1, 1);
217 }); 225 });
218 }); 226 });
219 } 227 }
OLDNEW
« no previous file with comments | « packages/quiver/test/testing/equality/equality_test.dart ('k') | packages/quiver/tool/travis.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698