|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+import org.junit.Ignore;
|
|
|
2
|
+import org.junit.Rule;
|
|
|
3
|
+import org.junit.Test;
|
|
|
4
|
+import org.junit.rules.ExpectedException;
|
|
|
5
|
+
|
|
|
6
|
+import static org.junit.Assert.assertFalse;
|
|
|
7
|
+import static org.junit.Assert.assertTrue;
|
|
|
8
|
+
|
|
|
9
|
+public final class QueenAttackCalculatorTest {
|
|
|
10
|
+
|
|
|
11
|
+ /*
|
|
|
12
|
+ * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
|
|
|
13
|
+ * ExpectedExceptions in particular.
|
|
|
14
|
+ */
|
|
|
15
|
+ @Rule
|
|
|
16
|
+ public ExpectedException expectedException = ExpectedException.none();
|
|
|
17
|
+
|
|
|
18
|
+ @Ignore
|
|
|
19
|
+ @Test
|
|
|
20
|
+ public void testCoordinateWithNegativeRankNotAllowed() {
|
|
|
21
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
22
|
+ expectedException.expectMessage("Coordinate must have positive rank.");
|
|
|
23
|
+
|
|
|
24
|
+ new BoardCoordinate(-2, 2);
|
|
|
25
|
+ }
|
|
|
26
|
+
|
|
|
27
|
+ @Ignore
|
|
|
28
|
+ @Test
|
|
|
29
|
+ public void testCoordinateWithRankGreaterThan7NotAllowed() {
|
|
|
30
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
31
|
+ expectedException.expectMessage("Coordinate must have rank <= 7.");
|
|
|
32
|
+
|
|
|
33
|
+ new BoardCoordinate(8, 4);
|
|
|
34
|
+ }
|
|
|
35
|
+
|
|
|
36
|
+ @Ignore
|
|
|
37
|
+ @Test
|
|
|
38
|
+ public void testCoordinateWithNegativeFileNotAllowed() {
|
|
|
39
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
40
|
+ expectedException.expectMessage("Coordinate must have positive file.");
|
|
|
41
|
+
|
|
|
42
|
+ new BoardCoordinate(2, -2);
|
|
|
43
|
+ }
|
|
|
44
|
+
|
|
|
45
|
+ @Ignore
|
|
|
46
|
+ @Test
|
|
|
47
|
+ public void testCoordinateWithFileGreaterThan7NotAllowed() {
|
|
|
48
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
49
|
+ expectedException.expectMessage("Coordinate must have file <= 7.");
|
|
|
50
|
+
|
|
|
51
|
+ new BoardCoordinate(4, 8);
|
|
|
52
|
+ }
|
|
|
53
|
+
|
|
|
54
|
+ @Ignore
|
|
|
55
|
+ @Test
|
|
|
56
|
+ public void testNullCoordinateNotAllowed() {
|
|
|
57
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
58
|
+ expectedException.expectMessage("You must supply valid board coordinates for both Queens.");
|
|
|
59
|
+
|
|
|
60
|
+ new QueenAttackCalculator(null, new BoardCoordinate(0, 7));
|
|
|
61
|
+ }
|
|
|
62
|
+
|
|
|
63
|
+ @Ignore
|
|
|
64
|
+ @Test
|
|
|
65
|
+ public void testQueensMustNotOccupyTheSameSquare() {
|
|
|
66
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
67
|
+ expectedException.expectMessage("Queens may not occupy the same board coordinate.");
|
|
|
68
|
+
|
|
|
69
|
+ new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(2, 2));
|
|
|
70
|
+ }
|
|
|
71
|
+
|
|
|
72
|
+ @Ignore
|
|
|
73
|
+ @Test
|
|
|
74
|
+ public void testQueensThatDoNotShareRankFileOrDiagonalCannotAttack() {
|
|
|
75
|
+ final QueenAttackCalculator calculator
|
|
|
76
|
+ = new QueenAttackCalculator(new BoardCoordinate(2, 4), new BoardCoordinate(6, 6));
|
|
|
77
|
+
|
|
|
78
|
+ assertFalse(calculator.canQueensAttackOneAnother());
|
|
|
79
|
+ }
|
|
|
80
|
+
|
|
|
81
|
+ @Ignore
|
|
|
82
|
+ @Test
|
|
|
83
|
+ public void testQueensCanAttackOnTheSameRank() {
|
|
|
84
|
+ final QueenAttackCalculator calculator
|
|
|
85
|
+ = new QueenAttackCalculator(new BoardCoordinate(2, 4), new BoardCoordinate(2, 6));
|
|
|
86
|
+
|
|
|
87
|
+ assertTrue(calculator.canQueensAttackOneAnother());
|
|
|
88
|
+ }
|
|
|
89
|
+
|
|
|
90
|
+ @Ignore
|
|
|
91
|
+ @Test
|
|
|
92
|
+ public void testQueensCanAttackOnTheSameFile() {
|
|
|
93
|
+ final QueenAttackCalculator calculator
|
|
|
94
|
+ = new QueenAttackCalculator(new BoardCoordinate(4, 5), new BoardCoordinate(2, 5));
|
|
|
95
|
+
|
|
|
96
|
+ assertTrue(calculator.canQueensAttackOneAnother());
|
|
|
97
|
+ }
|
|
|
98
|
+
|
|
|
99
|
+ @Ignore
|
|
|
100
|
+ @Test
|
|
|
101
|
+ public void testQueensCanAttackOnFirstDiagonal() {
|
|
|
102
|
+ final QueenAttackCalculator calculator
|
|
|
103
|
+ = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(0, 4));
|
|
|
104
|
+
|
|
|
105
|
+ assertTrue(calculator.canQueensAttackOneAnother());
|
|
|
106
|
+ }
|
|
|
107
|
+
|
|
|
108
|
+ @Ignore
|
|
|
109
|
+ @Test
|
|
|
110
|
+ public void testQueensCanAttackOnSecondDiagonal() {
|
|
|
111
|
+ final QueenAttackCalculator calculator
|
|
|
112
|
+ = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(3, 1));
|
|
|
113
|
+
|
|
|
114
|
+ assertTrue(calculator.canQueensAttackOneAnother());
|
|
|
115
|
+ }
|
|
|
116
|
+
|
|
|
117
|
+ @Ignore
|
|
|
118
|
+ @Test
|
|
|
119
|
+ public void testQueensCanAttackOnThirdDiagonal() {
|
|
|
120
|
+ final QueenAttackCalculator calculator
|
|
|
121
|
+ = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(1, 1));
|
|
|
122
|
+
|
|
|
123
|
+ assertTrue(calculator.canQueensAttackOneAnother());
|
|
|
124
|
+ }
|
|
|
125
|
+
|
|
|
126
|
+ @Ignore
|
|
|
127
|
+ @Test
|
|
|
128
|
+ public void testQueensCanAttackOnFourthDiagonal() {
|
|
|
129
|
+ final QueenAttackCalculator calculator
|
|
|
130
|
+ = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(5, 5));
|
|
|
131
|
+
|
|
|
132
|
+ assertTrue(calculator.canQueensAttackOneAnother());
|
|
|
133
|
+ }
|
|
|
134
|
+
|
|
|
135
|
+}
|