-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathWordBoggleTest.java
57 lines (49 loc) · 2.66 KB
/
WordBoggleTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.thealgorithms.puzzlesandgames;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class WordBoggleTest {
private char[][] board;
@BeforeEach
void setup() {
board = new char[][] {
{'t', 'h', 'i', 's', 'i', 's', 'a'},
{'s', 'i', 'm', 'p', 'l', 'e', 'x'},
{'b', 'x', 'x', 'x', 'x', 'e', 'b'},
{'x', 'o', 'g', 'g', 'l', 'x', 'o'},
{'x', 'x', 'x', 'D', 'T', 'r', 'a'},
{'R', 'E', 'P', 'E', 'A', 'd', 'x'},
{'x', 'x', 'x', 'x', 'x', 'x', 'x'},
{'N', 'O', 'T', 'R', 'E', '_', 'P'},
{'x', 'x', 'D', 'E', 'T', 'A', 'E'},
};
}
@ParameterizedTest
@MethodSource("provideTestCases")
void testBoggleBoard(String[] words, List<String> expectedWords, String testDescription) {
List<String> result = WordBoggle.boggleBoard(board, words);
assertEquals(expectedWords.size(), result.size(), "Test failed for: " + testDescription);
assertTrue(expectedWords.containsAll(result), "Test failed for: " + testDescription);
}
private static Stream<Arguments> provideTestCases() {
return Stream.of(Arguments.of(new String[] {"this", "is", "not", "a", "simple", "test", "boggle", "board", "REPEATED", "NOTRE_PEATED"}, Arrays.asList("this", "is", "a", "simple", "board", "boggle", "NOTRE_PEATED"), "All words"),
Arguments.of(new String[] {"xyz", "hello", "world"}, List.of(), "No matching words"), Arguments.of(new String[] {}, List.of(), "Empty words array"), Arguments.of(new String[] {"this", "this", "board", "board"}, Arrays.asList("this", "board"), "Duplicate words in input"));
}
@ParameterizedTest
@MethodSource("provideSpecialCases")
void testBoggleBoardSpecialCases(char[][] specialBoard, String[] words, Collection<String> expectedWords, String testDescription) {
List<String> result = WordBoggle.boggleBoard(specialBoard, words);
assertEquals(expectedWords.size(), result.size(), "Test failed for: " + testDescription);
assertTrue(expectedWords.containsAll(result), "Test failed for: " + testDescription);
}
private static Stream<Arguments> provideSpecialCases() {
return Stream.of(Arguments.of(new char[0][0], new String[] {"this", "is", "a", "test"}, List.of(), "Empty board"));
}
}