forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update WordLadderTest.java & WordLadder.java (TheAlgorithms#3674)
- Loading branch information
1 parent
2e25f89
commit a0d03e8
Showing
2 changed files
with
28 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
31 changes: 26 additions & 5 deletions
31
src/test/java/com/thealgorithms/strings/WordLadderTest.java
This file contains 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 |
---|---|---|
@@ -1,17 +1,38 @@ | ||
package com.thealgorithms.strings; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import java.util.*; | ||
|
||
public class WordLadderTest { | ||
|
||
@Test | ||
public void testWordLadder() { | ||
String words1[] = { "hot", "dot", "dog", "lot", "log", "cog" }; | ||
assertEquals(5, WordLadder.ladderLength("hit", "cog", Arrays.asList(words1))); | ||
String words2[] = { "hot", "dot", "dog", "lot", "log" }; | ||
assertEquals(0, WordLadder.ladderLength("hit", "cog", Arrays.asList(words2))); | ||
|
||
/** | ||
* Test 1: | ||
* Input: beginWord = "hit", endWord = "cog", wordList = | ||
* ["hot","dot","dog","lot","log","cog"] | ||
* Output: 5 | ||
* Explanation: One shortest transformation sequence is | ||
* "hit" -> "hot" -> "dot" -> "dog" -> cog" | ||
* which is 5 words long. | ||
*/ | ||
|
||
List<String> wordList1 = Arrays.asList("hot", "dot", "dog", "lot", "log", "cog"); | ||
assertEquals(WordLadder.ladderLength("hit", "cog", wordList1), 5); | ||
|
||
/** | ||
* Test 2: | ||
* Input: beginWord = "hit", endWord = "cog", wordList = | ||
* ["hot","dot","dog","lot","log"] | ||
* Output: 0 | ||
* Explanation: The endWord "cog" is not in wordList, | ||
* therefore there is no valid transformation sequence. | ||
*/ | ||
|
||
List<String> wordList2 = Arrays.asList("hot", "dot", "dog", "lot", "log"); | ||
assertEquals(WordLadder.ladderLength("hit", "cog", wordList2), 0); | ||
|
||
} | ||
} |