-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardTest.java
More file actions
71 lines (59 loc) · 2.24 KB
/
Copy pathBoardTest.java
File metadata and controls
71 lines (59 loc) · 2.24 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
package amazons;
import org.junit.Test;
import ucb.junit.textui;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/** The suite of all JUnit tests for the amazons package.
* @author
*/
public class BoardTest {
/**
* Run the JUnit tests in this package. Add xxxTest.class entries to
* the arguments of runClasses to run other JUnit tests.
*/
public static void main(String[] ignored) {
textui.runClasses(UnitTest.class);
}
/**
* Tests basic correctness of put and get on the initialized board.
*/
@Test
public void testToString() {
Board b = new Board();
assertEquals(INIT_BOARD_STATE, b.toString());
assertFalse(b.isLegal(Square.sq(1, 0)));
assertTrue(b.isLegal(Square.sq(3, 0)));
assertFalse(b.isLegal(Square.sq(3, 0), Square.sq(7, 0)));
assertTrue(b.isLegal(Square.sq(3, 0), Square.sq(4, 0)));
assertTrue(b.isLegal(Square.sq(3, 0), Square.sq(7, 4)));
assertTrue(b.isLegal(Square.sq(3, 0)));
assertFalse(b.isLegal(Square.sq("d1"),
Square.sq("e1"), Square.sq("h1")));
assertTrue(b.isLegal(Square.sq("d1"),
Square.sq("e1"), Square.sq("d2")));
assertTrue(b.isLegal(Square.sq("a4"),
Square.sq("a5"), Square.sq("a4")));
assertTrue(b.isLegal(Square.sq("d10"),
Square.sq("d7"), Square.sq("e8")));
}
@Test
public void testUndo() {
Board b = new Board();
Move move = Move.mv(Square.sq("d1"), Square.sq("e1"), Square.sq("d2"));
b.makeMove(move);
b.undo();
assertEquals(b.toString(), INIT_BOARD_STATE);
}
static final String INIT_BOARD_STATE =
" - - - B - - B - - -\n"
+ " - - - - - - - - - -\n"
+ " - - - - - - - - - -\n"
+ " B - - - - - - - - B\n"
+ " - - - - - - - - - -\n"
+ " - - - - - - - - - -\n"
+ " W - - - - - - - - W\n"
+ " - - - - - - - - - -\n"
+ " - - - - - - - - - -\n"
+ " - - - W - - W - - -\n";
}