-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestAtLeastOneMoveExists.java
More file actions
176 lines (153 loc) · 4.91 KB
/
TestAtLeastOneMoveExists.java
File metadata and controls
176 lines (153 loc) · 4.91 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package game2048;
import org.junit.Test;
import static org.junit.Assert.*;
/** Tests the atLeastOneMoveExists() static method of Model.
*
* You shouldn't expect to pass these tests until you're passing all the tests
* in TestEmptySpace.
*
* @author Omar Khan
*/
public class TestAtLeastOneMoveExists {
/** The Board that we'll be testing on. */
static Board b;
@Test
/** Tests a board with some empty space.
*
* Note that this isn't a comprehensive test for empty space. For that,
* see the TestEmptySpace class. */
public void testEmptySpace() {
int[][] rawVals = new int[][] {
{0, 0, 4, 0},
{0, 0, 0, 0},
{0, 2, 0, 0},
{0, 0, 0, 0},
};
b = new Board(rawVals, 0);
assertTrue("A tilt in any direction will change the board "
+ "(there is empty space on the board)\n" + b,
Model.atLeastOneMoveExists(b));
}
@Test
/** Tests a board where a tilt in any direction would cause a change. */
public void testAnyDir() {
int[][] rawVals = new int[][] {
{2, 4, 2, 2},
{4, 2, 4, 2},
{2, 4, 2, 4},
{4, 2, 4, 2},
};
b = new Board(rawVals, 0);
assertTrue("A tilt in any direction will change the board\n"
+ b,
Model.atLeastOneMoveExists(b));
}
@Test
/** Tests a board where a tilt left or right would cause a change. */
public void testLeftOrRight() {
int[][] rawVals = new int[][] {
{2, 4, 2, 4},
{4, 8, 4, 2},
{2, 2, 2, 4},
{4, 8, 4, 2},
};
b = new Board(rawVals, 0);
assertTrue("A tilt left or right will change the board\n" + b,
Model.atLeastOneMoveExists(b));
}
@Test
/** Tests a board where a tilt up or down would cause a change. */
public void testUpOrDown() {
int[][] rawVals = new int[][] {
{2, 4, 2, 4},
{4, 8, 4, 2},
{2, 16, 4, 8},
{4, 8, 4, 2},
};
b = new Board(rawVals, 0);
assertTrue("A tilt up or down will change the board\n" + b,
Model.atLeastOneMoveExists(b));
}
@Test
/** Tests a board where some move exists (max tile is on the board).
*
* While having the max tile on the board does mean the game is over, it
* should not be handled in this method. */
public void testMoveExistsMaxPiece() {
int[][] rawVals = new int[][] {
{2, 4, 2, 4},
{4, 2, 4, 2},
{2, 2, 2, 4},
{4, 2, 4, 2048},
};
b = new Board(rawVals, 0);
assertTrue("A tilt in any direction will change the board\n"
+ b,
Model.atLeastOneMoveExists(b));
}
@Test
/** Tests a board where no move exists. */
public void testNoMoveExists1() {
int[][] rawVals = new int[][] {
{2, 4, 2, 4},
{4, 2, 4, 2},
{2, 4, 2, 4},
{4, 2, 4, 2},
};
b = new Board(rawVals, 0);
assertFalse("No move exists\n" + b,
Model.atLeastOneMoveExists(b));
}
@Test
/** Tests a board where no move exists. */
public void testNoMoveExists2() {
int[][] rawVals = new int[][] {
{2, 1024, 2, 4},
{4, 2, 4, 2},
{2, 8, 16, 4},
{512, 2, 4, 2},
};
b = new Board(rawVals, 0);
assertFalse("No move exists\n" + b,
Model.atLeastOneMoveExists(b));
}
@Test
/** Tests a board where no move exists. */
public void testNoMoveExists3() {
int[][] rawVals = new int[][] {
{8, 4, 2, 32},
{32, 2, 4, 2},
{2, 8, 2, 4},
{4, 64, 4, 64},
};
b = new Board(rawVals, 0);
assertFalse("No move exists\n" + b,
Model.atLeastOneMoveExists(b));
}
@Test
/** Tests a board where no move exists. */
public void testNoMoveExists4() {
int[][] rawVals = new int[][] {
{2, 4, 2, 32},
{32, 2, 4, 2},
{2, 128, 2, 4},
{4, 2, 4, 2},
};
b = new Board(rawVals, 0);
assertFalse("No move exists\n" + b,
Model.atLeastOneMoveExists(b));
}
@Test
/** Tests a board where no move exists. */
public void testNoMoveExists5() {
int[][] rawVals = new int[][] {
{8, 16, 2, 32},
{32, 2, 64, 2},
{2, 256, 128, 256},
{1024, 8, 4, 2},
};
b = new Board(rawVals, 0);
assertFalse("No move exists\n" + b,
Model.atLeastOneMoveExists(b));
}
}