OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, 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 #library('game_of_life_tests'); |
| 6 |
| 7 #import('dart:html'); |
| 8 #import('package:unittest/unittest.dart'); |
| 9 #import('package:unittest/html_config.dart'); |
| 10 #import('../components/components.dart'); |
| 11 |
| 12 main() { |
| 13 useHtmlConfiguration(); |
| 14 test('Correct propogation of a glider', () { |
| 15 gameOfLifeComponentsSetup(); |
| 16 var game = new GameOfLife(); |
| 17 game.stepTime = 0; |
| 18 |
| 19 // make a glider |
| 20 gliderPattern(game, (i, j) => game.setAliveness(i, j, true), 0, 0); |
| 21 |
| 22 // We use 12 because it's a multiple of the period of a glider. |
| 23 for(int i = 0; i < 12; i++) { |
| 24 game.step(); |
| 25 } |
| 26 |
| 27 // gliders move at c/4 |
| 28 gliderPattern(game, (i, j) => expect(game.isAlive(i, j)), 3, 3); |
| 29 |
| 30 }); |
| 31 } |
| 32 |
| 33 /** |
| 34 * Takes a [game], x and y offsets [x] and [y], and a function [f] of two |
| 35 * integer inputs and calls [f] on all the squares of a glider pattern with |
| 36 * upper left corner at ([x], [y]). Does not validate [x], [y] -- behavior on |
| 37 * invalid [x] and [y] is undefined. |
| 38 */ |
| 39 void gliderPattern(GameOfLife game, Function f, int x, int y) { |
| 40 f(x, y); |
| 41 f(x + 1, y + 1); |
| 42 f(x + 2, y); |
| 43 f(x + 1, y + 2); |
| 44 f(x + 2, y + 1); |
| 45 } |
| 46 |
| 47 void _componentsSetup() { |
| 48 initializeComponents((String name) => CTOR_MAP[name], true); |
| 49 } |
OLD | NEW |