-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Add tests, remove main
in WordBoggle
#5782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f710b20
Add tests, remove `main` in `WordBoggle`
Hardvan 1b2112a
Update directory
Hardvan a99b4db
Fix
Hardvan 0b6fb5b
Merge remote-tracking branch 'origin/wordboggle_add_tests' into wordb…
Hardvan 7a31147
Fix
Hardvan 19b2352
Fix
Hardvan 35d03b8
Merge branch 'master' into wordboggle_add_tests
alxkm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.