-
Notifications
You must be signed in to change notification settings - Fork 21k
Expand file tree
/
Copy pathFactorialTest.java
More file actions
25 lines (20 loc) · 953 Bytes
/
FactorialTest.java
File metadata and controls
25 lines (20 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.thealgorithms.maths;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.math.BigInteger;
import org.junit.jupiter.api.Test;
public class FactorialTest {
private static final String EXCEPTION_MESSAGE = "Input number cannot be negative";
@Test
public void testWhenInvalidInoutProvidedShouldThrowException() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> Factorial.factorial(-1));
assertEquals(EXCEPTION_MESSAGE, exception.getMessage());
}
@Test
public void testCorrectFactorialCalculation() {
assertEquals(BigInteger.ONE, Factorial.factorial(0));
assertEquals(BigInteger.ONE, Factorial.factorial(1));
assertEquals(BigInteger.valueOf(120), Factorial.factorial(5));
assertEquals(BigInteger.valueOf(3628800), Factorial.factorial(10));
}
}