|
|
@@ -1,5 +1,6 @@
|
|
1
|
1
|
import org.junit.Before;
|
|
2
|
2
|
import org.junit.Test;
|
|
|
3
|
+import org.junit.Ignore;
|
|
3
|
4
|
|
|
4
|
5
|
import java.util.*;
|
|
5
|
6
|
|
|
|
@@ -15,7 +16,136 @@ public class WordSearcherTest {
|
|
15
|
16
|
}
|
|
16
|
17
|
|
|
17
|
18
|
@Test
|
|
18
|
|
- public void testLocatesWordsWrittenLeftToRight() {
|
|
|
19
|
+ public void testAcceptsInitialGridAndTargetWord() {
|
|
|
20
|
+ Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
21
|
+ expectedLocations.put("clojure", Optional.empty());
|
|
|
22
|
+
|
|
|
23
|
+ Set<String> searchWords = expectedLocations.keySet();
|
|
|
24
|
+
|
|
|
25
|
+ Map<String, Optional<WordLocation>> actualLocations = wordSearcher.search(
|
|
|
26
|
+ searchWords,
|
|
|
27
|
+ new char[][]{
|
|
|
28
|
+ {'j', 'e', 'f', 'b', 'l', 'p', 'e', 'p', 'r', 'e'}
|
|
|
29
|
+ }
|
|
|
30
|
+ );
|
|
|
31
|
+
|
|
|
32
|
+ assertEquals(expectedLocations, actualLocations);
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
|
35
|
+ @Ignore("Remove to run test")
|
|
|
36
|
+ @Test
|
|
|
37
|
+ public void testLocatesOneWordWrittenLeftToRight() {
|
|
|
38
|
+ Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
39
|
+ expectedLocations.put("clojure", Optional.of(new WordLocation(new Pair(1, 1), new Pair(7, 1))));
|
|
|
40
|
+
|
|
|
41
|
+ Set<String> searchWords = expectedLocations.keySet();
|
|
|
42
|
+
|
|
|
43
|
+ Map<String, Optional<WordLocation>> actualLocations = wordSearcher.search(
|
|
|
44
|
+ searchWords,
|
|
|
45
|
+ new char[][]{
|
|
|
46
|
+ {'c', 'l', 'o', 'j', 'u', 'r', 'e', 'r', 'm', 't'}
|
|
|
47
|
+ }
|
|
|
48
|
+ );
|
|
|
49
|
+
|
|
|
50
|
+ assertEquals(expectedLocations, actualLocations);
|
|
|
51
|
+ }
|
|
|
52
|
+
|
|
|
53
|
+ @Ignore("Remove to run test")
|
|
|
54
|
+ @Test
|
|
|
55
|
+ public void testShouldLocateTheSameWordLeftToRightInDifferentPosition() {
|
|
|
56
|
+ Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
57
|
+ expectedLocations.put("clojure", Optional.of(new WordLocation(new Pair(3, 1), new Pair(9, 1))));
|
|
|
58
|
+
|
|
|
59
|
+ Set<String> searchWords = expectedLocations.keySet();
|
|
|
60
|
+
|
|
|
61
|
+ Map<String, Optional<WordLocation>> actualLocations = wordSearcher.search(
|
|
|
62
|
+ searchWords,
|
|
|
63
|
+ new char[][]{
|
|
|
64
|
+ {'m', 't', 'c', 'l', 'o', 'j', 'u', 'r', 'e', 'r'}
|
|
|
65
|
+ }
|
|
|
66
|
+ );
|
|
|
67
|
+
|
|
|
68
|
+ assertEquals(expectedLocations, actualLocations);
|
|
|
69
|
+ }
|
|
|
70
|
+
|
|
|
71
|
+ @Ignore("Remove to run test")
|
|
|
72
|
+ @Test
|
|
|
73
|
+ public void testShouldLocateADifferentLeftToRightWord() {
|
|
|
74
|
+ Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
75
|
+ expectedLocations.put("coffee", Optional.of(new WordLocation(new Pair(1, 1), new Pair(6, 1))));
|
|
|
76
|
+
|
|
|
77
|
+ Set<String> searchWords = expectedLocations.keySet();
|
|
|
78
|
+
|
|
|
79
|
+ Map<String, Optional<WordLocation>> actualLocations = wordSearcher.search(
|
|
|
80
|
+ searchWords,
|
|
|
81
|
+ new char[][]{
|
|
|
82
|
+ {'c', 'o', 'f', 'f', 'e', 'e', 'l', 'p', 'l', 'x'}
|
|
|
83
|
+ }
|
|
|
84
|
+ );
|
|
|
85
|
+
|
|
|
86
|
+ assertEquals(expectedLocations, actualLocations);
|
|
|
87
|
+ }
|
|
|
88
|
+
|
|
|
89
|
+ @Ignore("Remove to run test")
|
|
|
90
|
+ @Test
|
|
|
91
|
+ public void testShouldLocateThatDifferentLeftToRightWordInADifferentPosition() {
|
|
|
92
|
+ Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
93
|
+ expectedLocations.put("coffee", Optional.of(new WordLocation(new Pair(2, 1), new Pair(7, 1))));
|
|
|
94
|
+
|
|
|
95
|
+ Set<String> searchWords = expectedLocations.keySet();
|
|
|
96
|
+
|
|
|
97
|
+ Map<String, Optional<WordLocation>> actualLocations = wordSearcher.search(
|
|
|
98
|
+ searchWords,
|
|
|
99
|
+ new char[][]{
|
|
|
100
|
+ {'x', 'c', 'o', 'f', 'f', 'e', 'e', 'z', 'l', 'p'}
|
|
|
101
|
+ }
|
|
|
102
|
+ );
|
|
|
103
|
+
|
|
|
104
|
+ assertEquals(expectedLocations, actualLocations);
|
|
|
105
|
+ }
|
|
|
106
|
+
|
|
|
107
|
+ @Ignore("Remove to run test")
|
|
|
108
|
+ @Test
|
|
|
109
|
+ public void testShouldLocateLeftToRightWordInTwoLineGrid() {
|
|
|
110
|
+ Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
111
|
+ expectedLocations.put("clojure", Optional.of(new WordLocation(new Pair(2, 2), new Pair(8, 2))));
|
|
|
112
|
+
|
|
|
113
|
+ Set<String> searchWords = expectedLocations.keySet();
|
|
|
114
|
+
|
|
|
115
|
+ Map<String, Optional<WordLocation>> actualLocations = wordSearcher.search(
|
|
|
116
|
+ searchWords,
|
|
|
117
|
+ new char[][]{
|
|
|
118
|
+ {'j', 'e', 'f', 'b', 'l', 'p', 'e', 'p', 'r', 'e'},
|
|
|
119
|
+ {'t', 'c', 'l', 'o', 'j', 'u', 'r', 'e', 'r', 'm'}
|
|
|
120
|
+ }
|
|
|
121
|
+ );
|
|
|
122
|
+
|
|
|
123
|
+ assertEquals(expectedLocations, actualLocations);
|
|
|
124
|
+ }
|
|
|
125
|
+
|
|
|
126
|
+ @Ignore("Remove to run test")
|
|
|
127
|
+ @Test
|
|
|
128
|
+ public void testShouldLocateLeftToRightWordInThreeLineGrid() {
|
|
|
129
|
+ Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
130
|
+ expectedLocations.put("clojure", Optional.of(new WordLocation(new Pair(1, 3), new Pair(7, 3))));
|
|
|
131
|
+
|
|
|
132
|
+ Set<String> searchWords = expectedLocations.keySet();
|
|
|
133
|
+
|
|
|
134
|
+ Map<String, Optional<WordLocation>> actualLocations = wordSearcher.search(
|
|
|
135
|
+ searchWords,
|
|
|
136
|
+ new char[][]{
|
|
|
137
|
+ {'c', 'a', 'm', 'd', 'c', 'i', 'm', 'g', 't', 'c'},
|
|
|
138
|
+ {'j', 'e', 'f', 'b', 'l', 'p', 'e', 'p', 'r', 'e'},
|
|
|
139
|
+ {'c', 'l', 'o', 'j', 'u', 'r', 'e', 'r', 'm', 't'}
|
|
|
140
|
+ }
|
|
|
141
|
+ );
|
|
|
142
|
+
|
|
|
143
|
+ assertEquals(expectedLocations, actualLocations);
|
|
|
144
|
+ }
|
|
|
145
|
+
|
|
|
146
|
+ @Ignore("Remove to run test")
|
|
|
147
|
+ @Test
|
|
|
148
|
+ public void testLocatesWordWrittenLeftToRightInTenLineGrid() {
|
|
19
|
149
|
Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
20
|
150
|
expectedLocations.put("clojure", Optional.of(new WordLocation(new Pair(1, 10), new Pair(7, 10))));
|
|
21
|
151
|
|
|
|
@@ -40,11 +170,112 @@ public class WordSearcherTest {
|
|
40
|
170
|
assertEquals(expectedLocations, actualLocations);
|
|
41
|
171
|
}
|
|
42
|
172
|
|
|
|
173
|
+ @Ignore("Remove to run test")
|
|
|
174
|
+ @Test
|
|
|
175
|
+ public void testLocatesSameWordWrittenLeftToRightInDifferentTenLineGrid() {
|
|
|
176
|
+ Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
177
|
+ expectedLocations.put("clojure", Optional.of(new WordLocation(new Pair(1, 9), new Pair(7, 9))));
|
|
|
178
|
+
|
|
|
179
|
+ Set<String> searchWords = expectedLocations.keySet();
|
|
|
180
|
+
|
|
|
181
|
+ Map<String, Optional<WordLocation>> actualLocations = wordSearcher.search(
|
|
|
182
|
+ searchWords,
|
|
|
183
|
+ new char[][]{
|
|
|
184
|
+ {'j', 'e', 'f', 'b', 'l', 'p', 'e', 'p', 'r', 'e'},
|
|
|
185
|
+ {'c', 'a', 'm', 'd', 'c', 'i', 'm', 'g', 't', 'c'},
|
|
|
186
|
+ {'o', 'i', 'v', 'o', 'k', 'p', 'r', 'j', 's', 'm'},
|
|
|
187
|
+ {'p', 'b', 'w', 'a', 's', 'q', 'r', 'o', 'u', 'a'},
|
|
|
188
|
+ {'r', 'i', 'x', 'i', 'l', 'e', 'l', 'h', 'r', 's'},
|
|
|
189
|
+ {'w', 'o', 'l', 'c', 'q', 'l', 'i', 'r', 'p', 'c'},
|
|
|
190
|
+ {'s', 'c', 'r', 'e', 'e', 'a', 'u', 'm', 'g', 'r'},
|
|
|
191
|
+ {'a', 'l', 'x', 'h', 'p', 'b', 'u', 'r', 'y', 'i'},
|
|
|
192
|
+ {'c', 'l', 'o', 'j', 'u', 'r', 'e', 'r', 'm', 't'},
|
|
|
193
|
+ {'j', 'a', 'l', 'a', 'y', 'c', 'a', 'l', 'm', 'p'}
|
|
|
194
|
+ }
|
|
|
195
|
+ );
|
|
|
196
|
+
|
|
|
197
|
+ assertEquals(expectedLocations, actualLocations);
|
|
|
198
|
+ }
|
|
|
199
|
+
|
|
|
200
|
+ @Ignore("Remove to run test")
|
|
|
201
|
+ @Test
|
|
|
202
|
+ public void testLocatesDifferentWordWrittenLeftToRightInTenLineGrid() {
|
|
|
203
|
+ Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
204
|
+ expectedLocations.put("fortran", Optional.of(new WordLocation(new Pair(1, 7), new Pair(7, 7))));
|
|
|
205
|
+
|
|
|
206
|
+ Set<String> searchWords = expectedLocations.keySet();
|
|
|
207
|
+
|
|
|
208
|
+ Map<String, Optional<WordLocation>> actualLocations = wordSearcher.search(
|
|
|
209
|
+ searchWords,
|
|
|
210
|
+ new char[][]{
|
|
|
211
|
+ {'j', 'e', 'f', 'b', 'l', 'p', 'e', 'p', 'r', 'e'},
|
|
|
212
|
+ {'c', 'a', 'm', 'd', 'c', 'i', 'm', 'g', 't', 'c'},
|
|
|
213
|
+ {'o', 'i', 'v', 'o', 'k', 'p', 'r', 'j', 's', 'm'},
|
|
|
214
|
+ {'p', 'b', 'w', 'a', 's', 'q', 'r', 'o', 'u', 'a'},
|
|
|
215
|
+ {'r', 'i', 'x', 'i', 'l', 'e', 'l', 'h', 'r', 's'},
|
|
|
216
|
+ {'w', 'o', 'l', 'c', 'q', 'l', 'i', 'r', 'p', 'c'},
|
|
|
217
|
+ {'f', 'o', 'r', 't', 'r', 'a', 'n', 'f', 't', 'w'},
|
|
|
218
|
+ {'a', 'l', 'x', 'h', 'p', 'b', 'u', 'r', 'y', 'i'},
|
|
|
219
|
+ {'c', 'l', 'o', 'j', 'u', 'r', 'e', 'r', 'm', 't'},
|
|
|
220
|
+ {'j', 'a', 'l', 'a', 'y', 'c', 'a', 'l', 'm', 'p'}
|
|
|
221
|
+ }
|
|
|
222
|
+ );
|
|
|
223
|
+
|
|
|
224
|
+ assertEquals(expectedLocations, actualLocations);
|
|
|
225
|
+ }
|
|
|
226
|
+
|
|
|
227
|
+ @Ignore("Remove to run test")
|
|
43
|
228
|
@Test
|
|
44
|
|
- public void testLocatesWordsWrittenRightToLeft() {
|
|
|
229
|
+ public void testShouldLocateMultipleWords() {
|
|
45
|
230
|
Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
231
|
+ expectedLocations.put("fortran", Optional.of(new WordLocation(new Pair(1, 7), new Pair(7, 7))));
|
|
46
|
232
|
expectedLocations.put("clojure", Optional.of(new WordLocation(new Pair(1, 10), new Pair(7, 10))));
|
|
|
233
|
+
|
|
|
234
|
+ Set<String> searchWords = expectedLocations.keySet();
|
|
|
235
|
+
|
|
|
236
|
+ Map<String, Optional<WordLocation>> actualLocations = wordSearcher.search(
|
|
|
237
|
+ searchWords,
|
|
|
238
|
+ new char[][]{
|
|
|
239
|
+ {'j', 'e', 'f', 'b', 'l', 'p', 'e', 'p', 'r', 'e'},
|
|
|
240
|
+ {'c', 'a', 'm', 'd', 'c', 'i', 'm', 'g', 't', 'c'},
|
|
|
241
|
+ {'o', 'i', 'v', 'o', 'k', 'p', 'r', 'j', 's', 'm'},
|
|
|
242
|
+ {'p', 'b', 'w', 'a', 's', 'q', 'r', 'o', 'u', 'a'},
|
|
|
243
|
+ {'r', 'i', 'x', 'i', 'l', 'e', 'l', 'h', 'r', 's'},
|
|
|
244
|
+ {'w', 'o', 'l', 'c', 'q', 'l', 'i', 'r', 'p', 'c'},
|
|
|
245
|
+ {'f', 'o', 'r', 't', 'r', 'a', 'n', 'f', 't', 'w'},
|
|
|
246
|
+ {'a', 'l', 'x', 'h', 'p', 'b', 'u', 'r', 'y', 'i'},
|
|
|
247
|
+ {'j', 'a', 'l', 'a', 'y', 'c', 'a', 'l', 'm', 'p'},
|
|
|
248
|
+ {'c', 'l', 'o', 'j', 'u', 'r', 'e', 'r', 'm', 't'}
|
|
|
249
|
+ }
|
|
|
250
|
+ );
|
|
|
251
|
+
|
|
|
252
|
+ assertEquals(expectedLocations, actualLocations);
|
|
|
253
|
+ }
|
|
|
254
|
+
|
|
|
255
|
+ @Ignore("Remove to run test")
|
|
|
256
|
+ @Test
|
|
|
257
|
+ public void testShouldLocateASingleWordRightToLeft() {
|
|
|
258
|
+ Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
259
|
+ expectedLocations.put("elixir", Optional.of(new WordLocation(new Pair(6, 1), new Pair(1, 1))));
|
|
|
260
|
+
|
|
|
261
|
+ Set<String> searchWords = expectedLocations.keySet();
|
|
|
262
|
+
|
|
|
263
|
+ Map<String, Optional<WordLocation>> actualLocations = wordSearcher.search(
|
|
|
264
|
+ searchWords,
|
|
|
265
|
+ new char[][]{
|
|
|
266
|
+ {'r', 'i', 'x', 'i', 'l', 'e', 'l', 'h', 'r', 's'}
|
|
|
267
|
+ }
|
|
|
268
|
+ );
|
|
|
269
|
+
|
|
|
270
|
+ assertEquals(expectedLocations, actualLocations);
|
|
|
271
|
+ }
|
|
|
272
|
+
|
|
|
273
|
+ @Ignore("Remove to run test")
|
|
|
274
|
+ @Test
|
|
|
275
|
+ public void testShouldLocateMultipleWordsWrittenInDifferentHorizontalDirections() {
|
|
|
276
|
+ Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
47
|
277
|
expectedLocations.put("elixir", Optional.of(new WordLocation(new Pair(6, 5), new Pair(1, 5))));
|
|
|
278
|
+ expectedLocations.put("clojure", Optional.of(new WordLocation(new Pair(1, 10), new Pair(7, 10))));
|
|
48
|
279
|
|
|
49
|
280
|
Set<String> searchWords = expectedLocations.keySet();
|
|
50
|
281
|
|
|
|
@@ -67,6 +298,7 @@ public class WordSearcherTest {
|
|
67
|
298
|
assertEquals(expectedLocations, actualLocations);
|
|
68
|
299
|
}
|
|
69
|
300
|
|
|
|
301
|
+ @Ignore("Remove to run test")
|
|
70
|
302
|
@Test
|
|
71
|
303
|
public void testLocatesWordsWrittenTopToBottom() {
|
|
72
|
304
|
Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
@@ -95,6 +327,7 @@ public class WordSearcherTest {
|
|
95
|
327
|
assertEquals(expectedLocations, actualLocations);
|
|
96
|
328
|
}
|
|
97
|
329
|
|
|
|
330
|
+ @Ignore("Remove to run test")
|
|
98
|
331
|
@Test
|
|
99
|
332
|
public void testLocatesWordsWrittenBottomToTop() {
|
|
100
|
333
|
Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
@@ -122,6 +355,7 @@ public class WordSearcherTest {
|
|
122
|
355
|
assertEquals(expectedLocations, actualLocations);
|
|
123
|
356
|
}
|
|
124
|
357
|
|
|
|
358
|
+ @Ignore("Remove to run test")
|
|
125
|
359
|
@Test
|
|
126
|
360
|
public void testLocatesWordsWrittenTopLeftToBottomRight() {
|
|
127
|
361
|
Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
@@ -150,6 +384,7 @@ public class WordSearcherTest {
|
|
150
|
384
|
assertEquals(expectedLocations, actualLocations);
|
|
151
|
385
|
}
|
|
152
|
386
|
|
|
|
387
|
+ @Ignore("Remove to run test")
|
|
153
|
388
|
@Test
|
|
154
|
389
|
public void testLocatesWordsWrittenBottomRightToTopLeft() {
|
|
155
|
390
|
Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
@@ -179,6 +414,7 @@ public class WordSearcherTest {
|
|
179
|
414
|
assertEquals(expectedLocations, actualLocations);
|
|
180
|
415
|
}
|
|
181
|
416
|
|
|
|
417
|
+ @Ignore("Remove to run test")
|
|
182
|
418
|
@Test
|
|
183
|
419
|
public void testLocatesWordsWrittenBottomLeftToTopRight() {
|
|
184
|
420
|
Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
@@ -209,6 +445,7 @@ public class WordSearcherTest {
|
|
209
|
445
|
assertEquals(expectedLocations, actualLocations);
|
|
210
|
446
|
}
|
|
211
|
447
|
|
|
|
448
|
+ @Ignore("Remove to run test")
|
|
212
|
449
|
@Test
|
|
213
|
450
|
public void testLocatesWordsWrittenTopRightToBottomLeft() {
|
|
214
|
451
|
Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|
|
|
@@ -240,6 +477,7 @@ public class WordSearcherTest {
|
|
240
|
477
|
assertEquals(expectedLocations, actualLocations);
|
|
241
|
478
|
}
|
|
242
|
479
|
|
|
|
480
|
+ @Ignore("Remove to run test")
|
|
243
|
481
|
@Test
|
|
244
|
482
|
public void testFailsToLocateAWordsThatIsNotInThePuzzle() {
|
|
245
|
483
|
Map<String, Optional<WordLocation>> expectedLocations = new HashMap<>();
|