/
WordLadderTest.java
39 lines (31 loc) · 1.19 KB
/
WordLadderTest.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
package com.thealgorithms.strings;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
public class WordLadderTest {
@Test
public void testWordLadder() {
/**
* 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);
}
}