Skip to content

Commit aa8be9f

Browse files
committed
factorail test
1 parent 1c69e7f commit aa8be9f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
6+
import org.junit.jupiter.api.Test;
7+
8+
public class FactorialTest {
9+
10+
@Test
11+
public void testFactorialOfZero() {
12+
assertEquals(1, Factorial.factorial(0));
13+
}
14+
15+
@Test
16+
public void testFactorialOfOne() {
17+
assertEquals(1, Factorial.factorial(1));
18+
}
19+
20+
@Test
21+
public void testFactorialOfPositiveNumbers() {
22+
assertEquals(120, Factorial.factorial(5));
23+
assertEquals(720, Factorial.factorial(6));
24+
assertEquals(5040, Factorial.factorial(7));
25+
}
26+
27+
@Test
28+
public void testFactorialOfTen() {
29+
assertEquals(3628800, Factorial.factorial(10));
30+
}
31+
32+
@Test
33+
public void testNegativeNumberThrowsException() {
34+
assertThrows(IllegalArgumentException.class, () -> Factorial.factorial(-1));
35+
}
36+
}

0 commit comments

Comments
 (0)