Skip to content

Commit e55a411

Browse files
committed
Added to WordLadderTest corner case where wordList is empty
1 parent 90d20b3 commit e55a411

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/test/java/com/thealgorithms/strings/WordLadderTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ public void testWordLadder2() {
4141
assertEquals(WordLadder.ladderLength("hit", "cog", wordList2), 0);
4242
}
4343

44+
/**
45+
* Test 3:
46+
* Input: beginWord = "hit", endWord = "cog", wordList =
47+
* []
48+
* Output: 0
49+
* Explanation: The wordList is empty (corner case),
50+
* therefore there is no valid transformation sequence.
51+
*/
52+
@Test
53+
public void testWordLadder3() {
54+
55+
List<String> wordList3 = Arrays.asList();
56+
assertEquals(WordLadder.ladderLength("hit", "cog", wordList3), 0);
57+
}
58+
4459
@ParameterizedTest
4560
@CsvSource({"'a', 'c', 'b,c', 2", "'a', 'c', 'a', 0", "'a', 'a', 'a', 0", "'ab', 'cd', 'ad,bd,cd', 3", "'a', 'd', 'b,c,d', 2", "'a', 'd', 'b,c,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,d', 2"})
4661
void testLadderLength(String beginWord, String endWord, String wordListStr, int expectedLength) {

0 commit comments

Comments
 (0)