| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, 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 // Dart test program for testing stopwatch support. | |
| 6 | |
| 7 class StopWatchTest { | |
| 8 static bool checkTicking(StopWatch sw) { | |
| 9 sw.start(); | |
| 10 for (int i = 0; i < 10000; i++) { | |
| 11 Math.parseInt(i.toString()); | |
| 12 if (sw.elapsed() > 0) { | |
| 13 break; | |
| 14 } | |
| 15 } | |
| 16 return sw.elapsed() > 0; | |
| 17 } | |
| 18 | |
| 19 static bool checkStopping(StopWatch sw) { | |
| 20 sw.stop(); | |
| 21 int v1 = sw.elapsed(); | |
| 22 Expect.isTrue(v1 > 0); // Expect a non-zero elapsed time. | |
| 23 StopWatch sw2 = new StopWatch(); // Used for verification. | |
| 24 sw2.start(); | |
| 25 for (int i = 0; i < 10000; i++) { | |
| 26 Math.parseInt(i.toString()); | |
| 27 int v2 = sw.elapsed(); | |
| 28 if (v1 != v2) { | |
| 29 return false; | |
| 30 } | |
| 31 v1 = v2; | |
| 32 } | |
| 33 // The test only makes sense if measureable time elapsed and elapsed time | |
| 34 // on the stopped StopWatch did not increase. | |
| 35 Expect.isTrue(sw2.elapsed() > 0); | |
| 36 return true; | |
| 37 } | |
| 38 | |
| 39 static checkRestart() { | |
| 40 StopWatch sw = new StopWatch(); | |
| 41 sw.start(); | |
| 42 for (int i = 0; i < 1000; i++) { | |
| 43 Math.parseInt(i.toString()); | |
| 44 } | |
| 45 sw.stop(); | |
| 46 int initial = sw.elapsed(); | |
| 47 sw.start(); | |
| 48 for (int i = 0; i < 10; i++) { | |
| 49 Math.parseInt(i.toString()); | |
| 50 } | |
| 51 sw.stop(); | |
| 52 Expect.isTrue(sw.elapsed() >= initial); | |
| 53 } | |
| 54 | |
| 55 static testMain() { | |
| 56 StopWatch sw = new StopWatch(); | |
| 57 Expect.isTrue(checkTicking(sw)); | |
| 58 Expect.isTrue(checkStopping(sw)); | |
| 59 checkRestart(); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 main() { | |
| 64 StopWatchTest.testMain(); | |
| 65 } | |
| OLD | NEW |