Skip to content

Commit 81d66b6

Browse files
committed
Setup exercise
0 parents  commit 81d66b6

File tree

6 files changed

+342
-0
lines changed

6 files changed

+342
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/src/example

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: java

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Minesweeper is a popular game where the user has to find the mines using
2+
numeric hints that indicate how many mines are directly adjacent
3+
(horizontally, vertically, diagonally) to a square.
4+
5+
In this exercise you have to create some code that counts the number of
6+
mines adjacent to a square and transforms boards like this (where `*`
7+
indicates a mine):
8+
9+
+-----+
10+
| * * |
11+
| * |
12+
| * |
13+
| |
14+
+-----+
15+
16+
into this:
17+
18+
+-----+
19+
|1*3*1|
20+
|13*31|
21+
| 2*2 |
22+
| 111 |
23+
+-----+

build.gradle

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apply plugin: "java"
2+
apply plugin: "eclipse"
3+
apply plugin: "idea"
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
testCompile "junit:junit:4.12"
11+
}
12+
test {
13+
testLogging {
14+
exceptionFormat = 'full'
15+
events = ["passed", "failed", "skipped"]
16+
}
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public final class MinesweeperBoard {
2+
3+
4+
5+
}
Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
import org.junit.Ignore;
2+
import org.junit.Rule;
3+
import org.junit.Test;
4+
import org.junit.rules.ExpectedException;
5+
6+
import java.util.Arrays;
7+
import java.util.Collections;
8+
import java.util.List;
9+
10+
import static org.junit.Assert.assertEquals;
11+
12+
public final class MinesweeperBoardTest {
13+
14+
/*
15+
* See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
16+
* ExpectedExceptions in particular.
17+
*/
18+
@Rule
19+
public ExpectedException expectedException = ExpectedException.none();
20+
21+
@Test
22+
public void testInputBoardWithNoRowsAndNoColumns() {
23+
final List<String> inputBoard = Collections.emptyList();
24+
final List<String> expectedAnnotatedRepresentation = Collections.emptyList();
25+
final List<String> actualAnnotatedRepresentation
26+
= new MinesweeperBoard(inputBoard).getAnnotatedRepresentation();
27+
28+
assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation);
29+
}
30+
31+
@Ignore
32+
@Test
33+
public void testInputBoardWithOneRowAndNoColumns() {
34+
final List<String> inputBoard = Collections.singletonList("");
35+
final List<String> expectedAnnotatedRepresentation = Collections.singletonList("");
36+
final List<String> actualAnnotatedRepresentation
37+
= new MinesweeperBoard(inputBoard).getAnnotatedRepresentation();
38+
39+
assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation);
40+
}
41+
42+
@Ignore
43+
@Test
44+
public void testInputBoardWithNoMines() {
45+
final List<String> inputBoard = Arrays.asList(
46+
" ",
47+
" ",
48+
" "
49+
);
50+
51+
final List<String> expectedAnnotatedRepresentation = Arrays.asList(
52+
" ",
53+
" ",
54+
" "
55+
);
56+
57+
final List<String> actualAnnotatedRepresentation
58+
= new MinesweeperBoard(inputBoard).getAnnotatedRepresentation();
59+
60+
assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation);
61+
}
62+
63+
@Ignore
64+
@Test
65+
public void testInputBoardWithOnlyMines() {
66+
final List<String> inputBoard = Arrays.asList(
67+
"***",
68+
"***",
69+
"***"
70+
);
71+
72+
final List<String> expectedAnnotatedRepresentation = Arrays.asList(
73+
"***",
74+
"***",
75+
"***"
76+
);
77+
78+
final List<String> actualAnnotatedRepresentation
79+
= new MinesweeperBoard(inputBoard).getAnnotatedRepresentation();
80+
81+
assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation);
82+
}
83+
84+
@Ignore
85+
@Test
86+
public void testInputBoardWithSingleMineAtCenter() {
87+
final List<String> inputBoard = Arrays.asList(
88+
" ",
89+
" * ",
90+
" "
91+
);
92+
93+
final List<String> expectedAnnotatedRepresentation = Arrays.asList(
94+
"111",
95+
"1*1",
96+
"111"
97+
);
98+
99+
final List<String> actualAnnotatedRepresentation
100+
= new MinesweeperBoard(inputBoard).getAnnotatedRepresentation();
101+
102+
assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation);
103+
}
104+
105+
@Ignore
106+
@Test
107+
public void testInputBoardWithMinesAroundPerimeter() {
108+
final List<String> inputBoard = Arrays.asList(
109+
"***",
110+
"* *",
111+
"***"
112+
);
113+
114+
final List<String> expectedAnnotatedRepresentation = Arrays.asList(
115+
"***",
116+
"*8*",
117+
"***"
118+
);
119+
120+
final List<String> actualAnnotatedRepresentation
121+
= new MinesweeperBoard(inputBoard).getAnnotatedRepresentation();
122+
123+
assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation);
124+
}
125+
126+
@Ignore
127+
@Test
128+
public void testInputBoardWithSingleRowAndTwoMines() {
129+
final List<String> inputBoard = Collections.singletonList(
130+
" * * "
131+
);
132+
133+
final List<String> expectedAnnotatedRepresentation = Collections.singletonList(
134+
"1*2*1"
135+
);
136+
137+
final List<String> actualAnnotatedRepresentation
138+
= new MinesweeperBoard(inputBoard).getAnnotatedRepresentation();
139+
140+
assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation);
141+
}
142+
143+
@Ignore
144+
@Test
145+
public void testInputBoardWithSingleRowAndTwoMinesAtEdges() {
146+
final List<String> inputBoard = Collections.singletonList(
147+
"* *"
148+
);
149+
150+
final List<String> expectedAnnotatedRepresentation = Collections.singletonList(
151+
"*1 1*"
152+
);
153+
154+
final List<String> actualAnnotatedRepresentation
155+
= new MinesweeperBoard(inputBoard).getAnnotatedRepresentation();
156+
157+
assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation);
158+
}
159+
160+
@Ignore
161+
@Test
162+
public void testInputBoardWithSingleColumnAndTwoMines() {
163+
final List<String> inputBoard = Arrays.asList(
164+
" ",
165+
"*",
166+
" ",
167+
"*",
168+
" "
169+
);
170+
171+
final List<String> expectedAnnotatedRepresentation = Arrays.asList(
172+
"1",
173+
"*",
174+
"2",
175+
"*",
176+
"1"
177+
);
178+
179+
final List<String> actualAnnotatedRepresentation
180+
= new MinesweeperBoard(inputBoard).getAnnotatedRepresentation();
181+
182+
assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation);
183+
}
184+
185+
@Ignore
186+
@Test
187+
public void testInputBoardWithSingleColumnAndTwoMinesAtEdges() {
188+
final List<String> inputBoard = Arrays.asList(
189+
"*",
190+
" ",
191+
" ",
192+
" ",
193+
"*"
194+
);
195+
196+
final List<String> expectedAnnotatedRepresentation = Arrays.asList(
197+
"*",
198+
"1",
199+
" ",
200+
"1",
201+
"*"
202+
);
203+
204+
final List<String> actualAnnotatedRepresentation
205+
= new MinesweeperBoard(inputBoard).getAnnotatedRepresentation();
206+
207+
assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation);
208+
}
209+
210+
@Ignore
211+
@Test
212+
public void testInputBoardWithMinesInCross() {
213+
final List<String> inputBoard = Arrays.asList(
214+
" * ",
215+
" * ",
216+
"*****",
217+
" * ",
218+
" * "
219+
);
220+
221+
final List<String> expectedAnnotatedRepresentation = Arrays.asList(
222+
" 2*2 ",
223+
"25*52",
224+
"*****",
225+
"25*52",
226+
" 2*2 "
227+
);
228+
229+
final List<String> actualAnnotatedRepresentation
230+
= new MinesweeperBoard(inputBoard).getAnnotatedRepresentation();
231+
232+
assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation);
233+
}
234+
235+
@Ignore
236+
@Test
237+
public void testLargeInputBoard() {
238+
final List<String> inputBoard = Arrays.asList(
239+
" * * ",
240+
" * ",
241+
" * ",
242+
" * *",
243+
" * * ",
244+
" "
245+
);
246+
247+
final List<String> expectedAnnotatedRepresentation = Arrays.asList(
248+
"1*22*1",
249+
"12*322",
250+
" 123*2",
251+
"112*4*",
252+
"1*22*2",
253+
"111111"
254+
);
255+
256+
final List<String> actualAnnotatedRepresentation
257+
= new MinesweeperBoard(inputBoard).getAnnotatedRepresentation();
258+
259+
assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation);
260+
}
261+
262+
@Ignore
263+
@Test
264+
public void testNullInputBoardIsRejected() {
265+
expectedException.expect(IllegalArgumentException.class);
266+
expectedException.expectMessage("Input board may not be null.");
267+
268+
new MinesweeperBoard(null);
269+
}
270+
271+
@Ignore
272+
@Test
273+
public void testInputBoardWithInvalidSymbolsIsRejected() {
274+
expectedException.expect(IllegalArgumentException.class);
275+
expectedException.expectMessage("Input board can only contain the characters ' ' and '*'.");
276+
277+
new MinesweeperBoard(Collections.singletonList(" * & "));
278+
}
279+
280+
@Ignore
281+
@Test
282+
public void testInputBoardWithInconsistentRowLengthsIsRejected() {
283+
expectedException.expect(IllegalArgumentException.class);
284+
expectedException.expectMessage("Input board rows must all have the same number of columns.");
285+
286+
new MinesweeperBoard(Arrays.asList(
287+
"*",
288+
"**",
289+
"* *",
290+
"* *",
291+
"* *"
292+
));
293+
}
294+
295+
}

0 commit comments

Comments
 (0)