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

Unified Diff: test/codegen/corelib/stopwatch_test.dart

Issue 1945153002: Add corelib tests (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: error_test and range_error_test now pass Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/codegen/corelib/stopwatch2_test.dart ('k') | test/codegen/corelib/string_base_vm_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/codegen/corelib/stopwatch_test.dart
diff --git a/test/codegen/corelib/stopwatch_test.dart b/test/codegen/corelib/stopwatch_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..28ec48b10ca77d6d937bd51ed1ba3826c164c3e1
--- /dev/null
+++ b/test/codegen/corelib/stopwatch_test.dart
@@ -0,0 +1,127 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Dart test program for testing stopwatch support.
+
+library stopwatch_test;
+import "package:expect/expect.dart";
+
+class StopwatchTest {
+ static bool checkTicking(Stopwatch sw) {
+ Expect.isFalse(sw.isRunning);
+ sw.start();
+ Expect.isTrue(sw.isRunning);
+ for (int i = 0; i < 1000000; i++) {
+ int.parse(i.toString());
+ if (sw.elapsedTicks > 0) {
+ break;
+ }
+ }
+ return sw.elapsedTicks > 0;
+ }
+
+ static bool checkStopping(Stopwatch sw) {
+ sw.stop();
+ Expect.isFalse(sw.isRunning);
+ int v1 = sw.elapsedTicks;
+ Expect.isTrue(v1 > 0); // Expect a non-zero elapsed time.
+ Stopwatch sw2 = new Stopwatch(); // Used for verification.
+ sw2.start();
+ Expect.isTrue(sw2.isRunning);
+ int sw2LastElapsed = 0;
+ for (int i = 0; i < 100000; i++) {
+ int.parse(i.toString());
+ int v2 = sw.elapsedTicks;
+ if (v1 != v2) {
+ return false;
+ }
+ // If sw2 elapsed twice then sw must have advanced too if it wasn't
+ // stopped.
+ if (sw2LastElapsed > 0 && sw2.elapsedTicks > sw2LastElapsed) {
+ break;
+ }
+ sw2LastElapsed = sw2.elapsedTicks;
+ }
+ // The test only makes sense if measureable time elapsed and elapsed time
+ // on the stopped Stopwatch did not increase.
+ Expect.isTrue(sw2.elapsedTicks > 0);
+ return true;
+ }
+
+ static checkRestart() {
+ Stopwatch sw = new Stopwatch();
+ Expect.isFalse(sw.isRunning);
+ sw.start();
+ Expect.isTrue(sw.isRunning);
+ for (int i = 0; i < 100000; i++) {
+ int.parse(i.toString());
+ if (sw.elapsedTicks > 0) {
+ break;
+ }
+ }
+ sw.stop();
+ Expect.isFalse(sw.isRunning);
+ int initial = sw.elapsedTicks;
+ sw.start();
+ Expect.isTrue(sw.isRunning);
+ for (int i = 0; i < 100000; i++) {
+ int.parse(i.toString());
+ if (sw.elapsedTicks > initial) {
+ break;
+ }
+ }
+ sw.stop();
+ Expect.isFalse(sw.isRunning);
+ Expect.isTrue(sw.elapsedTicks > initial);
+ }
+
+ static checkReset() {
+ Stopwatch sw = new Stopwatch();
+ Expect.isFalse(sw.isRunning);
+ sw.start();
+ Expect.isTrue(sw.isRunning);
+ for (int i = 0; i < 100000; i++) {
+ int.parse(i.toString());
+ if (sw.elapsedTicks > 0) {
+ break;
+ }
+ }
+ sw.stop();
+ Expect.isFalse(sw.isRunning);
+ sw.reset();
+ Expect.isFalse(sw.isRunning);
+ Expect.equals(0, sw.elapsedTicks);
+ sw.start();
+ Expect.isTrue(sw.isRunning);
+ for (int i = 0; i < 100000; i++) {
+ int.parse(i.toString());
+ if (sw.elapsedTicks > 0) {
+ break;
+ }
+ }
+ sw.reset();
+ Expect.isTrue(sw.isRunning);
+ for (int i = 0; i < 100000; i++) {
+ int.parse(i.toString());
+ if (sw.elapsedTicks > 0) {
+ break;
+ }
+ }
+ sw.stop();
+ Expect.isFalse(sw.isRunning);
+ Expect.isTrue(sw.elapsedTicks > 0);
+ }
+
+ static testMain() {
+ Stopwatch sw = new Stopwatch();
+ Expect.isTrue(checkTicking(sw));
+ Expect.isTrue(checkStopping(sw));
+ checkRestart();
+ checkReset();
+ }
+}
+
+main() {
+ StopwatchTest.testMain();
+}
« no previous file with comments | « test/codegen/corelib/stopwatch2_test.dart ('k') | test/codegen/corelib/string_base_vm_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698