mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-08 02:04:31 +08:00
Cleanup combination and combination test (#5902)
This commit is contained in:
@ -1,17 +1,28 @@
|
||||
package com.thealgorithms.backtracking;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CombinationTest {
|
||||
|
||||
@Test
|
||||
void testNegativeElement() {
|
||||
Integer[] array = {1, 2};
|
||||
assertThrows(IllegalArgumentException.class, () -> { Combination.combination(array, -1); });
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNoElement() {
|
||||
List<TreeSet<Integer>> result = Combination.combination(new Integer[] {1, 2}, 0);
|
||||
assertTrue(result == null);
|
||||
assertNotNull(result);
|
||||
assertEquals(0, result.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -28,4 +39,13 @@ public class CombinationTest {
|
||||
assertTrue(arr[0] == 1);
|
||||
assertTrue(arr[1] == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCombinationsWithStrings() {
|
||||
List<TreeSet<String>> result = Combination.combination(new String[] {"a", "b", "c"}, 2);
|
||||
assertEquals(3, result.size());
|
||||
assertTrue(result.contains(new TreeSet<>(Set.of("a", "b"))));
|
||||
assertTrue(result.contains(new TreeSet<>(Set.of("a", "c"))));
|
||||
assertTrue(result.contains(new TreeSet<>(Set.of("b", "c"))));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user