Skip to content

Commit c1368b4

Browse files
Fixed Formatting issues
1 parent d9e43ba commit c1368b4

2 files changed

Lines changed: 18 additions & 23 deletions

File tree

src/main/java/com/thealgorithms/recursion/Permutations.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package com.thealgorithms.recursion;
22

3-
import java.util.ArrayList;
4-
import java.util.Arrays;
5-
import java.util.HashSet;
6-
import java.util.List;
7-
import java.util.Set;
3+
import java.util.*;
84

95
/**
106
* This class provides methods to generate all permutations
117
* of a given array of any type using recursion.
12-
*
8+
* <p>
139
* Reference:
1410
* https://en.wikipedia.org/wiki/Permutation
1511
*/

src/test/java/com/thealgorithms/recursion/Permutations.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.thealgorithms.recursion;
22

3-
import static org.junit.jupiter.api.Assertions.assertEquals;
4-
import static org.junit.jupiter.api.Assertions.assertThrows;
5-
import static org.junit.jupiter.api.Assertions.assertTrue;
3+
import org.junit.jupiter.api.Test;
64

75
import java.util.List;
8-
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
98

109
class PermutationsTest {
1110

@@ -20,7 +19,7 @@ void testNullArrayThrowsNullPointerException() {
2019

2120
@Test
2221
void testArrayWithNullElementThrowsIllegalArgumentException() {
23-
Integer[] items = { 1, null, 3 };
22+
Integer[] items = {1, null, 3};
2423
assertThrows(IllegalArgumentException.class, () -> Permutations.permutations(items));
2524
}
2625

@@ -38,7 +37,7 @@ void testEmptyArrayReturnsOneEmptyPermutation() {
3837

3938
@Test
4039
void testSingleElementReturnsOnePermutation() {
41-
Integer[] items = { 42 };
40+
Integer[] items = {42};
4241
List<List<Integer>> result = Permutations.permutations(items);
4342
assertEquals(1, result.size());
4443
assertEquals(List.of(42), result.get(0));
@@ -50,7 +49,7 @@ void testSingleElementReturnsOnePermutation() {
5049

5150
@Test
5251
void testTwoIntegersReturnsTwoPermutations() {
53-
Integer[] items = { 1, 2 };
52+
Integer[] items = {1, 2};
5453
List<List<Integer>> result = Permutations.permutations(items);
5554
assertEquals(2, result.size());
5655
assertTrue(result.contains(List.of(1, 2)));
@@ -59,14 +58,14 @@ void testTwoIntegersReturnsTwoPermutations() {
5958

6059
@Test
6160
void testThreeIntegersReturnsSixPermutations() {
62-
Integer[] items = { 1, 2, 3 };
61+
Integer[] items = {1, 2, 3};
6362
List<List<Integer>> result = Permutations.permutations(items);
6463
assertEquals(6, result.size());
6564
}
6665

6766
@Test
6867
void testIntegerPermutationsContainAllExpectedOrders() {
69-
Integer[] items = { 1, 2, 3 };
68+
Integer[] items = {1, 2, 3};
7069
List<List<Integer>> result = Permutations.permutations(items);
7170
assertTrue(result.contains(List.of(1, 2, 3)));
7271
assertTrue(result.contains(List.of(1, 3, 2)));
@@ -82,15 +81,15 @@ void testIntegerPermutationsContainAllExpectedOrders() {
8281

8382
@Test
8483
void testTwoDuplicateIntegersReturnsOnePermutation() {
85-
Integer[] items = { 1, 1 };
84+
Integer[] items = {1, 1};
8685
List<List<Integer>> result = Permutations.permutations(items);
8786
assertEquals(1, result.size());
8887
assertEquals(List.of(1, 1), result.get(0));
8988
}
9089

9190
@Test
9291
void testArrayWithDuplicatesReturnsCorrectCount() {
93-
Integer[] items = { 1, 1, 2 };
92+
Integer[] items = {1, 1, 2};
9493
List<List<Integer>> result = Permutations.permutations(items);
9594
// 3!/2! = 3 unique permutations
9695
assertEquals(3, result.size());
@@ -101,7 +100,7 @@ void testArrayWithDuplicatesReturnsCorrectCount() {
101100

102101
@Test
103102
void testAllDuplicatesReturnsOnePermutation() {
104-
Integer[] items = { 5, 5, 5 };
103+
Integer[] items = {5, 5, 5};
105104
List<List<Integer>> result = Permutations.permutations(items);
106105
assertEquals(1, result.size());
107106
assertEquals(List.of(5, 5, 5), result.get(0));
@@ -113,7 +112,7 @@ void testAllDuplicatesReturnsOnePermutation() {
113112

114113
@Test
115114
void testTwoStringsReturnsTwoPermutations() {
116-
String[] items = { "a", "b" };
115+
String[] items = {"a", "b"};
117116
List<List<String>> result = Permutations.permutations(items);
118117
assertEquals(2, result.size());
119118
assertTrue(result.contains(List.of("a", "b")));
@@ -122,14 +121,14 @@ void testTwoStringsReturnsTwoPermutations() {
122121

123122
@Test
124123
void testThreeStringsReturnsSixPermutations() {
125-
String[] items = { "x", "y", "z" };
124+
String[] items = {"x", "y", "z"};
126125
List<List<String>> result = Permutations.permutations(items);
127126
assertEquals(6, result.size());
128127
}
129128

130129
@Test
131130
void testDuplicateStringsReturnsCorrectCount() {
132-
String[] items = { "a", "a", "b" };
131+
String[] items = {"a", "a", "b"};
133132
List<List<String>> result = Permutations.permutations(items);
134133
assertEquals(3, result.size());
135134
assertTrue(result.contains(List.of("a", "a", "b")));
@@ -143,14 +142,14 @@ void testDuplicateStringsReturnsCorrectCount() {
143142

144143
@Test
145144
void testCharacterPermutations() {
146-
Character[] items = { 'a', 'b', 'c' };
145+
Character[] items = {'a', 'b', 'c'};
147146
List<List<Character>> result = Permutations.permutations(items);
148147
assertEquals(6, result.size());
149148
}
150149

151150
@Test
152151
void testDuplicateCharactersReturnsCorrectCount() {
153-
Character[] items = { 'a', 'a', 'b' };
152+
Character[] items = {'a', 'a', 'b'};
154153
List<List<Character>> result = Permutations.permutations(items);
155154
assertEquals(3, result.size());
156155
}

0 commit comments

Comments
 (0)