mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 06:23:08 +08:00
refactor: WordLadder
(#5434)
* refactor: WordLadder * refactor: fix redundant check --------- Co-authored-by: alxkm <alx@alx.com>
This commit is contained in:
@ -5,6 +5,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
public class WordLadderTest {
|
||||
|
||||
@ -38,4 +40,12 @@ public class WordLadderTest {
|
||||
List<String> wordList2 = Arrays.asList("hot", "dot", "dog", "lot", "log");
|
||||
assertEquals(WordLadder.ladderLength("hit", "cog", wordList2), 0);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@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"})
|
||||
void testLadderLength(String beginWord, String endWord, String wordListStr, int expectedLength) {
|
||||
List<String> wordList = List.of(wordListStr.split(","));
|
||||
int result = WordLadder.ladderLength(beginWord, endWord, wordList);
|
||||
assertEquals(expectedLength, result);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user