| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, 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 library pop_pop_win.field_test; | |
| 5 | |
| 6 import 'package:pop_pop_win/src/game.dart'; | |
| 7 import 'package:unittest/unittest.dart'; | |
| 8 | |
| 9 import 'test_util.dart'; | |
| 10 | |
| 11 void main() { | |
| 12 test('defaults', _testDefaults); | |
| 13 test('bombCount', _testBombCount); | |
| 14 test('fromSquares', _testFromSquares); | |
| 15 test('adjacent', _testAdjacent); | |
| 16 } | |
| 17 | |
| 18 void _testDefaults() { | |
| 19 var f = new Field(); | |
| 20 | |
| 21 expect(f.bombCount, equals(40)); | |
| 22 expect(f.height, equals(16)); | |
| 23 expect(f.width, equals(16)); | |
| 24 } | |
| 25 | |
| 26 void _testBombCount() { | |
| 27 var f = new Field(); | |
| 28 | |
| 29 int bombCount = 0; | |
| 30 for (int x = 0; x < 16; x++) { | |
| 31 for (int y = 0; y < 16; y++) { | |
| 32 if (f.get(x, y)) { | |
| 33 bombCount++; | |
| 34 } | |
| 35 } | |
| 36 } | |
| 37 expect(bombCount, equals(f.bombCount)); | |
| 38 } | |
| 39 | |
| 40 void _testFromSquares() { | |
| 41 var f = new Field.fromSquares(2, 2, [true, true, true, false]); | |
| 42 expect(f.height, equals(2)); | |
| 43 expect(f.width, equals(2)); | |
| 44 expect(f.bombCount, equals(3)); | |
| 45 } | |
| 46 | |
| 47 void _testAdjacent() { | |
| 48 var f = getSampleField(); | |
| 49 | |
| 50 expect(f.bombCount, equals(13)); | |
| 51 | |
| 52 for (int x = 0; x < f.width; x++) { | |
| 53 for (int y = 0; y < f.height; y++) { | |
| 54 var i = x + y * f.width; | |
| 55 var adj = f.getAdjacentCount(x, y); | |
| 56 expect(adj, equals(SAMPLE_FIELD[i])); | |
| 57 } | |
| 58 } | |
| 59 } | |
| OLD | NEW |