Chromium Code Reviews| Index: tests/corelib/src/StopWatchTest.dart |
| diff --git a/tests/corelib/src/StopWatchTest.dart b/tests/corelib/src/StopWatchTest.dart |
| index 2b47cba58f0003acaa20d020cfae3f6758d8ddc2..687c46b2351ff2f4a1dcc0095ce09a6f2844c9cc 100644 |
| --- a/tests/corelib/src/StopWatchTest.dart |
| +++ b/tests/corelib/src/StopWatchTest.dart |
| @@ -4,8 +4,8 @@ |
| // Dart test program for testing stopwatch support. |
| -class StopWatchTest { |
| - static bool checkTicking(StopWatch sw) { |
| +class StopwatchTest { |
| + static bool checkTicking(Stopwatch sw) { |
| sw.start(); |
| for (int i = 0; i < 10000; i++) { |
| Math.parseInt(i.toString()); |
| @@ -16,50 +16,91 @@ class StopWatchTest { |
| return sw.elapsed() > 0; |
| } |
| - static bool checkStopping(StopWatch sw) { |
| + static bool checkStopping(Stopwatch sw) { |
| sw.stop(); |
| int v1 = sw.elapsed(); |
| Expect.isTrue(v1 > 0); // Expect a non-zero elapsed time. |
| - StopWatch sw2 = new StopWatch(); // Used for verification. |
| + Stopwatch sw2 = new Stopwatch(); // Used for verification. |
| sw2.start(); |
| - for (int i = 0; i < 10000; i++) { |
| + int sw2LastElapsed = 0; |
| + for (int i = 0; i < 100000; i++) { |
| Math.parseInt(i.toString()); |
| int v2 = sw.elapsed(); |
| if (v1 != v2) { |
| return false; |
| } |
| - v1 = v2; |
| + // If sw2 elapsed twice then sw must have advanced too if it wasn't |
| + // stopped. |
| + if (sw2LastElapsed > 0 && sw2.elapsed() > sw2LastElapsed) { |
| + break; |
| + } |
| + sw2LastElapsed = sw2.elapsed(); |
| } |
| // The test only makes sense if measureable time elapsed and elapsed time |
| - // on the stopped StopWatch did not increase. |
| + // on the stopped Stopwatch did not increase. |
| Expect.isTrue(sw2.elapsed() > 0); |
| return true; |
| } |
| static checkRestart() { |
| - StopWatch sw = new StopWatch(); |
| + Stopwatch sw = new Stopwatch(); |
| sw.start(); |
| - for (int i = 0; i < 1000; i++) { |
| + for (int i = 0; i < 100000; i++) { |
| Math.parseInt(i.toString()); |
| + if (sw.elapsed() > 0) { |
| + break; |
| + } |
| } |
| sw.stop(); |
| int initial = sw.elapsed(); |
| sw.start(); |
| - for (int i = 0; i < 10; i++) { |
| + for (int i = 0; i < 100000; i++) { |
| + Math.parseInt(i.toString()); |
| + if (sw.elapsed() > initial) break; |
|
floitsch
2011/11/11 13:57:49
In the very latest revision I have moved the break
|
| + } |
| + sw.stop(); |
| + Expect.isTrue(sw.elapsed() > initial); |
| + } |
| + |
| + static checkReset() { |
| + Stopwatch sw = new Stopwatch(); |
| + sw.start(); |
| + for (int i = 0; i < 100000; i++) { |
| Math.parseInt(i.toString()); |
| + if (sw.elapsed() > 0) { |
| + break; |
| + } |
| + } |
| + sw.stop(); |
| + sw.reset(); |
| + Expect.equals(0, sw.elapsed()); |
| + sw.start(); |
| + for (int i = 0; i < 100000; i++) { |
| + Math.parseInt(i.toString()); |
| + if (sw.elapsed() > 0) { |
| + break; |
| + } |
| + } |
| + sw.reset(); |
| + for (int i = 0; i < 100000; i++) { |
| + Math.parseInt(i.toString()); |
| + if (sw.elapsed() > 0) { |
| + break; |
| + } |
| } |
| sw.stop(); |
| - Expect.isTrue(sw.elapsed() >= initial); |
| + Expect.isTrue(sw.elapsed() > 0); |
| } |
| static testMain() { |
| - StopWatch sw = new StopWatch(); |
| + Stopwatch sw = new Stopwatch(); |
| Expect.isTrue(checkTicking(sw)); |
| Expect.isTrue(checkStopping(sw)); |
| checkRestart(); |
| + checkReset(); |
| } |
| } |
| main() { |
| - StopWatchTest.testMain(); |
| + StopwatchTest.testMain(); |
| } |