Add tests, remove main in WordBoggle (#5782)

This commit is contained in:
Hardik Pawar
2024-10-14 16:57:06 +05:30
committed by GitHub
parent 8d8834987a
commit bcf4034ce5
3 changed files with 57 additions and 31 deletions

View File

@ -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;
@ -32,36 +31,6 @@ public final class WordBoggle {
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;