-
Notifications
You must be signed in to change notification settings - Fork 11
/
board_test.cc
97 lines (83 loc) · 1.76 KB
/
board_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <assert.h>
#include "board.h"
void TestMoves() {
int layout[N][N] = {
{ 0, 0, 0, 1 },
{ 0, 2, 0, 2 },
{ 2, 2, 2, 2 },
{ 3, 1, 1, 1 },
};
int moved_left[N][N] = {
{ 1, 0, 0, 0 },
{ 3, 0, 0, 0 },
{ 3, 3, 0, 0 },
{ 3, 2, 1, 0 },
};
int moved_right[N][N] = {
{ 0, 0, 0, 1 },
{ 0, 0, 0, 3 },
{ 0, 0, 3, 3 },
{ 0, 3, 1, 2 },
};
int moved_up[N][N] = {
{ 2, 3, 2, 1 },
{ 3, 1, 1, 3 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 0 },
};
int moved_down[N][N] = {
{ 0, 0, 0, 0 },
{ 0, 0, 0, 1 },
{ 2, 3, 2, 3 },
{ 3, 1, 1, 1 },
};
Board left(layout);
assert(left.MoveLeft());
assert(left == Board(moved_left));
Board right(layout);
assert(right.MoveRight());
assert(right == Board(moved_right));
Board up(layout);
assert(up.MoveUp());
assert(up == Board(moved_up));
Board down(layout);
assert(down.MoveDown());
assert(down == Board(moved_down));
int layout2[N][N] = {
{ 0, 0, 0, 1 },
{ 0, 0, 3, 2 },
{ 2, 3, 4, 5 },
{ 3, 4, 5, 6 },
};
Board down2(layout2);
assert(!down2.MoveDown());
assert(down2 == Board(layout2));
Board right2(layout2);
assert(!right2.MoveRight());
assert(right2 == Board(layout2));
Board up2(layout2);
assert(up2.MoveUp());
Board left2(layout2);
assert(left2.MoveLeft());
int layout3[N][N] = {
{ 3, 4, 5, 6 },
{ 2, 3, 4, 5 },
{ 1, 2, 0, 0 },
{ 3, 0, 0, 0 },
};
Board up3(layout3);
assert(!up3.MoveUp());
assert(up3 == Board(layout3));
Board left3(layout3);
assert(!left3.MoveLeft());
assert(left3 == Board(layout3));
Board right3(layout3);
assert(right3.MoveRight());
Board down3(layout3);
assert(down3.MoveDown());
}
int main() {
Board::BuildMoveMap();
TestMoves();
return 0;
}