forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFactorialTest.java
More file actions
24 lines (19 loc) · 858 Bytes
/
FactorialTest.java
File metadata and controls
24 lines (19 loc) · 858 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
package com.thealgorithms.maths;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
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.getMessage(), EXCEPTION_MESSAGE);
}
@Test
public void testCorrectFactorialCalculation() {
assertEquals(1, Factorial.factorial(0));
assertEquals(1, Factorial.factorial(1));
assertEquals(120, Factorial.factorial(5));
assertEquals(3628800, Factorial.factorial(10));
}
}