Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static org.junit.jupiter.api.Assertions.*;
- class FactorialTest {
- @org.junit.jupiter.api.Test
- void factorial() {
- assertThrows(
- ArithmeticException.class,
- () -> Factorial.factorial(-3),
- "Cannot compute factorial of negative number."
- );
- assertThrows(
- ArithmeticException.class,
- () -> Factorial.factorial(-2),
- "Cannot compute factorial of negative number."
- );
- assertThrows(
- ArithmeticException.class,
- () -> Factorial.factorial(-1),
- "Cannot compute factorial of negative number."
- );
- assertEquals(1, Factorial.factorial(0));
- assertEquals(1, Factorial.factorial(1));
- assertEquals(2, Factorial.factorial(2));
- assertEquals(6, Factorial.factorial(3));
- assertEquals(24, Factorial.factorial(4));
- assertEquals(120, Factorial.factorial(5));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement