summaryrefslogtreecommitdiff
path: root/junit/02-maths/src/test/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'junit/02-maths/src/test/java/com')
-rw-r--r--junit/02-maths/src/test/java/com/example/maths/MathsTest.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/junit/02-maths/src/test/java/com/example/maths/MathsTest.java b/junit/02-maths/src/test/java/com/example/maths/MathsTest.java
new file mode 100644
index 0000000..4396901
--- /dev/null
+++ b/junit/02-maths/src/test/java/com/example/maths/MathsTest.java
@@ -0,0 +1,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());
+ }
+} \ No newline at end of file