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

Unified Diff: dart/samples/webcomponents/game_of_life/test/game_of_life_test.dart

Issue 10918082: adding game_of_life sample (Closed) Base URL: git@github.com:samhopkins/bleeding_edge.git@master
Patch Set: addressing sigmund's remarks Created 8 years, 3 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
Index: dart/samples/webcomponents/game_of_life/test/game_of_life_test.dart
diff --git a/dart/samples/webcomponents/game_of_life/test/game_of_life_test.dart b/dart/samples/webcomponents/game_of_life/test/game_of_life_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..35016cdc7de8163af2bfeb97986769f7ffef6f21
--- /dev/null
+++ b/dart/samples/webcomponents/game_of_life/test/game_of_life_test.dart
@@ -0,0 +1,49 @@
+// 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.
+
+#library('game_of_life_tests');
+
+#import('dart:html');
+#import('package:unittest/unittest.dart');
+#import('package:unittest/html_config.dart');
+#import('../components/components.dart');
+
+main() {
+ useHtmlConfiguration();
+ test('Correct propogation of a glider', () {
+ gameOfLifeComponentsSetup();
+ var game = new GameOfLife();
+ game.stepTime = 0;
+
+ // make a glider
+ gliderPattern(game, (i, j) => game.setAliveness(i, j, true), 0, 0);
+
+ // We use 12 because it's a multiple of the period of a glider.
+ for(int i = 0; i < 12; i++) {
+ game.step();
+ }
+
+ // gliders move at c/4
+ gliderPattern(game, (i, j) => expect(game.isAlive(i, j)), 3, 3);
+
+ });
+}
+
+/**
+ * Takes a [game], x and y offsets [x] and [y], and a function [f] of two
+ * integer inputs and calls [f] on all the squares of a glider pattern with
+ * upper left corner at ([x], [y]). Does not validate [x], [y] -- behavior on
+ * invalid [x] and [y] is undefined.
+ */
+void gliderPattern(GameOfLife game, Function f, int x, int y) {
+ f(x, y);
+ f(x + 1, y + 1);
+ f(x + 2, y);
+ f(x + 1, y + 2);
+ f(x + 2, y + 1);
+}
+
+void _componentsSetup() {
+ initializeComponents((String name) => CTOR_MAP[name], true);
+}
« no previous file with comments | « dart/samples/webcomponents/game_of_life/styles.css ('k') | dart/samples/webcomponents/game_of_life/test/test_page.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698