| OLD | NEW |
| 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, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 part of quiver.testing.time; | 15 part of quiver.testing.time; |
| 16 | 16 |
| 17 /** | 17 /// Returns the current test time in microseconds. |
| 18 * Returns the current test time in microseconds. | |
| 19 */ | |
| 20 typedef int Now(); | 18 typedef int Now(); |
| 21 | 19 |
| 22 /** | 20 /// A [Stopwatch] implementation that gets the current time in microseconds |
| 23 * A [Stopwatch] implementation that gets the current time in microseconds | 21 /// via a user-supplied function. |
| 24 * via a user-supplied function. | |
| 25 */ | |
| 26 class FakeStopwatch implements Stopwatch { | 22 class FakeStopwatch implements Stopwatch { |
| 27 Now _now; | 23 Now _now; |
| 28 int frequency; | 24 int frequency; |
| 29 int _start; | 25 int _start; |
| 30 int _stop; | 26 int _stop; |
| 31 | 27 |
| 32 FakeStopwatch(int now(), int this.frequency) | 28 FakeStopwatch(int now(), int this.frequency) |
| 33 : _now = now, | 29 : _now = now, |
| 34 _start = null, | 30 _start = null, |
| 35 _stop = null; | 31 _stop = null; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 65 } | 61 } |
| 66 | 62 |
| 67 Duration get elapsed => new Duration(microseconds: elapsedMicroseconds); | 63 Duration get elapsed => new Duration(microseconds: elapsedMicroseconds); |
| 68 | 64 |
| 69 int get elapsedMicroseconds => (elapsedTicks * 1000000) ~/ frequency; | 65 int get elapsedMicroseconds => (elapsedTicks * 1000000) ~/ frequency; |
| 70 | 66 |
| 71 int get elapsedMilliseconds => (elapsedTicks * 1000) ~/ frequency; | 67 int get elapsedMilliseconds => (elapsedTicks * 1000) ~/ frequency; |
| 72 | 68 |
| 73 bool get isRunning => _start != null && _stop == null; | 69 bool get isRunning => _start != null && _stop == null; |
| 74 } | 70 } |
| OLD | NEW |