Skip to content

Commit f029c33

Browse files
committed
Fix formatting issues for clang-format compliance
1 parent e4ea563 commit f029c33

File tree

2 files changed

+34
-53
lines changed

2 files changed

+34
-53
lines changed
Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,23 @@
1-
package com.thealgorithms.recursion;
2-
3-
/*
4-
The Factorial of a non-negative integer n is the product of all positive integers less than or
5-
equal to n. It is defined as: n! = n × (n - 1) × (n - 2) × ... × 1 with the base case: 0! = 1
6-
7-
Example:
8-
5! = 5 × 4 × 3 × 2 × 1 = 120
9-
*/
10-
111
public final class Factorial {
12-
private Factorial() {
13-
throw new UnsupportedOperationException("Utility class");
14-
}
15-
16-
/**
17-
* Computes the factorial of a non-negative integer using recursion.
18-
*
19-
* @param n the number for which factorial is to be calculated
20-
* @return factorial of n
21-
* @throws IllegalArgumentException if n is negative
22-
*/
23-
24-
public static long factorial(int n) {
25-
if (n < 0) {
26-
throw new IllegalArgumentException("Factorial is not defined for negative numbers.");
2+
private Factorial() {
3+
throw new UnsupportedOperationException("Utility class");
274
}
285

29-
if (n == 0 || n == 1) {
30-
return 1;
6+
/**
7+
* Computes the factorial of a non-negative integer using recursion.
8+
*
9+
* @param n the number for which factorial is to be calculated
10+
* @return factorial of n
11+
* @throws IllegalArgumentException if n is negative
12+
*/
13+
public static long factorial(int n) {
14+
if (n < 0) {
15+
throw new IllegalArgumentException("Factorial is not defined for negative numbers.");
16+
}
17+
18+
if (n == 0 || n == 1) {
19+
return 1;
20+
}
21+
return n * factorial(n - 1);
3122
}
32-
return n * factorial(n - 1);
33-
}
3423
}
Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
1-
package com.thealgorithms.recursion;
2-
3-
import static org.junit.jupiter.api.Assertions.assertEquals;
4-
import static org.junit.jupiter.api.Assertions.assertThrows;
5-
1+
import static org.junit.jupiter.api.Assertions.*;
62
import org.junit.jupiter.api.Test;
73

84
public class FactorialTest {
9-
@Test
10-
public void testFactorialOfZero() {
11-
assertEquals(1, Factorial.factorial(0));
12-
}
135

146
@Test
157
public void testFactorialOfOne() {
168
assertEquals(1, Factorial.factorial(1));
17-
}
9+
}
1810

19-
@Test
20-
public void testFactorialOfPositiveNumbers() {
21-
assertEquals(120, Factorial.factorial(5));
22-
assertEquals(720, Factorial.factorial(6));
23-
assertEquals(5040, Factorial.factorial(7));
24-
}
11+
@Test
12+
public void testFactorialOfPositiveNumbers() {
13+
assertEquals(120, Factorial.factorial(5));
14+
assertEquals(720, Factorial.factorial(6));
15+
assertEquals(5040, Factorial.factorial(7));
16+
}
2517

26-
@Test
27-
public void testFactorialOfTen() {
28-
assertEquals(3628800, Factorial.factorial(10));
29-
}
18+
@Test
19+
public void testFactorialOfTen() {
20+
assertEquals(3628800, Factorial.factorial(10));
21+
}
3022

31-
@Test
32-
public void testNegativeNumberThrowsException() {
33-
assertThrows(IllegalArgumentException.class, () -> Factorial.factorial(-1));
34-
}
23+
@Test
24+
public void testNegativeNumberThrowsException() {
25+
assertThrows(IllegalArgumentException.class, () -> Factorial.factorial(-1));
26+
}
3527
}

0 commit comments

Comments
 (0)