mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
Add AllConstruct algorithm (#5791)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.thealgorithms.dynamicprogramming;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class AllConstructTest {
|
||||
|
||||
@Test
|
||||
public void testAllConstructBasic() {
|
||||
List<List<String>> expected = Arrays.asList(Arrays.asList("he", "l", "l", "o"));
|
||||
List<List<String>> result = AllConstruct.allConstruct("hello", Arrays.asList("he", "l", "o"));
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllConstructMultipleWays() {
|
||||
List<List<String>> expected = Arrays.asList(Arrays.asList("purp", "le"), Arrays.asList("p", "ur", "p", "le"));
|
||||
List<List<String>> result = AllConstruct.allConstruct("purple", Arrays.asList("purp", "p", "ur", "le", "purpl"));
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllConstructNoWays() {
|
||||
List<List<String>> expected = Arrays.asList();
|
||||
List<List<String>> result = AllConstruct.allConstruct("abcdef", Arrays.asList("gh", "ijk"));
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllConstructEmptyTarget() {
|
||||
List<List<String>> expected = Arrays.asList(Arrays.asList());
|
||||
List<List<String>> result = AllConstruct.allConstruct("", Arrays.asList("a", "b", "c"));
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user