Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@
* [MirrorOfMatrixTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/misc/MirrorOfMatrixTest.java)
* [PalindromeSinglyLinkedListTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/misc/PalindromeSinglyLinkedListTest.java)
* [TwoSumProblemTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/misc/TwoSumProblemTest.java)
* [WordBoggleTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/misc/WordBoggleTest.java)
* others
* [ArrayLeftRotationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ArrayLeftRotationTest.java)
* [ArrayRightRotationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ArrayRightRotationTest.java)
Expand Down
31 changes: 0 additions & 31 deletions src/main/java/com/thealgorithms/misc/WordBoggle.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.thealgorithms.misc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -32,36 +31,6 @@ public static List<String> boggleBoard(char[][] board, String[] words) {
return new ArrayList<>(finalWords);
}

public static void main(String[] args) {
// Testcase
List<String> ans = new ArrayList<>(Arrays.asList("a", "boggle", "this", "NOTRE_PEATED", "is", "simple", "board"));
assert (boggleBoard(
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'},
},
new String[] {
"this",
"is",
"not",
"a",
"simple",
"test",
"boggle",
"board",
"REPEATED",
"NOTRE_PEATED",
})
.equals(ans));
}

public static void explore(int i, int j, char[][] board, TrieNode trieNode, boolean[][] visited, Set<String> finalWords) {
if (visited[i][j]) {
return;
Expand Down
83 changes: 83 additions & 0 deletions src/test/java/com/thealgorithms/misc/WordBoggleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.thealgorithms.misc;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class WordBoggleTest {

private char[][] board;
private String[] words;

@BeforeEach
public 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'},
};

words = new String[] {"this", "is", "not", "a", "simple", "test", "boggle", "board", "REPEATED", "NOTRE_PEATED"};
}

@Test
public void testBoggleBoardFindsAllWords() {
List<String> expected = Arrays.asList("this", "is", "a", "simple", "board", "boggle", "NOTRE_PEATED");
List<String> result = WordBoggle.boggleBoard(board, words);
assertEquals(expected.size(), result.size());
assertTrue(expected.containsAll(result));
}

@Test
public void testBoggleBoardNoMatchingWords() {
// Test with words that don't exist on the board
String[] nonMatchingWords = {"xyz", "hello", "world"};
List<String> result = WordBoggle.boggleBoard(board, nonMatchingWords);
assertEquals(0, result.size());
}

@Test
public void testBoggleBoardEmptyBoard() {
// Test with an empty board
char[][] emptyBoard = new char[0][0];
List<String> result = WordBoggle.boggleBoard(emptyBoard, words);
assertEquals(0, result.size());
}

@Test
public void testBoggleBoardEmptyWordsArray() {
// Test with an empty words array
String[] emptyWords = {};
List<String> result = WordBoggle.boggleBoard(board, emptyWords);
assertEquals(0, result.size());
}

@Test
public void testBoggleBoardSingleCharacterWords() {
// Test with single-character words
String[] singleCharWords = {"a", "x", "o"};
List<String> expected = Arrays.asList("a", "o");
List<String> result = WordBoggle.boggleBoard(board, singleCharWords);
assertEquals(expected.size() + 1, result.size());
}

@Test
public void testBoggleBoardDuplicateWordsInInput() {
// Test with duplicate words in the input array
String[] duplicateWords = {"this", "this", "board", "board"};
List<String> expected = Arrays.asList("this", "board");
List<String> result = WordBoggle.boggleBoard(board, duplicateWords);
assertEquals(expected.size(), result.size());
assertTrue(expected.containsAll(result));
}
}