|
|
@@ -0,0 +1,47 @@
|
|
|
+package nl.quintor.hdboer.aegoncalc.services;
|
|
|
+
|
|
|
+import org.junit.jupiter.api.Assertions;
|
|
|
+import org.junit.jupiter.api.DisplayName;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+class SimpleCalculatorTest {
|
|
|
+
|
|
|
+ private final SimpleCalculator calculator = new SimpleCalculator();
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @DisplayName("add: test integers do not over- or underflow")
|
|
|
+ void add() {
|
|
|
+ Assertions.assertAll(
|
|
|
+ () -> Assertions.assertEquals(calculator.add(1, Integer.MAX_VALUE), 2147483648.0),
|
|
|
+ () -> Assertions.assertEquals(calculator.add(-1, Integer.MIN_VALUE), -2147483649.0)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @DisplayName("subtract: test integers do not over- or underflow")
|
|
|
+ void subtract() {
|
|
|
+ Assertions.assertAll(
|
|
|
+ () -> Assertions.assertEquals(calculator.subtract(-1, Integer.MAX_VALUE), -2147483648.0),
|
|
|
+ () -> Assertions.assertEquals(calculator.subtract(1, Integer.MIN_VALUE), 2147483649.0)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @DisplayName("multiply: test integers do not overflow")
|
|
|
+ void multiply() {
|
|
|
+ Assertions.assertEquals(calculator.multiply(2, Integer.MAX_VALUE), 4294967294.0);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @DisplayName("divide: test non-integer fraction is retained when dividing")
|
|
|
+ void divide() {
|
|
|
+ Assertions.assertEquals(calculator.divide(10, 8), 1.25);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @DisplayName("divide: test division by 0 is handled")
|
|
|
+ void divideByZero() {
|
|
|
+ Assertions.assertThrows(IllegalArgumentException.class, () -> calculator.divide(1, 0));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|