11import org .junit .Ignore ;
2- import org .junit .Rule ;
32import org .junit .Test ;
4- import org .junit .rules .ExpectedException ;
53
64import java .util .Arrays ;
75import java .util .Collections ;
1412 */
1513public class MinesweeperBoardTest {
1614
17- /*
18- * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
19- * ExpectedExceptions in particular.
20- */
21- @ Rule
22- public ExpectedException expectedException = ExpectedException .none ();
23-
2415 @ Test
2516 public void testInputBoardWithNoRowsAndNoColumns () {
2617 final List <String > inputBoard = Collections .emptyList ();
27- final List <String > expectedAnnotatedRepresentation = Collections .emptyList ();
28- final List <String > actualAnnotatedRepresentation
29- = new MinesweeperBoard (inputBoard ).getAnnotatedRepresentation ();
18+ final List <String > expectedNumberedBoard = Collections .emptyList ();
19+ final List <String > actualNumberedBoard = new MinesweeperBoard (inputBoard ).withNumbers ();
3020
31- assertEquals (expectedAnnotatedRepresentation , actualAnnotatedRepresentation );
21+ assertEquals (expectedNumberedBoard , actualNumberedBoard );
3222 }
3323
3424 @ Ignore ("Remove to run test" )
3525 @ Test
3626 public void testInputBoardWithOneRowAndNoColumns () {
3727 final List <String > inputBoard = Collections .singletonList ("" );
38- final List <String > expectedAnnotatedRepresentation = Collections .singletonList ("" );
39- final List <String > actualAnnotatedRepresentation
40- = new MinesweeperBoard (inputBoard ).getAnnotatedRepresentation ();
28+ final List <String > expectedNumberedBoard = Collections .singletonList ("" );
29+ final List <String > actualNumberedBoard = new MinesweeperBoard (inputBoard ).withNumbers ();
4130
42- assertEquals (expectedAnnotatedRepresentation , actualAnnotatedRepresentation );
31+ assertEquals (expectedNumberedBoard , actualNumberedBoard );
4332 }
4433
4534 @ Ignore ("Remove to run test" )
@@ -51,16 +40,15 @@ public void testInputBoardWithNoMines() {
5140 " "
5241 );
5342
54- final List <String > expectedAnnotatedRepresentation = Arrays .asList (
43+ final List <String > expectedNumberedBoard = Arrays .asList (
5544 " " ,
5645 " " ,
5746 " "
5847 );
5948
60- final List <String > actualAnnotatedRepresentation
61- = new MinesweeperBoard (inputBoard ).getAnnotatedRepresentation ();
49+ final List <String > actualNumberedBoard = new MinesweeperBoard (inputBoard ).withNumbers ();
6250
63- assertEquals (expectedAnnotatedRepresentation , actualAnnotatedRepresentation );
51+ assertEquals (expectedNumberedBoard , actualNumberedBoard );
6452 }
6553
6654 @ Ignore ("Remove to run test" )
@@ -72,16 +60,15 @@ public void testInputBoardWithOnlyMines() {
7260 "***"
7361 );
7462
75- final List <String > expectedAnnotatedRepresentation = Arrays .asList (
63+ final List <String > expectedNumberedBoard = Arrays .asList (
7664 "***" ,
7765 "***" ,
7866 "***"
7967 );
8068
81- final List <String > actualAnnotatedRepresentation
82- = new MinesweeperBoard (inputBoard ).getAnnotatedRepresentation ();
69+ final List <String > actualNumberedBoard = new MinesweeperBoard (inputBoard ).withNumbers ();
8370
84- assertEquals (expectedAnnotatedRepresentation , actualAnnotatedRepresentation );
71+ assertEquals (expectedNumberedBoard , actualNumberedBoard );
8572 }
8673
8774 @ Ignore ("Remove to run test" )
@@ -93,16 +80,15 @@ public void testInputBoardWithSingleMineAtCenter() {
9380 " "
9481 );
9582
96- final List <String > expectedAnnotatedRepresentation = Arrays .asList (
83+ final List <String > expectedNumberedBoard = Arrays .asList (
9784 "111" ,
9885 "1*1" ,
9986 "111"
10087 );
10188
102- final List <String > actualAnnotatedRepresentation
103- = new MinesweeperBoard (inputBoard ).getAnnotatedRepresentation ();
89+ final List <String > actualNumberedBoard = new MinesweeperBoard (inputBoard ).withNumbers ();
10490
105- assertEquals (expectedAnnotatedRepresentation , actualAnnotatedRepresentation );
91+ assertEquals (expectedNumberedBoard , actualNumberedBoard );
10692 }
10793
10894 @ Ignore ("Remove to run test" )
@@ -114,16 +100,15 @@ public void testInputBoardWithMinesAroundPerimeter() {
114100 "***"
115101 );
116102
117- final List <String > expectedAnnotatedRepresentation = Arrays .asList (
103+ final List <String > expectedNumberedBoard = Arrays .asList (
118104 "***" ,
119105 "*8*" ,
120106 "***"
121107 );
122108
123- final List <String > actualAnnotatedRepresentation
124- = new MinesweeperBoard (inputBoard ).getAnnotatedRepresentation ();
109+ final List <String > actualNumberedBoard = new MinesweeperBoard (inputBoard ).withNumbers ();
125110
126- assertEquals (expectedAnnotatedRepresentation , actualAnnotatedRepresentation );
111+ assertEquals (expectedNumberedBoard , actualNumberedBoard );
127112 }
128113
129114 @ Ignore ("Remove to run test" )
@@ -133,14 +118,13 @@ public void testInputBoardWithSingleRowAndTwoMines() {
133118 " * * "
134119 );
135120
136- final List <String > expectedAnnotatedRepresentation = Collections .singletonList (
121+ final List <String > expectedNumberedBoard = Collections .singletonList (
137122 "1*2*1"
138123 );
139124
140- final List <String > actualAnnotatedRepresentation
141- = new MinesweeperBoard (inputBoard ).getAnnotatedRepresentation ();
125+ final List <String > actualNumberedBoard = new MinesweeperBoard (inputBoard ).withNumbers ();
142126
143- assertEquals (expectedAnnotatedRepresentation , actualAnnotatedRepresentation );
127+ assertEquals (expectedNumberedBoard , actualNumberedBoard );
144128 }
145129
146130 @ Ignore ("Remove to run test" )
@@ -150,14 +134,13 @@ public void testInputBoardWithSingleRowAndTwoMinesAtEdges() {
150134 "* *"
151135 );
152136
153- final List <String > expectedAnnotatedRepresentation = Collections .singletonList (
137+ final List <String > expectedNumberedBoard = Collections .singletonList (
154138 "*1 1*"
155139 );
156140
157- final List <String > actualAnnotatedRepresentation
158- = new MinesweeperBoard (inputBoard ).getAnnotatedRepresentation ();
141+ final List <String > actualNumberedBoard = new MinesweeperBoard (inputBoard ).withNumbers ();
159142
160- assertEquals (expectedAnnotatedRepresentation , actualAnnotatedRepresentation );
143+ assertEquals (expectedNumberedBoard , actualNumberedBoard );
161144 }
162145
163146 @ Ignore ("Remove to run test" )
@@ -171,18 +154,17 @@ public void testInputBoardWithSingleColumnAndTwoMines() {
171154 " "
172155 );
173156
174- final List <String > expectedAnnotatedRepresentation = Arrays .asList (
157+ final List <String > expectedNumberedBoard = Arrays .asList (
175158 "1" ,
176159 "*" ,
177160 "2" ,
178161 "*" ,
179162 "1"
180163 );
181164
182- final List <String > actualAnnotatedRepresentation
183- = new MinesweeperBoard (inputBoard ).getAnnotatedRepresentation ();
165+ final List <String > actualNumberedBoard = new MinesweeperBoard (inputBoard ).withNumbers ();
184166
185- assertEquals (expectedAnnotatedRepresentation , actualAnnotatedRepresentation );
167+ assertEquals (expectedNumberedBoard , actualNumberedBoard );
186168 }
187169
188170 @ Ignore ("Remove to run test" )
@@ -196,18 +178,17 @@ public void testInputBoardWithSingleColumnAndTwoMinesAtEdges() {
196178 "*"
197179 );
198180
199- final List <String > expectedAnnotatedRepresentation = Arrays .asList (
181+ final List <String > expectedNumberedBoard = Arrays .asList (
200182 "*" ,
201183 "1" ,
202184 " " ,
203185 "1" ,
204186 "*"
205187 );
206188
207- final List <String > actualAnnotatedRepresentation
208- = new MinesweeperBoard (inputBoard ).getAnnotatedRepresentation ();
189+ final List <String > actualNumberedBoard = new MinesweeperBoard (inputBoard ).withNumbers ();
209190
210- assertEquals (expectedAnnotatedRepresentation , actualAnnotatedRepresentation );
191+ assertEquals (expectedNumberedBoard , actualNumberedBoard );
211192 }
212193
213194 @ Ignore ("Remove to run test" )
@@ -221,18 +202,17 @@ public void testInputBoardWithMinesInCross() {
221202 " * "
222203 );
223204
224- final List <String > expectedAnnotatedRepresentation = Arrays .asList (
205+ final List <String > expectedNumberedBoard = Arrays .asList (
225206 " 2*2 " ,
226207 "25*52" ,
227208 "*****" ,
228209 "25*52" ,
229210 " 2*2 "
230211 );
231212
232- final List <String > actualAnnotatedRepresentation
233- = new MinesweeperBoard (inputBoard ).getAnnotatedRepresentation ();
213+ final List <String > actualNumberedBoard = new MinesweeperBoard (inputBoard ).withNumbers ();
234214
235- assertEquals (expectedAnnotatedRepresentation , actualAnnotatedRepresentation );
215+ assertEquals (expectedNumberedBoard , actualNumberedBoard );
236216 }
237217
238218 @ Ignore ("Remove to run test" )
@@ -247,7 +227,7 @@ public void testLargeInputBoard() {
247227 " "
248228 );
249229
250- final List <String > expectedAnnotatedRepresentation = Arrays .asList (
230+ final List <String > expectedNumberedBoard = Arrays .asList (
251231 "1*22*1" ,
252232 "12*322" ,
253233 " 123*2" ,
@@ -256,43 +236,9 @@ public void testLargeInputBoard() {
256236 "111111"
257237 );
258238
259- final List <String > actualAnnotatedRepresentation
260- = new MinesweeperBoard (inputBoard ).getAnnotatedRepresentation ();
261-
262- assertEquals (expectedAnnotatedRepresentation , actualAnnotatedRepresentation );
263- }
264-
265- @ Ignore ("Remove to run test" )
266- @ Test
267- public void testNullInputBoardIsRejected () {
268- expectedException .expect (IllegalArgumentException .class );
269- expectedException .expectMessage ("Input board may not be null." );
270-
271- new MinesweeperBoard (null );
272- }
239+ final List <String > actualNumberedBoard = new MinesweeperBoard (inputBoard ).withNumbers ();
273240
274- @ Ignore ("Remove to run test" )
275- @ Test
276- public void testInputBoardWithInvalidSymbolsIsRejected () {
277- expectedException .expect (IllegalArgumentException .class );
278- expectedException .expectMessage ("Input board can only contain the characters ' ' and '*'." );
279-
280- new MinesweeperBoard (Collections .singletonList (" * & " ));
281- }
282-
283- @ Ignore ("Remove to run test" )
284- @ Test
285- public void testInputBoardWithInconsistentRowLengthsIsRejected () {
286- expectedException .expect (IllegalArgumentException .class );
287- expectedException .expectMessage ("Input board rows must all have the same number of columns." );
288-
289- new MinesweeperBoard (Arrays .asList (
290- "*" ,
291- "**" ,
292- "* *" ,
293- "* *" ,
294- "* *"
295- ));
241+ assertEquals (expectedNumberedBoard , actualNumberedBoard );
296242 }
297243
298244}
0 commit comments