backtracking: add unique permutation algorithm with test cases (#7078)

* Add unique permutation algorithm and test cases

* Fix: add braces for checkstyle

* Apply clang-format
This commit is contained in:
shreeya-g10
2025-11-19 21:50:46 +05:30
committed by GitHub
parent 1c97ad8015
commit 3519e396af
2 changed files with 93 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
package com.thealgorithms.backtracking;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
public class UniquePermutationTest {
@Test
void testUniquePermutationsAab() {
List<String> expected = Arrays.asList("AAB", "ABA", "BAA");
List<String> result = UniquePermutation.generateUniquePermutations("AAB");
assertEquals(expected, result);
}
@Test
void testUniquePermutationsAbc() {
List<String> expected = Arrays.asList("ABC", "ACB", "BAC", "BCA", "CAB", "CBA");
List<String> result = UniquePermutation.generateUniquePermutations("ABC");
assertEquals(expected, result);
}
@Test
void testEmptyString() {
List<String> expected = Arrays.asList("");
List<String> result = UniquePermutation.generateUniquePermutations("");
assertEquals(expected, result);
}
}