Advertisement
Guest User

Untitled

a guest
May 15th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.00 KB | None | 0 0
  1. import static org.junit.jupiter.api.Assertions.*;
  2.  
  3. class FactorialTest {
  4.  
  5.     @org.junit.jupiter.api.Test
  6.     void factorial() {
  7.         assertThrows(
  8.                 ArithmeticException.class,
  9.                 () -> Factorial.factorial(-3),
  10.                 "Cannot compute factorial of negative number."
  11.         );
  12.         assertThrows(
  13.                 ArithmeticException.class,
  14.                 () -> Factorial.factorial(-2),
  15.                 "Cannot compute factorial of negative number."
  16.         );
  17.         assertThrows(
  18.                 ArithmeticException.class,
  19.                 () -> Factorial.factorial(-1),
  20.                 "Cannot compute factorial of negative number."
  21.         );
  22.         assertEquals(1, Factorial.factorial(0));
  23.         assertEquals(1, Factorial.factorial(1));
  24.         assertEquals(2, Factorial.factorial(2));
  25.         assertEquals(6, Factorial.factorial(3));
  26.         assertEquals(24, Factorial.factorial(4));
  27.         assertEquals(120, Factorial.factorial(5));
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement