blob: 4396901976d191c9067aa7f797e6dc6e71657792 (
plain)
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
26
27
28
29
30
31
32
|
package com.example.maths;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class MathsTest {
private Maths maths;
@BeforeEach
void setUp() {
maths = new Maths();
}
@Test
void testFactorial() {
assertEquals(1, maths.factorial(0), "Factorial of 0");
assertEquals(1, maths.factorial(1), "Factorial of 1");
assertEquals(120, maths.factorial(5), "Factorial of 5");
}
@Test
void testDivideByZeroThrowsException() {
ArithmeticException exception = assertThrows(ArithmeticException.class, () -> {
maths.divide(10, 0);
});
assertEquals("/ by zero", exception.getMessage());
}
}
|