|
| 1 | +package com.thealgorithms.backtracking; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertIterableEquals; |
| 4 | + |
| 5 | +import java.util.ArrayList; |
| 6 | +import java.util.List; |
| 7 | +import java.util.stream.Stream; |
| 8 | +import org.junit.jupiter.params.ParameterizedTest; |
| 9 | +import org.junit.jupiter.params.provider.MethodSource; |
| 10 | + |
| 11 | +public class SubsequenceFinderTest { |
| 12 | + |
| 13 | + @ParameterizedTest |
| 14 | + @MethodSource("getTestCases") |
| 15 | + void testGenerateAll(TestCase testData) { |
| 16 | + final var actual = SubsequenceFinder.generateAll(testData.input()); |
| 17 | + assertIterableEquals(testData.expected(), actual); |
| 18 | + } |
| 19 | + |
| 20 | + static Stream<TestCase> getTestCases() { |
| 21 | + return Stream.of(new TestCase(new ArrayList<>(), List.of(List.of())), new TestCase(List.of(1, 2), List.of(List.of(), List.of(2), List.of(1), List.of(1, 2))), |
| 22 | + new TestCase(List.of("A", "B", "C"), List.of(List.of(), List.of("C"), List.of("B"), List.of("B", "C"), List.of("A"), List.of("A", "C"), List.of("A", "B"), List.of("A", "B", "C"))), |
| 23 | + new TestCase(List.of(1, 2, 3), List.of(List.of(), List.of(3), List.of(2), List.of(2, 3), List.of(1), List.of(1, 3), List.of(1, 2), List.of(1, 2, 3))), |
| 24 | + new TestCase(List.of(2, 2), List.of(List.of(), List.of(2), List.of(2), List.of(2, 2)))); |
| 25 | + } |
| 26 | + |
| 27 | + record TestCase(List<Object> input, List<List<Object>> expected) { |
| 28 | + } |
| 29 | +} |
0 commit comments