|
|
@@ -12,119 +12,125 @@ public class QueenAttackCalculatorTest {
|
|
12
|
12
|
public ExpectedException expectedException = ExpectedException.none();
|
|
13
|
13
|
|
|
14
|
14
|
@Test
|
|
15
|
|
- public void testQueensThatDoNotShareRowColumnOrDiagonalCannotAttack() {
|
|
16
|
|
- final QueenAttackCalculator calculator
|
|
17
|
|
- = new QueenAttackCalculator(new BoardCoordinate(2, 4), new BoardCoordinate(6, 6));
|
|
|
15
|
+ public void testCreateQueenWithAValidPosition() {
|
|
|
16
|
+ new Queen(2, 2);
|
|
|
17
|
+ }
|
|
18
|
18
|
|
|
19
|
|
- assertFalse(calculator.canQueensAttackOneAnother());
|
|
|
19
|
+ @Ignore("Remove to run test")
|
|
|
20
|
+ @Test
|
|
|
21
|
+ public void testCreateQueenMustHavePositiveRow() {
|
|
|
22
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
23
|
+ expectedException.expectMessage("Queen position must have positive row.");
|
|
|
24
|
+
|
|
|
25
|
+ new Queen(-2, 2);
|
|
20
|
26
|
}
|
|
21
|
27
|
|
|
22
|
28
|
@Ignore("Remove to run test")
|
|
23
|
29
|
@Test
|
|
24
|
|
- public void testQueensCanAttackOnTheSameRow() {
|
|
25
|
|
- final QueenAttackCalculator calculator
|
|
26
|
|
- = new QueenAttackCalculator(new BoardCoordinate(2, 4), new BoardCoordinate(2, 6));
|
|
|
30
|
+ public void testCreateQueenMustHaveRowOnBoard() {
|
|
|
31
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
32
|
+ expectedException.expectMessage("Queen position must have row <= 7.");
|
|
27
|
33
|
|
|
28
|
|
- assertTrue(calculator.canQueensAttackOneAnother());
|
|
|
34
|
+ new Queen(8, 4);
|
|
29
|
35
|
}
|
|
30
|
36
|
|
|
31
|
37
|
@Ignore("Remove to run test")
|
|
32
|
38
|
@Test
|
|
33
|
|
- public void testQueensCanAttackOnTheSameColumn() {
|
|
34
|
|
- final QueenAttackCalculator calculator
|
|
35
|
|
- = new QueenAttackCalculator(new BoardCoordinate(4, 5), new BoardCoordinate(2, 5));
|
|
|
39
|
+ public void testCreateQueenMustHavePositiveColumn() {
|
|
|
40
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
41
|
+ expectedException.expectMessage("Queen position must have positive column.");
|
|
36
|
42
|
|
|
37
|
|
- assertTrue(calculator.canQueensAttackOneAnother());
|
|
|
43
|
+ new Queen(2, -2);
|
|
38
|
44
|
}
|
|
39
|
45
|
|
|
40
|
46
|
@Ignore("Remove to run test")
|
|
41
|
47
|
@Test
|
|
42
|
|
- public void testQueensCanAttackOnFirstDiagonal() {
|
|
43
|
|
- final QueenAttackCalculator calculator
|
|
44
|
|
- = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(0, 4));
|
|
|
48
|
+ public void testCreateQueenMustHaveColumnOnBoard() {
|
|
|
49
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
50
|
+ expectedException.expectMessage("Queen position must have column <= 7.");
|
|
45
|
51
|
|
|
46
|
|
- assertTrue(calculator.canQueensAttackOneAnother());
|
|
|
52
|
+ new Queen(4, 8);
|
|
47
|
53
|
}
|
|
48
|
54
|
|
|
49
|
55
|
@Ignore("Remove to run test")
|
|
50
|
56
|
@Test
|
|
51
|
|
- public void testQueensCanAttackOnSecondDiagonal() {
|
|
|
57
|
+ public void testQueensCannotAttack() {
|
|
52
|
58
|
final QueenAttackCalculator calculator
|
|
53
|
|
- = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(3, 1));
|
|
|
59
|
+ = new QueenAttackCalculator(new Queen(2, 4), new Queen(6, 6));
|
|
54
|
60
|
|
|
55
|
|
- assertTrue(calculator.canQueensAttackOneAnother());
|
|
|
61
|
+ assertFalse(calculator.canQueensAttackOneAnother());
|
|
56
|
62
|
}
|
|
57
|
63
|
|
|
58
|
64
|
@Ignore("Remove to run test")
|
|
59
|
65
|
@Test
|
|
60
|
|
- public void testQueensCanAttackOnThirdDiagonal() {
|
|
|
66
|
+ public void testQueensCanAttackOnTheSameRow() {
|
|
61
|
67
|
final QueenAttackCalculator calculator
|
|
62
|
|
- = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(1, 1));
|
|
|
68
|
+ = new QueenAttackCalculator(new Queen(2, 4), new Queen(2, 6));
|
|
63
|
69
|
|
|
64
|
70
|
assertTrue(calculator.canQueensAttackOneAnother());
|
|
65
|
71
|
}
|
|
66
|
72
|
|
|
67
|
73
|
@Ignore("Remove to run test")
|
|
68
|
74
|
@Test
|
|
69
|
|
- public void testQueensCanAttackOnFourthDiagonal() {
|
|
|
75
|
+ public void testQueensCanAttackOnTheSameColumn() {
|
|
70
|
76
|
final QueenAttackCalculator calculator
|
|
71
|
|
- = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(5, 5));
|
|
|
77
|
+ = new QueenAttackCalculator(new Queen(4, 5), new Queen(2, 5));
|
|
72
|
78
|
|
|
73
|
79
|
assertTrue(calculator.canQueensAttackOneAnother());
|
|
74
|
80
|
}
|
|
75
|
81
|
|
|
76
|
82
|
@Ignore("Remove to run test")
|
|
77
|
83
|
@Test
|
|
78
|
|
- public void testCoordinateWithNegativeRowNotAllowed() {
|
|
79
|
|
- expectedException.expect(IllegalArgumentException.class);
|
|
80
|
|
- expectedException.expectMessage("Coordinate must have positive row.");
|
|
|
84
|
+ public void testQueensCanAttackOnFirstDiagonal() {
|
|
|
85
|
+ final QueenAttackCalculator calculator
|
|
|
86
|
+ = new QueenAttackCalculator(new Queen(2, 2), new Queen(0, 4));
|
|
81
|
87
|
|
|
82
|
|
- new BoardCoordinate(-2, 2);
|
|
|
88
|
+ assertTrue(calculator.canQueensAttackOneAnother());
|
|
83
|
89
|
}
|
|
84
|
90
|
|
|
85
|
91
|
@Ignore("Remove to run test")
|
|
86
|
92
|
@Test
|
|
87
|
|
- public void testCoordinateWithRowGreaterThan7NotAllowed() {
|
|
88
|
|
- expectedException.expect(IllegalArgumentException.class);
|
|
89
|
|
- expectedException.expectMessage("Coordinate must have row <= 7.");
|
|
|
93
|
+ public void testQueensCanAttackOnSecondDiagonal() {
|
|
|
94
|
+ final QueenAttackCalculator calculator
|
|
|
95
|
+ = new QueenAttackCalculator(new Queen(2, 2), new Queen(3, 1));
|
|
90
|
96
|
|
|
91
|
|
- new BoardCoordinate(8, 4);
|
|
|
97
|
+ assertTrue(calculator.canQueensAttackOneAnother());
|
|
92
|
98
|
}
|
|
93
|
99
|
|
|
94
|
100
|
@Ignore("Remove to run test")
|
|
95
|
101
|
@Test
|
|
96
|
|
- public void testCoordinateWithNegativeColumnNotAllowed() {
|
|
97
|
|
- expectedException.expect(IllegalArgumentException.class);
|
|
98
|
|
- expectedException.expectMessage("Coordinate must have positive column.");
|
|
|
102
|
+ public void testQueensCanAttackOnThirdDiagonal() {
|
|
|
103
|
+ final QueenAttackCalculator calculator
|
|
|
104
|
+ = new QueenAttackCalculator(new Queen(2, 2), new Queen(1, 1));
|
|
99
|
105
|
|
|
100
|
|
- new BoardCoordinate(2, -2);
|
|
|
106
|
+ assertTrue(calculator.canQueensAttackOneAnother());
|
|
101
|
107
|
}
|
|
102
|
108
|
|
|
103
|
109
|
@Ignore("Remove to run test")
|
|
104
|
110
|
@Test
|
|
105
|
|
- public void testCoordinateWithColumnGreaterThan7NotAllowed() {
|
|
106
|
|
- expectedException.expect(IllegalArgumentException.class);
|
|
107
|
|
- expectedException.expectMessage("Coordinate must have column <= 7.");
|
|
|
111
|
+ public void testQueensCanAttackOnFourthDiagonal() {
|
|
|
112
|
+ final QueenAttackCalculator calculator
|
|
|
113
|
+ = new QueenAttackCalculator(new Queen(2, 2), new Queen(5, 5));
|
|
108
|
114
|
|
|
109
|
|
- new BoardCoordinate(4, 8);
|
|
|
115
|
+ assertTrue(calculator.canQueensAttackOneAnother());
|
|
110
|
116
|
}
|
|
111
|
117
|
|
|
112
|
118
|
@Ignore("Remove to run test")
|
|
113
|
119
|
@Test
|
|
114
|
|
- public void testNullCoordinateNotAllowed() {
|
|
|
120
|
+ public void testNullPositionsNotAllowed() {
|
|
115
|
121
|
expectedException.expect(IllegalArgumentException.class);
|
|
116
|
|
- expectedException.expectMessage("You must supply valid board coordinates for both Queens.");
|
|
|
122
|
+ expectedException.expectMessage("You must supply valid positions for both Queens.");
|
|
117
|
123
|
|
|
118
|
|
- new QueenAttackCalculator(null, new BoardCoordinate(0, 7));
|
|
|
124
|
+ new QueenAttackCalculator(null, new Queen(0, 7));
|
|
119
|
125
|
}
|
|
120
|
126
|
|
|
121
|
127
|
@Ignore("Remove to run test")
|
|
122
|
128
|
@Test
|
|
123
|
129
|
public void testQueensMustNotOccupyTheSameSquare() {
|
|
124
|
130
|
expectedException.expect(IllegalArgumentException.class);
|
|
125
|
|
- expectedException.expectMessage("Queens may not occupy the same board coordinate.");
|
|
|
131
|
+ expectedException.expectMessage("Queens cannot occupy the same position.");
|
|
126
|
132
|
|
|
127
|
|
- new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(2, 2));
|
|
|
133
|
+ new QueenAttackCalculator(new Queen(2, 2), new Queen(2, 2));
|
|
128
|
134
|
}
|
|
129
|
135
|
|
|
130
|
136
|
}
|