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

Side by Side Diff: tests/corelib/src/StopWatchTest.dart

Issue 8537011: Rename StopWatch to Stopwatch. Add new Stopwatch.start() and Stopwatch.reset(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « tests/co19/co19-runtime.status ('k') | tests/corelib/src/StopwatchTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « tests/co19/co19-runtime.status ('k') | tests/corelib/src/StopwatchTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698