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

Side by Side Diff: samples/third_party/pop-pop-win/test/ppw/test_field.dart

Issue 200723008: samples/poppopwin: upgrade to first-class sample (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fixed pkgbuild.status for rename Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 part of ppw_test;
2
3 class TestField {
4 // This grid
5 // XXXXX2
6 // X7X8X3
7 // X5XXX2
8 // X32321
9 // 110000
10
11 static const sample = const
12 [null, null, null, null, null, 2,
13 null, 7, null, 8, null, 3,
14 null, 5, null, null, null, 2,
15 null, 3, 2, 3, 2, 1,
16 1, 1, 0, 0, 0, 0];
17
18
19 static Field getSampleField() {
20 final bools = new List<bool>.from(sample.map((x) => x == null));
21
22 return new Field.fromSquares(6, 5, bools);
23 }
24
25 static void run() {
26 group('Field', () {
27 test('defaults', _testDefaults);
28 test('bombCount', _testBombCount);
29 test('fromSquares', _testFromSquares);
30 test('adjacent', _testAdjacent);
31 });
32 }
33
34 static void _testDefaults() {
35 final f = new Field();
36
37 expect(f.bombCount, equals(40));
38 expect(f.height, equals(16));
39 expect(f.width, equals(16));
40 }
41
42 static void _testBombCount() {
43 final f = new Field();
44
45 int bombCount = 0;
46 for(int x = 0; x < 16; x++) {
47 for(int y = 0; y < 16; y++) {
48 if(f.get(x, y)) {
49 bombCount++;
50 }
51 }
52 }
53 expect(bombCount, equals(f.bombCount));
54 }
55
56 static void _testFromSquares() {
57 final f = new Field.fromSquares(2, 2, [true, true, true, false]);
58 expect(f.height, equals(2));
59 expect(f.width, equals(2));
60 expect(f.bombCount, equals(3));
61 }
62
63 static void _testAdjacent() {
64 final f = getSampleField();
65
66 expect(f.bombCount, equals(13));
67
68 for(int x = 0; x < f.width; x++) {
69 for(int y = 0; y < f.height; y++) {
70 final i = x + y * f.width;
71 final adj = f.getAdjacentCount(x, y);
72 expect(adj, equals(sample[i]));
73 }
74 }
75 }
76 }
OLDNEW
« no previous file with comments | « samples/third_party/pop-pop-win/test/ppw/_ppw_runner.dart ('k') | samples/third_party/pop-pop-win/test/ppw/test_game.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698