-
Notifications
You must be signed in to change notification settings - Fork 0
/
MinesTester.java
70 lines (60 loc) · 2.08 KB
/
MinesTester.java
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
// 19472578
package mines;
import util.Tester;
public class MinesTester extends Tester {
void testMines1() {
initPublishedTest("4X4 board, mine at (0,0)");
Mines m = new Mines(4, 4, 0);
m.addMine(0, 0);
checkEqStr(m, "....\n....\n....\n....\n", "clear board");
check(!m.isDone(), "Should not win yet!");
m.open(3, 3);
checkEqStr(m, ".1 \n11 \n \n \n", "after open(3,3)");
check(m.isDone(), "Should win after open(3,3).");
}
void testMines2() {
initPublishedTest("3X2 board, mine at (2, 1)");
Mines m = new Mines(3, 2, 0);
m.addMine(2, 1);
checkEqStr(m, "..\n..\n..\n", "clear board");
check(m.open(0, 1), "open (0,1)");
checkEqStr(m, " \n11\n..\n", "after open(0,1)");
check(!m.open(2, 1), "open (2,1)");
checkEqStr(m, " \n11\n..\n", "after open(0,1), open(2,1)");
m.setShowAll(true);
}
void testMines3() {
initPublishedTest("4X4 board, mine at (1,1), (2,3), (3,3)");
Mines m = new Mines(4, 4, 0);
m.addMine(1, 1);
m.addMine(2, 3);
m.addMine(3, 3);
check(!m.isDone(), "Should not win yet!");
m.open(2, 2);
checkEqStr(m, "....\n....\n..3.\n....\n", "after open(2,2)");
m.open(3, 0);
checkEqStr(m, "....\n....\n113.\n 2.\n", "after open(2,2), open(3,0)");
m.toggleFlag(3, 3);
checkEqStr(m, "....\n....\n113.\n 2F\n", "after open(2,2), open(3,0), toggleFlag(3,3)");
m.toggleFlag(3, 3);
checkEqStr(m, "....\n....\n113.\n 2.\n", "after open(2,2), open(3,0), toggleFlag(3,3) X 2");
m.setShowAll(true);
checkEqStr(m, "111 \n1X21\n113X\n 2X\n", "after open(2,2), open(3,0), setShowAll(true)");
m.setShowAll(false);
m.open(1, 2);
checkEqStr(m, "....\n..2.\n113.\n 2.\n",
"after open(2,2), open(3,0), " + "setShowAll(true), open(1,2), setShowAll(false)");
check(!m.isDone(), "should not win yet.");
}
// ------------------------------------------------------------
public static void main(String[] args) {
new MinesTester().myMain("mines");
}
// ------------------------------------------------------------
// Here you can choose which tests to run.
public void myTests() {
testMines1();
testMines2();
testMines3();
}
}