Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21.3k
Expand file tree
/
Copy pathFactorialTest.java
More file actions
Latest commit
25 lines (20 loc) · 953 Bytes
/
Copy pathFactorialTest.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
packagecom.thealgorithms.maths;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importstaticorg.junit.jupiter.api.Assertions.assertThrows;
importjava.math.BigInteger;
importorg.junit.jupiter.api.Test;
publicclassFactorialTest {
privatestaticfinalStringEXCEPTION_MESSAGE = "Input number cannot be negative";
@Test
publicvoidtestWhenInvalidInoutProvidedShouldThrowException() {
IllegalArgumentExceptionexception = assertThrows(IllegalArgumentException.class, () -> Factorial.factorial(-1));
assertEquals(EXCEPTION_MESSAGE, exception.getMessage());
}
@Test
publicvoidtestCorrectFactorialCalculation() {
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));
}
}