From d4634a026318ccd103750f7dbda37a43953cc1c2 Mon Sep 17 00:00:00 2001 From: Vitalii Mykh Date: Tue, 14 Sep 2021 00:01:56 +0300 Subject: [PATCH 1/4] full test coverage --- pom.xml | 9 +- src/main/java/core/basesyntax/Calculator.java | 26 + src/main/java/core/basesyntax/HelloWorld.java | 8 - .../basesyntax/IllegalOperatorException.java | 7 + .../basesyntax/IllegalValueException.java | 7 + .../java/core/basesyntax/CalculatorTest.java | 629 ++++++++++++++++++ .../java/core/basesyntax/HelloWorldTest.java | 8 - 7 files changed, 671 insertions(+), 23 deletions(-) create mode 100644 src/main/java/core/basesyntax/Calculator.java delete mode 100644 src/main/java/core/basesyntax/HelloWorld.java create mode 100644 src/main/java/core/basesyntax/IllegalOperatorException.java create mode 100644 src/main/java/core/basesyntax/IllegalValueException.java create mode 100644 src/test/java/core/basesyntax/CalculatorTest.java delete mode 100644 src/test/java/core/basesyntax/HelloWorldTest.java diff --git a/pom.xml b/pom.xml index edd71909..606f826c 100644 --- a/pom.xml +++ b/pom.xml @@ -22,15 +22,10 @@ org.junit.jupiter junit-jupiter-api - ${junit-jupiter.version} - test - - - org.junit.jupiter - junit-jupiter-engine - ${junit-jupiter.version} + 5.8.0-RC1 test + diff --git a/src/main/java/core/basesyntax/Calculator.java b/src/main/java/core/basesyntax/Calculator.java new file mode 100644 index 00000000..31c17059 --- /dev/null +++ b/src/main/java/core/basesyntax/Calculator.java @@ -0,0 +1,26 @@ +package core.basesyntax; + +public class Calculator { + public double calculate(double firstValue, double secondValue, char operation) { + switch (operation) { + case '+': + return firstValue + secondValue; + case '-': + return firstValue - secondValue; + case '*': + return firstValue * secondValue; + case '/': + if (secondValue == 0) { + throw new ArithmeticException("can`t divide on 0"); + } + return firstValue / secondValue; + case '^': + if (secondValue == Double.MIN_VALUE) { + throw new IllegalValueException("can`t resolve operation"); + } + return Math.pow(firstValue, secondValue); + default: + throw new IllegalOperatorException("can't recognise operator, try again"); + } + } +} diff --git a/src/main/java/core/basesyntax/HelloWorld.java b/src/main/java/core/basesyntax/HelloWorld.java deleted file mode 100644 index 97db782b..00000000 --- a/src/main/java/core/basesyntax/HelloWorld.java +++ /dev/null @@ -1,8 +0,0 @@ -package core.basesyntax; - -/** - * Feel free to remove this class and create your own. - */ -public class HelloWorld { - -} diff --git a/src/main/java/core/basesyntax/IllegalOperatorException.java b/src/main/java/core/basesyntax/IllegalOperatorException.java new file mode 100644 index 00000000..3f90d590 --- /dev/null +++ b/src/main/java/core/basesyntax/IllegalOperatorException.java @@ -0,0 +1,7 @@ +package core.basesyntax; + +public class IllegalOperatorException extends RuntimeException { + public IllegalOperatorException(String message) { + super(message); + } +} diff --git a/src/main/java/core/basesyntax/IllegalValueException.java b/src/main/java/core/basesyntax/IllegalValueException.java new file mode 100644 index 00000000..30e87b34 --- /dev/null +++ b/src/main/java/core/basesyntax/IllegalValueException.java @@ -0,0 +1,7 @@ +package core.basesyntax; + +public class IllegalValueException extends RuntimeException { + public IllegalValueException(String message) { + super(message); + } +} diff --git a/src/test/java/core/basesyntax/CalculatorTest.java b/src/test/java/core/basesyntax/CalculatorTest.java new file mode 100644 index 00000000..67ef39fc --- /dev/null +++ b/src/test/java/core/basesyntax/CalculatorTest.java @@ -0,0 +1,629 @@ +package core.basesyntax; + +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; + +class CalculatorTest { + private static Calculator calculator; + private static final double DELTA = 0.0001; + + @BeforeEach + void setUp() { + calculator = new Calculator(); + } + + @Test + void checkOperatorNotOk() { + double firstValue = 1; + double secondValue = 4; + assertThrows(IllegalOperatorException.class, () -> { + calculator.calculate(firstValue, secondValue, '&'); + }); + } + + @Test + void addTwoPositiveOk() { + double firstValue = 5; + double secondValue = 1; + double actual = calculator.calculate(firstValue, secondValue, '+'); + double expected = 6; + assertEquals(expected, actual); + } + + @Test + void addTwoNegativeOk() { + double firstValue = -5; + double secondValue = -1; + double actual = calculator.calculate(firstValue, secondValue, '+'); + double expected = -6; + assertEquals(expected, actual); + } + + @Test + void addFirstNegativeSecondPositiveOk() { + double firstValue = -1; + double secondValue = 1; + double actual = calculator.calculate(firstValue, secondValue, '+'); + double expected = 0; + assertEquals(expected, actual); + } + + @Test + void addFirstPositiveSecondBegativeOk() { + double firstValue = 1; + double secondValue = -4; + double actual = calculator.calculate(firstValue, secondValue, '+'); + double expected = -3; + assertEquals(expected, actual); + } + + @Test + void addTwoZeroOk() { + double firstValue = 0; + double secondValue = 0; + double actual = calculator.calculate(firstValue, secondValue, '+'); + double expected = 0; + assertEquals(expected, actual); + } + + @Test + void addFirstZeroOk() { + double firstValue = 0; + double secondValue = 3; + double actual = calculator.calculate(firstValue, secondValue, '+'); + double expected = 3; + assertEquals(expected, actual); + } + + @Test + void addSecondZeroOk() { + double firstValue = -4; + double secondValue = 0; + double actual = calculator.calculate(firstValue, secondValue, '+'); + double expected = -4; + assertEquals(expected, actual); + } + + @Test + void addFirstPositiveSecondMinOk() { + double firstValue = 1; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '+'); + double expected = 1; + assertEquals(expected, actual, DELTA); + } + + @Test + void addFirstNegativeSecondMinOk() { + double firstValue = -1; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '+'); + double expected = -1; + assertEquals(expected, actual, DELTA); + } + + @Test + void addFirstPositiveSecondMaxOk() { + double firstValue = 1; + double secondValue = Double.MAX_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '+'); + double expected = Double.MAX_VALUE; + assertEquals(expected, actual); + } + + @Test + void addFirstZeroSecondMaxOk() { + double firstValue = 0; + double secondValue = Double.MAX_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '+'); + double expected = Double.MAX_VALUE; + assertEquals(expected, actual); + } + + @Test + void addFirstMaxSecondMinOk() { + double firstValue = Double.MAX_VALUE; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '+'); + double expected = Double.MAX_VALUE; + assertEquals(expected, actual, DELTA); + } + + @Test + void addTwoMaxOk() { + double firstValue = Double.MAX_VALUE; + double secondValue = Double.MAX_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '+'); + double expected = Double.POSITIVE_INFINITY; + assertEquals(expected, actual); + } + + @Test + void addTwoMinOk() { + double firstValue = Double.MIN_VALUE; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue,secondValue, '+'); + double expected = 0; + assertEquals(expected, actual, DELTA); + } + + @Test + void subTwoPositiveOk() { + double firstValue = 5; + double secondValue = 1; + double actual = calculator.calculate(firstValue, secondValue, '-'); + double expected = 4; + assertEquals(expected, actual); + } + + @Test + void subTwoNegativeOk() { + double firstValue = -5; + double secondValue = -1; + double actual = calculator.calculate(firstValue, secondValue, '-'); + double expected = -4; + assertEquals(expected, actual); + } + + @Test + void subFirstNegativeSecondPositiveOk() { + double firstValue = -1; + double secondValue = 1; + double actual = calculator.calculate(firstValue, secondValue, '-'); + double expected = -2; + assertEquals(expected, actual); + } + + @Test + void subFirstPositiveSecondNegativeOk() { + double firstValue = 1; + double secondValue = -4; + double actual = calculator.calculate(firstValue, secondValue, '-'); + double expected = 5; + assertEquals(expected, actual); + } + + @Test + void subTwoZeroOk() { + double firstValue = 0; + double secondValue = 0; + double actual = calculator.calculate(firstValue, secondValue, '-'); + double expected = 0; + assertEquals(expected, actual); + } + + @Test + void subFirstZeroOk() { + double firstValue = 0; + double secondValue = 3; + double actual = calculator.calculate(firstValue, secondValue, '-'); + double expected = -3; + assertEquals(expected, actual); + } + + @Test + void subSecondZeroOk() { + double firstValue = -4; + double secondValue = 0; + double actual = calculator.calculate(firstValue, secondValue, '-'); + double expected = -4; + assertEquals(expected, actual); + } + + @Test + void subFirstPositiveSecondMinOk() { + double firstValue = 1; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '-'); + double expected = 1; + assertEquals(expected, actual, DELTA); + } + + @Test + void subFirstNegativeSecondMinOk() { + double firstValue = -1; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '-'); + double expected = -1; + assertEquals(expected, actual, DELTA); + } + + @Test + void subFirstPositiveSecondMaxOk() { + double firstValue = 1; + double secondValue = Double.MAX_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '-'); + double expected = -Double.MAX_VALUE; + assertEquals(expected, actual, DELTA); + } + + @Test + void subFirstZeroSecondMaxOk() { + double firstValue = 0; + double secondValue = Double.MAX_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '-'); + double expected = -Double.MAX_VALUE; + assertEquals(expected, actual, DELTA); + } + + @Test + void subFirstMaxSecondMinOk() { + double firstValue = Double.MAX_VALUE; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '-'); + double expected = Double.MAX_VALUE; + assertEquals(expected, actual, DELTA); + } + + @Test + void subTwoMaxOk() { + double firstValue = Double.MAX_VALUE; + double secondValue = Double.MAX_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '-'); + double expected = 0; + assertEquals(expected, actual); + } + + @Test + void subTwoMinOk() { + double firstValue = Double.MIN_VALUE; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue,secondValue, '-'); + double expected = 0; + assertEquals(expected, actual, DELTA); + } + + @Test + void multiplyTwoPositiveOk() { + double firstValue = 5; + double secondValue = 1; + double actual = calculator.calculate(firstValue, secondValue, '*'); + double expected = 5; + assertEquals(expected, actual); + } + + @Test + void multiplyTwoNegativeOk() { + double firstValue = -5; + double secondValue = -1; + double actual = calculator.calculate(firstValue, secondValue, '*'); + double expected = 5; + assertEquals(expected, actual); + } + + @Test + void multiplyFirstNegativeSecondPositiveOk() { + double firstValue = -1; + double secondValue = 1; + double actual = calculator.calculate(firstValue, secondValue, '*'); + double expected = -1; + assertEquals(expected, actual); + } + + @Test + void multiplyFirstPositiveSecondNegativeOk() { + double firstValue = 1; + double secondValue = -4; + double actual = calculator.calculate(firstValue, secondValue, '*'); + double expected = -4; + assertEquals(expected, actual); + } + + @Test + void multiplyTwoZeroOk() { + double firstValue = 0; + double secondValue = 0; + double actual = calculator.calculate(firstValue, secondValue, '*'); + double expected = 0; + assertEquals(expected, actual); + } + + @Test + void multiplyFirstZeroOk() { + double firstValue = 0; + double secondValue = 3; + double actual = calculator.calculate(firstValue, secondValue, '*'); + double expected = 0; + assertEquals(expected, actual); + } + + @Test + void multiplySecondZeroOk() { + double firstValue = -4; + double secondValue = 0; + double actual = calculator.calculate(firstValue, secondValue, '*'); + double expected = -0.0; + assertEquals(expected, actual); + } + + @Test + void multiplyFirstPositiveSecondMinOk() { + double firstValue = 1; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '*'); + double expected = 0; + assertEquals(expected, actual, DELTA); + } + + @Test + void multiplyFirstNegativeSecondMinOk() { + double firstValue = -1; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '*'); + double expected = 0; + assertEquals(expected, actual, DELTA); + } + + @Test + void multiplyFirstPositiveSecondMaxOk() { + double firstValue = 1; + double secondValue = Double.MAX_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '*'); + double expected = Double.MAX_VALUE; + assertEquals(expected, actual); + } + + @Test + void multiplyFirstZeroSecondMaxOk() { + double firstValue = 0; + double secondValue = Double.MAX_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '*'); + double expected = 0; + assertEquals(expected, actual); + } + + @Test + void multiplyFirstMaxSecondMinOk() { + double firstValue = Double.MAX_VALUE; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '*'); + double expected = 0; + assertEquals(expected, actual, DELTA); + } + + @Test + void multiplyTwoMaxOk() { + double firstValue = Double.MAX_VALUE; + double secondValue = Double.MAX_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '*'); + double expected = Double.POSITIVE_INFINITY; + assertEquals(expected, actual); + } + + @Test + void multiplyTwoMinOk() { + double firstValue = Double.MIN_VALUE; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue,secondValue, '*'); + double expected = 0; + assertEquals(expected, actual, DELTA); + } + + @Test + void divideTwoPositiveOk() { + double firstValue = 5; + double secondValue = 1; + double actual = calculator.calculate(firstValue, secondValue, '/'); + double expected = 5; + assertEquals(expected, actual); + } + + @Test + void divideTwoNegativeOk() { + double firstValue = -5; + double secondValue = -1; + double actual = calculator.calculate(firstValue, secondValue, '/'); + double expected = 5; + assertEquals(expected, actual); + } + + @Test + void divideFirstNegativeSecondPositiveOk() { + double firstValue = -1; + double secondValue = 1; + double actual = calculator.calculate(firstValue, secondValue, '/'); + double expected = -1; + assertEquals(expected, actual); + } + + @Test + void divideFirstPositiveSecondNegativeOk() { + double firstValue = 1; + double secondValue = -4; + double actual = calculator.calculate(firstValue, secondValue, '/'); + double expected = -0.25; + assertEquals(expected, actual); + } + + @Test + void divideFirstPositiveSecondMinOk() { + double firstValue = 1; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '/'); + double expected = Double.POSITIVE_INFINITY; + assertEquals(expected, actual); + } + + @Test + void divideFirstNegativeSecondMinOk() { + double firstValue = -1; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '/'); + double expected = Double.NEGATIVE_INFINITY; + assertEquals(expected, actual); + } + + @Test + void divideFirstPositiveSecondMaxOk() { + double firstValue = 1; + double secondValue = Double.MAX_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '/'); + double expected = 0; + assertEquals(expected, actual, DELTA); + } + + @Test + void divideFirstZeroSecondMaxOk() { + double firstValue = 0; + double secondValue = Double.MAX_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '/'); + double expected = 0; + assertEquals(expected, actual); + } + + @Test + void divideFirstMaxSecondMinOk() { + double firstValue = Double.MAX_VALUE; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '/'); + double expected = Double.POSITIVE_INFINITY; + assertEquals(expected, actual, DELTA); + } + + @Test + void divideTwoMaxOk() { + double firstValue = Double.MAX_VALUE; + double secondValue = Double.MAX_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '/'); + double expected = 1; + assertEquals(expected, actual); + } + + @Test + void divideTwoMinOk() { + double firstValue = Double.MIN_VALUE; + double secondValue = Double.MIN_VALUE; + double actual = calculator.calculate(firstValue,secondValue, '/'); + double expected = 1; + assertEquals(expected, actual, DELTA); + } + + @Test + void divideFirstPositiveSecondZeroOK() { + double firstValue = 1; + double secondValue = 0; + assertThrows(ArithmeticException.class, () -> { + calculator.calculate(firstValue, secondValue, '/'); + }); + } + + @Test + void divideFirstNegativeSecondZeroOK() { + double firstValue = -1; + double secondValue = 0; + assertThrows(ArithmeticException.class, () -> { + calculator.calculate(firstValue, secondValue, '/'); + }); + } + + @Test + void divideFirstMaxSecondZeroOK() { + double firstValue = Double.MAX_VALUE; + double secondValue = 0; + assertThrows(ArithmeticException.class, () -> { + calculator.calculate(firstValue, secondValue, '/'); + }); + } + + @Test + void divideFirstMinSecondZeroOK() { + double firstValue = Double.MIN_VALUE; + double secondValue = 0; + assertThrows(ArithmeticException.class, () -> { + calculator.calculate(firstValue, secondValue, '/'); + }); + } + + @Test + void raisingFirstPositiveSecondPositiveOK() { + double firstValue = 5.5; + double secondValue = 4; + double actual = calculator.calculate(firstValue,secondValue,'^'); + double expected = Math.pow(firstValue,secondValue); + assertEquals(expected, actual); + } + + @Test + void raisingFirstNegativeSecondPositiveOk() { + double firstValue = -1.1; + double secondValue = 3; + double actual = calculator.calculate(firstValue, secondValue, '^'); + double expected = Math.pow(firstValue, secondValue); + assertEquals(expected, actual); + } + + @Test + void raisingPositiveToNegative() { + double firstValue = 1; + double secondValue = -1.5; + double actual = calculator.calculate(firstValue, secondValue, '^'); + double expected = Math.pow(firstValue, secondValue); + assertEquals(expected, actual); + } + + @Test + void raisingNegativeToNegative() { + double firstValue = -1; + double secondValue = -5; + double actual = calculator.calculate(firstValue, secondValue, '^'); + double expected = Math.pow(firstValue, secondValue); + assertEquals(expected, actual); + } + + @Test + void raisingPositiveToZeroOK() { + double firstValue = 1; + double secondValue = 0; + double actual = calculator.calculate(firstValue, secondValue, '^'); + double expected = 1; + assertEquals(expected, actual); + } + + @Test + void raisingNegativeToZeroOK() { + double firstValue = -2; + double secondValue = 0; + double actual = calculator.calculate(firstValue, secondValue, '^'); + double expected = 1; + assertEquals(expected, actual); + } + + @Test + void raisingZeroToPositiveOk() { + double firstValue = 0; + double secondValue = 8; + double actual = calculator.calculate(firstValue, secondValue, '^'); + double expected = 0; + assertEquals(expected, actual); + } + + @Test + void raisingZeroToNegativeOk() { + double firstValue = 0; + double secondValue = -3; + double actual = calculator.calculate(firstValue, secondValue, '^'); + double expected = Double.POSITIVE_INFINITY; + assertEquals(expected, actual); + } + + @Test + void raisingZeroToMaxOK() { + double firstValue = 0; + double secondValue = Double.MAX_VALUE; + double actual = calculator.calculate(firstValue, secondValue, '^'); + double expected = 0; + assertEquals(expected, actual); + } + + @Test + void raisingZeroToMinOk() { + double firstValue = -2; + double secondValue = Double.MIN_VALUE; + assertThrows(IllegalValueException.class, () -> { + calculator.calculate(firstValue, secondValue, '^'); + }); + } +} diff --git a/src/test/java/core/basesyntax/HelloWorldTest.java b/src/test/java/core/basesyntax/HelloWorldTest.java deleted file mode 100644 index 9a90d822..00000000 --- a/src/test/java/core/basesyntax/HelloWorldTest.java +++ /dev/null @@ -1,8 +0,0 @@ -package core.basesyntax; - -/** - * Feel free to remove this class and create your own. - */ -public class HelloWorldTest { - -} From 2e945290376a299711359fe44597cbb55dea54c2 Mon Sep 17 00:00:00 2001 From: Vitalii Mykh Date: Tue, 14 Sep 2021 13:29:00 +0300 Subject: [PATCH 2/4] created constants for operators, shifted variable declarations from methods to class --- src/main/java/core/basesyntax/Calculator.java | 16 +- .../java/core/basesyntax/CalculatorTest.java | 547 +++++++++--------- 2 files changed, 289 insertions(+), 274 deletions(-) diff --git a/src/main/java/core/basesyntax/Calculator.java b/src/main/java/core/basesyntax/Calculator.java index 31c17059..bfc64d81 100644 --- a/src/main/java/core/basesyntax/Calculator.java +++ b/src/main/java/core/basesyntax/Calculator.java @@ -1,20 +1,26 @@ package core.basesyntax; public class Calculator { + private static final char ADDITION_OPERATOR = '+'; + private static final char SUBTRACTION_OPERATOR = '-'; + private static final char MULTIPLICATION_OPERATOR = '*'; + private static final char DIVISION_OPERATOR = '/'; + private static final char RAISING_TO_POWER_OPERATOR = '^'; + public double calculate(double firstValue, double secondValue, char operation) { switch (operation) { - case '+': + case ADDITION_OPERATOR: return firstValue + secondValue; - case '-': + case SUBTRACTION_OPERATOR: return firstValue - secondValue; - case '*': + case MULTIPLICATION_OPERATOR: return firstValue * secondValue; - case '/': + case DIVISION_OPERATOR: if (secondValue == 0) { throw new ArithmeticException("can`t divide on 0"); } return firstValue / secondValue; - case '^': + case RAISING_TO_POWER_OPERATOR: if (secondValue == Double.MIN_VALUE) { throw new IllegalValueException("can`t resolve operation"); } diff --git a/src/test/java/core/basesyntax/CalculatorTest.java b/src/test/java/core/basesyntax/CalculatorTest.java index 67ef39fc..e21138ad 100644 --- a/src/test/java/core/basesyntax/CalculatorTest.java +++ b/src/test/java/core/basesyntax/CalculatorTest.java @@ -3,22 +3,31 @@ 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.BeforeAll; import org.junit.jupiter.api.Test; class CalculatorTest { - private static Calculator calculator; private static final double DELTA = 0.0001; + private static final char ADDITION_OPERATOR = '+'; + private static final char SUBTRACTION_OPERATOR = '-'; + private static final char MULTIPLICATION_OPERATOR = '*'; + private static final char DIVISION_OPERATOR = '/'; + private static final char RAISING_TO_POWER_OPERATOR = '^'; + private static Calculator calculator; + private double firstValue; + private double secondValue; + private double actual; + private double expected; - @BeforeEach - void setUp() { + @BeforeAll + static void beforeAll() { calculator = new Calculator(); } @Test void checkOperatorNotOk() { - double firstValue = 1; - double secondValue = 4; + firstValue = 1; + secondValue = 4; assertThrows(IllegalOperatorException.class, () -> { calculator.calculate(firstValue, secondValue, '&'); }); @@ -26,604 +35,604 @@ void checkOperatorNotOk() { @Test void addTwoPositiveOk() { - double firstValue = 5; - double secondValue = 1; - double actual = calculator.calculate(firstValue, secondValue, '+'); - double expected = 6; + firstValue = 5; + secondValue = 1; + actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); + expected = 6; assertEquals(expected, actual); } @Test void addTwoNegativeOk() { - double firstValue = -5; - double secondValue = -1; - double actual = calculator.calculate(firstValue, secondValue, '+'); - double expected = -6; + firstValue = -5.1; + secondValue = -1; + actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); + expected = -6.1; assertEquals(expected, actual); } @Test void addFirstNegativeSecondPositiveOk() { - double firstValue = -1; - double secondValue = 1; - double actual = calculator.calculate(firstValue, secondValue, '+'); - double expected = 0; + firstValue = -1; + secondValue = 1; + actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); + expected = 0; assertEquals(expected, actual); } @Test void addFirstPositiveSecondBegativeOk() { - double firstValue = 1; - double secondValue = -4; - double actual = calculator.calculate(firstValue, secondValue, '+'); - double expected = -3; + firstValue = 1; + secondValue = -4; + actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); + expected = -3; assertEquals(expected, actual); } @Test void addTwoZeroOk() { - double firstValue = 0; - double secondValue = 0; - double actual = calculator.calculate(firstValue, secondValue, '+'); - double expected = 0; + firstValue = 0; + secondValue = 0; + actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); + expected = 0; assertEquals(expected, actual); } @Test void addFirstZeroOk() { - double firstValue = 0; - double secondValue = 3; - double actual = calculator.calculate(firstValue, secondValue, '+'); - double expected = 3; + firstValue = 0; + secondValue = 3; + actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); + expected = 3; assertEquals(expected, actual); } @Test void addSecondZeroOk() { - double firstValue = -4; - double secondValue = 0; - double actual = calculator.calculate(firstValue, secondValue, '+'); - double expected = -4; + firstValue = -4; + secondValue = 0; + actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); + expected = -4; assertEquals(expected, actual); } @Test void addFirstPositiveSecondMinOk() { - double firstValue = 1; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '+'); - double expected = 1; + firstValue = 1; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); + expected = 1; assertEquals(expected, actual, DELTA); } @Test void addFirstNegativeSecondMinOk() { - double firstValue = -1; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '+'); - double expected = -1; + firstValue = -1; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); + expected = -1; assertEquals(expected, actual, DELTA); } @Test void addFirstPositiveSecondMaxOk() { - double firstValue = 1; - double secondValue = Double.MAX_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '+'); - double expected = Double.MAX_VALUE; + firstValue = 1; + secondValue = Double.MAX_VALUE; + actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); + expected = Double.MAX_VALUE; assertEquals(expected, actual); } @Test void addFirstZeroSecondMaxOk() { - double firstValue = 0; - double secondValue = Double.MAX_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '+'); - double expected = Double.MAX_VALUE; + firstValue = 0; + secondValue = Double.MAX_VALUE; + actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); + expected = Double.MAX_VALUE; assertEquals(expected, actual); } @Test void addFirstMaxSecondMinOk() { - double firstValue = Double.MAX_VALUE; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '+'); - double expected = Double.MAX_VALUE; + firstValue = Double.MAX_VALUE; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); + expected = Double.MAX_VALUE; assertEquals(expected, actual, DELTA); } @Test void addTwoMaxOk() { - double firstValue = Double.MAX_VALUE; - double secondValue = Double.MAX_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '+'); - double expected = Double.POSITIVE_INFINITY; + firstValue = Double.MAX_VALUE; + secondValue = Double.MAX_VALUE; + actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); + expected = Double.POSITIVE_INFINITY; assertEquals(expected, actual); } @Test void addTwoMinOk() { - double firstValue = Double.MIN_VALUE; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue,secondValue, '+'); - double expected = 0; + firstValue = Double.MIN_VALUE; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue,secondValue, ADDITION_OPERATOR); + expected = 0; assertEquals(expected, actual, DELTA); } @Test void subTwoPositiveOk() { - double firstValue = 5; - double secondValue = 1; - double actual = calculator.calculate(firstValue, secondValue, '-'); - double expected = 4; + firstValue = 5; + secondValue = 1; + actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); + expected = 4; assertEquals(expected, actual); } @Test void subTwoNegativeOk() { - double firstValue = -5; - double secondValue = -1; - double actual = calculator.calculate(firstValue, secondValue, '-'); - double expected = -4; + firstValue = -5; + secondValue = -1; + actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); + expected = -4; assertEquals(expected, actual); } @Test void subFirstNegativeSecondPositiveOk() { - double firstValue = -1; - double secondValue = 1; - double actual = calculator.calculate(firstValue, secondValue, '-'); - double expected = -2; + firstValue = -1; + secondValue = 1; + actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); + expected = -2; assertEquals(expected, actual); } @Test void subFirstPositiveSecondNegativeOk() { - double firstValue = 1; - double secondValue = -4; - double actual = calculator.calculate(firstValue, secondValue, '-'); - double expected = 5; + firstValue = 1; + secondValue = -4; + actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); + expected = 5; assertEquals(expected, actual); } @Test void subTwoZeroOk() { - double firstValue = 0; - double secondValue = 0; - double actual = calculator.calculate(firstValue, secondValue, '-'); - double expected = 0; + firstValue = 0; + secondValue = 0; + actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); + expected = 0; assertEquals(expected, actual); } @Test void subFirstZeroOk() { - double firstValue = 0; - double secondValue = 3; - double actual = calculator.calculate(firstValue, secondValue, '-'); - double expected = -3; + firstValue = 0; + secondValue = 3; + actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); + expected = -3; assertEquals(expected, actual); } @Test void subSecondZeroOk() { - double firstValue = -4; - double secondValue = 0; - double actual = calculator.calculate(firstValue, secondValue, '-'); - double expected = -4; + firstValue = -4; + secondValue = 0; + actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); + expected = -4; assertEquals(expected, actual); } @Test void subFirstPositiveSecondMinOk() { - double firstValue = 1; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '-'); - double expected = 1; + firstValue = 1; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); + expected = 1; assertEquals(expected, actual, DELTA); } @Test void subFirstNegativeSecondMinOk() { - double firstValue = -1; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '-'); - double expected = -1; + firstValue = -1; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); + expected = -1; assertEquals(expected, actual, DELTA); } @Test void subFirstPositiveSecondMaxOk() { - double firstValue = 1; - double secondValue = Double.MAX_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '-'); - double expected = -Double.MAX_VALUE; + firstValue = 1; + secondValue = Double.MAX_VALUE; + actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); + expected = -Double.MAX_VALUE; assertEquals(expected, actual, DELTA); } @Test void subFirstZeroSecondMaxOk() { - double firstValue = 0; - double secondValue = Double.MAX_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '-'); - double expected = -Double.MAX_VALUE; + firstValue = 0; + secondValue = Double.MAX_VALUE; + actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); + expected = -Double.MAX_VALUE; assertEquals(expected, actual, DELTA); } @Test void subFirstMaxSecondMinOk() { - double firstValue = Double.MAX_VALUE; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '-'); - double expected = Double.MAX_VALUE; + firstValue = Double.MAX_VALUE; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); + expected = Double.MAX_VALUE; assertEquals(expected, actual, DELTA); } @Test void subTwoMaxOk() { - double firstValue = Double.MAX_VALUE; - double secondValue = Double.MAX_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '-'); - double expected = 0; + firstValue = Double.MAX_VALUE; + secondValue = Double.MAX_VALUE; + actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); + expected = 0; assertEquals(expected, actual); } @Test void subTwoMinOk() { - double firstValue = Double.MIN_VALUE; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue,secondValue, '-'); - double expected = 0; + firstValue = Double.MIN_VALUE; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue,secondValue, SUBTRACTION_OPERATOR); + expected = 0; assertEquals(expected, actual, DELTA); } @Test void multiplyTwoPositiveOk() { - double firstValue = 5; - double secondValue = 1; - double actual = calculator.calculate(firstValue, secondValue, '*'); - double expected = 5; + firstValue = 5; + secondValue = 1; + actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); + expected = 5; assertEquals(expected, actual); } @Test void multiplyTwoNegativeOk() { - double firstValue = -5; - double secondValue = -1; - double actual = calculator.calculate(firstValue, secondValue, '*'); - double expected = 5; + firstValue = -5; + secondValue = -1; + actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); + expected = 5; assertEquals(expected, actual); } @Test void multiplyFirstNegativeSecondPositiveOk() { - double firstValue = -1; - double secondValue = 1; - double actual = calculator.calculate(firstValue, secondValue, '*'); - double expected = -1; + firstValue = -1; + secondValue = 1; + actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); + expected = -1; assertEquals(expected, actual); } @Test void multiplyFirstPositiveSecondNegativeOk() { - double firstValue = 1; - double secondValue = -4; - double actual = calculator.calculate(firstValue, secondValue, '*'); - double expected = -4; + firstValue = 1; + secondValue = -4; + actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); + expected = -4; assertEquals(expected, actual); } @Test void multiplyTwoZeroOk() { - double firstValue = 0; - double secondValue = 0; - double actual = calculator.calculate(firstValue, secondValue, '*'); - double expected = 0; + firstValue = 0; + secondValue = 0; + actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); + expected = 0; assertEquals(expected, actual); } @Test void multiplyFirstZeroOk() { - double firstValue = 0; - double secondValue = 3; - double actual = calculator.calculate(firstValue, secondValue, '*'); - double expected = 0; + firstValue = 0; + secondValue = 3; + actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); + expected = 0; assertEquals(expected, actual); } @Test void multiplySecondZeroOk() { - double firstValue = -4; - double secondValue = 0; - double actual = calculator.calculate(firstValue, secondValue, '*'); - double expected = -0.0; + firstValue = -4; + secondValue = 0; + actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); + expected = -0.0; assertEquals(expected, actual); } @Test void multiplyFirstPositiveSecondMinOk() { - double firstValue = 1; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '*'); - double expected = 0; + firstValue = 1; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); + expected = 0; assertEquals(expected, actual, DELTA); } @Test void multiplyFirstNegativeSecondMinOk() { - double firstValue = -1; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '*'); - double expected = 0; + firstValue = -1; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); + expected = 0; assertEquals(expected, actual, DELTA); } @Test void multiplyFirstPositiveSecondMaxOk() { - double firstValue = 1; - double secondValue = Double.MAX_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '*'); - double expected = Double.MAX_VALUE; + firstValue = 1; + secondValue = Double.MAX_VALUE; + actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); + expected = Double.MAX_VALUE; assertEquals(expected, actual); } @Test void multiplyFirstZeroSecondMaxOk() { - double firstValue = 0; - double secondValue = Double.MAX_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '*'); - double expected = 0; + firstValue = 0; + secondValue = Double.MAX_VALUE; + actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); + expected = 0; assertEquals(expected, actual); } @Test void multiplyFirstMaxSecondMinOk() { - double firstValue = Double.MAX_VALUE; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '*'); - double expected = 0; + firstValue = Double.MAX_VALUE; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); + expected = 0; assertEquals(expected, actual, DELTA); } @Test void multiplyTwoMaxOk() { - double firstValue = Double.MAX_VALUE; - double secondValue = Double.MAX_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '*'); - double expected = Double.POSITIVE_INFINITY; + firstValue = Double.MAX_VALUE; + secondValue = Double.MAX_VALUE; + actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); + expected = Double.POSITIVE_INFINITY; assertEquals(expected, actual); } @Test void multiplyTwoMinOk() { - double firstValue = Double.MIN_VALUE; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue,secondValue, '*'); - double expected = 0; + firstValue = Double.MIN_VALUE; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue,secondValue, MULTIPLICATION_OPERATOR); + expected = 0; assertEquals(expected, actual, DELTA); } @Test void divideTwoPositiveOk() { - double firstValue = 5; - double secondValue = 1; - double actual = calculator.calculate(firstValue, secondValue, '/'); - double expected = 5; + firstValue = 5; + secondValue = 1; + actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); + expected = 5; assertEquals(expected, actual); } @Test void divideTwoNegativeOk() { - double firstValue = -5; - double secondValue = -1; - double actual = calculator.calculate(firstValue, secondValue, '/'); - double expected = 5; + firstValue = -5; + secondValue = -1; + actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); + expected = 5; assertEquals(expected, actual); } @Test void divideFirstNegativeSecondPositiveOk() { - double firstValue = -1; - double secondValue = 1; - double actual = calculator.calculate(firstValue, secondValue, '/'); - double expected = -1; + firstValue = -1; + secondValue = 1; + actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); + expected = -1; assertEquals(expected, actual); } @Test void divideFirstPositiveSecondNegativeOk() { - double firstValue = 1; - double secondValue = -4; - double actual = calculator.calculate(firstValue, secondValue, '/'); - double expected = -0.25; + firstValue = 1; + secondValue = -4; + actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); + expected = -0.25; assertEquals(expected, actual); } @Test void divideFirstPositiveSecondMinOk() { - double firstValue = 1; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '/'); - double expected = Double.POSITIVE_INFINITY; + firstValue = 1; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); + expected = Double.POSITIVE_INFINITY; assertEquals(expected, actual); } @Test void divideFirstNegativeSecondMinOk() { - double firstValue = -1; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '/'); - double expected = Double.NEGATIVE_INFINITY; + firstValue = -1; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); + expected = Double.NEGATIVE_INFINITY; assertEquals(expected, actual); } @Test void divideFirstPositiveSecondMaxOk() { - double firstValue = 1; - double secondValue = Double.MAX_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '/'); - double expected = 0; + firstValue = 1; + secondValue = Double.MAX_VALUE; + actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); + expected = 0; assertEquals(expected, actual, DELTA); } @Test void divideFirstZeroSecondMaxOk() { - double firstValue = 0; - double secondValue = Double.MAX_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '/'); - double expected = 0; + firstValue = 0; + secondValue = Double.MAX_VALUE; + actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); + expected = 0; assertEquals(expected, actual); } @Test void divideFirstMaxSecondMinOk() { - double firstValue = Double.MAX_VALUE; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '/'); - double expected = Double.POSITIVE_INFINITY; + firstValue = Double.MAX_VALUE; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); + expected = Double.POSITIVE_INFINITY; assertEquals(expected, actual, DELTA); } @Test void divideTwoMaxOk() { - double firstValue = Double.MAX_VALUE; - double secondValue = Double.MAX_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '/'); - double expected = 1; + firstValue = Double.MAX_VALUE; + secondValue = Double.MAX_VALUE; + actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); + expected = 1; assertEquals(expected, actual); } @Test void divideTwoMinOk() { - double firstValue = Double.MIN_VALUE; - double secondValue = Double.MIN_VALUE; - double actual = calculator.calculate(firstValue,secondValue, '/'); - double expected = 1; + firstValue = Double.MIN_VALUE; + secondValue = Double.MIN_VALUE; + actual = calculator.calculate(firstValue,secondValue, DIVISION_OPERATOR); + expected = 1; assertEquals(expected, actual, DELTA); } @Test void divideFirstPositiveSecondZeroOK() { - double firstValue = 1; - double secondValue = 0; + firstValue = 1; + secondValue = 0; assertThrows(ArithmeticException.class, () -> { - calculator.calculate(firstValue, secondValue, '/'); + calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); }); } @Test void divideFirstNegativeSecondZeroOK() { - double firstValue = -1; - double secondValue = 0; + firstValue = -1; + secondValue = 0; assertThrows(ArithmeticException.class, () -> { - calculator.calculate(firstValue, secondValue, '/'); + calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); }); } @Test void divideFirstMaxSecondZeroOK() { - double firstValue = Double.MAX_VALUE; - double secondValue = 0; + firstValue = Double.MAX_VALUE; + secondValue = 0; assertThrows(ArithmeticException.class, () -> { - calculator.calculate(firstValue, secondValue, '/'); + calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); }); } @Test void divideFirstMinSecondZeroOK() { - double firstValue = Double.MIN_VALUE; - double secondValue = 0; + firstValue = Double.MIN_VALUE; + secondValue = 0; assertThrows(ArithmeticException.class, () -> { - calculator.calculate(firstValue, secondValue, '/'); + calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); }); } @Test void raisingFirstPositiveSecondPositiveOK() { - double firstValue = 5.5; - double secondValue = 4; - double actual = calculator.calculate(firstValue,secondValue,'^'); - double expected = Math.pow(firstValue,secondValue); + firstValue = 5.5; + secondValue = 4; + actual = calculator.calculate(firstValue,secondValue,RAISING_TO_POWER_OPERATOR); + expected = Math.pow(firstValue,secondValue); assertEquals(expected, actual); } @Test void raisingFirstNegativeSecondPositiveOk() { - double firstValue = -1.1; - double secondValue = 3; - double actual = calculator.calculate(firstValue, secondValue, '^'); - double expected = Math.pow(firstValue, secondValue); + firstValue = -1.1; + secondValue = 3; + actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); + expected = Math.pow(firstValue, secondValue); assertEquals(expected, actual); } @Test void raisingPositiveToNegative() { - double firstValue = 1; - double secondValue = -1.5; - double actual = calculator.calculate(firstValue, secondValue, '^'); - double expected = Math.pow(firstValue, secondValue); + firstValue = 1; + secondValue = -1.5; + actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); + expected = Math.pow(firstValue, secondValue); assertEquals(expected, actual); } @Test void raisingNegativeToNegative() { - double firstValue = -1; - double secondValue = -5; - double actual = calculator.calculate(firstValue, secondValue, '^'); - double expected = Math.pow(firstValue, secondValue); + firstValue = -1; + secondValue = -5; + actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); + expected = Math.pow(firstValue, secondValue); assertEquals(expected, actual); } @Test void raisingPositiveToZeroOK() { - double firstValue = 1; - double secondValue = 0; - double actual = calculator.calculate(firstValue, secondValue, '^'); - double expected = 1; + firstValue = 1; + secondValue = 0; + actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); + expected = 1; assertEquals(expected, actual); } @Test void raisingNegativeToZeroOK() { - double firstValue = -2; - double secondValue = 0; - double actual = calculator.calculate(firstValue, secondValue, '^'); - double expected = 1; + firstValue = -2; + secondValue = 0; + actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); + expected = 1; assertEquals(expected, actual); } @Test void raisingZeroToPositiveOk() { - double firstValue = 0; - double secondValue = 8; - double actual = calculator.calculate(firstValue, secondValue, '^'); - double expected = 0; + firstValue = 0; + secondValue = 8; + actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); + expected = 0; assertEquals(expected, actual); } @Test void raisingZeroToNegativeOk() { - double firstValue = 0; - double secondValue = -3; - double actual = calculator.calculate(firstValue, secondValue, '^'); - double expected = Double.POSITIVE_INFINITY; + firstValue = 0; + secondValue = -3; + actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); + expected = Double.POSITIVE_INFINITY; assertEquals(expected, actual); } @Test void raisingZeroToMaxOK() { - double firstValue = 0; - double secondValue = Double.MAX_VALUE; - double actual = calculator.calculate(firstValue, secondValue, '^'); - double expected = 0; + firstValue = 0; + secondValue = Double.MAX_VALUE; + actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); + expected = 0; assertEquals(expected, actual); } @Test void raisingZeroToMinOk() { - double firstValue = -2; - double secondValue = Double.MIN_VALUE; + firstValue = -2; + secondValue = Double.MIN_VALUE; assertThrows(IllegalValueException.class, () -> { - calculator.calculate(firstValue, secondValue, '^'); + calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); }); } } From cca4ca4c6627e0dbfbb53c3d59515b7b49298068 Mon Sep 17 00:00:00 2001 From: Vitalii Mykh Date: Tue, 14 Sep 2021 16:31:27 +0300 Subject: [PATCH 3/4] changed dependency, refactored test naming, fixed if statement --- pom.xml | 3 +- src/main/java/core/basesyntax/Calculator.java | 2 +- .../java/core/basesyntax/CalculatorTest.java | 136 +++++++++--------- 3 files changed, 70 insertions(+), 71 deletions(-) diff --git a/pom.xml b/pom.xml index 606f826c..44539c01 100644 --- a/pom.xml +++ b/pom.xml @@ -22,10 +22,9 @@ org.junit.jupiter junit-jupiter-api - 5.8.0-RC1 + 5.8.0 test - diff --git a/src/main/java/core/basesyntax/Calculator.java b/src/main/java/core/basesyntax/Calculator.java index bfc64d81..89cf7e35 100644 --- a/src/main/java/core/basesyntax/Calculator.java +++ b/src/main/java/core/basesyntax/Calculator.java @@ -21,7 +21,7 @@ public double calculate(double firstValue, double secondValue, char operation) { } return firstValue / secondValue; case RAISING_TO_POWER_OPERATOR: - if (secondValue == Double.MIN_VALUE) { + if (firstValue < 0 && secondValue == Double.MIN_VALUE) { throw new IllegalValueException("can`t resolve operation"); } return Math.pow(firstValue, secondValue); diff --git a/src/test/java/core/basesyntax/CalculatorTest.java b/src/test/java/core/basesyntax/CalculatorTest.java index e21138ad..751b503a 100644 --- a/src/test/java/core/basesyntax/CalculatorTest.java +++ b/src/test/java/core/basesyntax/CalculatorTest.java @@ -25,7 +25,7 @@ static void beforeAll() { } @Test - void checkOperatorNotOk() { + void check_Operator_NotOk() { firstValue = 1; secondValue = 4; assertThrows(IllegalOperatorException.class, () -> { @@ -34,7 +34,7 @@ void checkOperatorNotOk() { } @Test - void addTwoPositiveOk() { + void add_TwoPositive_Ok() { firstValue = 5; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -43,7 +43,7 @@ void addTwoPositiveOk() { } @Test - void addTwoNegativeOk() { + void add_TwoNegative_Ok() { firstValue = -5.1; secondValue = -1; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -52,7 +52,7 @@ void addTwoNegativeOk() { } @Test - void addFirstNegativeSecondPositiveOk() { + void add_FirstNegativeSecondPositive_Ok() { firstValue = -1; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -61,7 +61,7 @@ void addFirstNegativeSecondPositiveOk() { } @Test - void addFirstPositiveSecondBegativeOk() { + void add_FirstPositiveSecondBegative_Ok() { firstValue = 1; secondValue = -4; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -70,7 +70,7 @@ void addFirstPositiveSecondBegativeOk() { } @Test - void addTwoZeroOk() { + void add_TwoZero_Ok() { firstValue = 0; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -79,7 +79,7 @@ void addTwoZeroOk() { } @Test - void addFirstZeroOk() { + void add_FirstZero_Ok() { firstValue = 0; secondValue = 3; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -88,7 +88,7 @@ void addFirstZeroOk() { } @Test - void addSecondZeroOk() { + void add_SecondZero_Ok() { firstValue = -4; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -97,7 +97,7 @@ void addSecondZeroOk() { } @Test - void addFirstPositiveSecondMinOk() { + void add_FirstPositiveSecondMin_Ok() { firstValue = 1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -106,7 +106,7 @@ void addFirstPositiveSecondMinOk() { } @Test - void addFirstNegativeSecondMinOk() { + void add_FirstNegativeSecondMin_Ok() { firstValue = -1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -115,7 +115,7 @@ void addFirstNegativeSecondMinOk() { } @Test - void addFirstPositiveSecondMaxOk() { + void add_FirstPositiveSecondMax_Ok() { firstValue = 1; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -124,7 +124,7 @@ void addFirstPositiveSecondMaxOk() { } @Test - void addFirstZeroSecondMaxOk() { + void add_FirstZeroSecondMax_Ok() { firstValue = 0; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -133,7 +133,7 @@ void addFirstZeroSecondMaxOk() { } @Test - void addFirstMaxSecondMinOk() { + void add_FirstMaxSecondMin_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -142,7 +142,7 @@ void addFirstMaxSecondMinOk() { } @Test - void addTwoMaxOk() { + void add_TwoMax_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -151,7 +151,7 @@ void addTwoMaxOk() { } @Test - void addTwoMinOk() { + void add_TwoMin_Ok() { firstValue = Double.MIN_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue,secondValue, ADDITION_OPERATOR); @@ -160,7 +160,7 @@ void addTwoMinOk() { } @Test - void subTwoPositiveOk() { + void sub_TwoPositive_Ok() { firstValue = 5; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -169,7 +169,7 @@ void subTwoPositiveOk() { } @Test - void subTwoNegativeOk() { + void sub_TwoNegative_Ok() { firstValue = -5; secondValue = -1; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -178,7 +178,7 @@ void subTwoNegativeOk() { } @Test - void subFirstNegativeSecondPositiveOk() { + void sub_FirstNegativeSecondPositive_Ok() { firstValue = -1; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -187,7 +187,7 @@ void subFirstNegativeSecondPositiveOk() { } @Test - void subFirstPositiveSecondNegativeOk() { + void sub_FirstPositiveSecondNegative_Ok() { firstValue = 1; secondValue = -4; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -196,7 +196,7 @@ void subFirstPositiveSecondNegativeOk() { } @Test - void subTwoZeroOk() { + void sub_TwoZero_Ok() { firstValue = 0; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -205,7 +205,7 @@ void subTwoZeroOk() { } @Test - void subFirstZeroOk() { + void sub_FirstZero_Ok() { firstValue = 0; secondValue = 3; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -214,7 +214,7 @@ void subFirstZeroOk() { } @Test - void subSecondZeroOk() { + void sub_SecondZero_Ok() { firstValue = -4; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -223,7 +223,7 @@ void subSecondZeroOk() { } @Test - void subFirstPositiveSecondMinOk() { + void sub_FirstPositiveSecondMin_Ok() { firstValue = 1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -232,7 +232,7 @@ void subFirstPositiveSecondMinOk() { } @Test - void subFirstNegativeSecondMinOk() { + void sub_FirstNegativeSecondMin_Ok() { firstValue = -1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -241,7 +241,7 @@ void subFirstNegativeSecondMinOk() { } @Test - void subFirstPositiveSecondMaxOk() { + void sub_FirstPositiveSecondMax_Ok() { firstValue = 1; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -250,7 +250,7 @@ void subFirstPositiveSecondMaxOk() { } @Test - void subFirstZeroSecondMaxOk() { + void sub_FirstZeroSecondMax_Ok() { firstValue = 0; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -259,7 +259,7 @@ void subFirstZeroSecondMaxOk() { } @Test - void subFirstMaxSecondMinOk() { + void sub_FirstMaxSecondMin_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -268,7 +268,7 @@ void subFirstMaxSecondMinOk() { } @Test - void subTwoMaxOk() { + void sub_TwoMax_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -277,7 +277,7 @@ void subTwoMaxOk() { } @Test - void subTwoMinOk() { + void sub_TwoMin_Ok() { firstValue = Double.MIN_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue,secondValue, SUBTRACTION_OPERATOR); @@ -286,7 +286,7 @@ void subTwoMinOk() { } @Test - void multiplyTwoPositiveOk() { + void multiply_TwoPositive_Ok() { firstValue = 5; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -295,7 +295,7 @@ void multiplyTwoPositiveOk() { } @Test - void multiplyTwoNegativeOk() { + void multiply_TwoNegative_Ok() { firstValue = -5; secondValue = -1; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -304,7 +304,7 @@ void multiplyTwoNegativeOk() { } @Test - void multiplyFirstNegativeSecondPositiveOk() { + void multiply_FirstNegativeSecondPositive_Ok() { firstValue = -1; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -313,7 +313,7 @@ void multiplyFirstNegativeSecondPositiveOk() { } @Test - void multiplyFirstPositiveSecondNegativeOk() { + void multiply_FirstPositiveSecondNegative_Ok() { firstValue = 1; secondValue = -4; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -322,7 +322,7 @@ void multiplyFirstPositiveSecondNegativeOk() { } @Test - void multiplyTwoZeroOk() { + void multiply_TwoZero_Ok() { firstValue = 0; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -331,7 +331,7 @@ void multiplyTwoZeroOk() { } @Test - void multiplyFirstZeroOk() { + void multiply_FirstZero_Ok() { firstValue = 0; secondValue = 3; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -340,7 +340,7 @@ void multiplyFirstZeroOk() { } @Test - void multiplySecondZeroOk() { + void multiply_SecondZero_Ok() { firstValue = -4; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -349,7 +349,7 @@ void multiplySecondZeroOk() { } @Test - void multiplyFirstPositiveSecondMinOk() { + void multiply_FirstPositiveSecondMin_Ok() { firstValue = 1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -358,7 +358,7 @@ void multiplyFirstPositiveSecondMinOk() { } @Test - void multiplyFirstNegativeSecondMinOk() { + void multiply_FirstNegativeSecondMin_Ok() { firstValue = -1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -367,7 +367,7 @@ void multiplyFirstNegativeSecondMinOk() { } @Test - void multiplyFirstPositiveSecondMaxOk() { + void multiply_FirstPositiveSecondMax_Ok() { firstValue = 1; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -376,7 +376,7 @@ void multiplyFirstPositiveSecondMaxOk() { } @Test - void multiplyFirstZeroSecondMaxOk() { + void multiply_FirstZeroSecondMax_Ok() { firstValue = 0; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -385,7 +385,7 @@ void multiplyFirstZeroSecondMaxOk() { } @Test - void multiplyFirstMaxSecondMinOk() { + void multiply_FirstMaxSecondMin_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -394,7 +394,7 @@ void multiplyFirstMaxSecondMinOk() { } @Test - void multiplyTwoMaxOk() { + void multiply_TwoMax_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -403,7 +403,7 @@ void multiplyTwoMaxOk() { } @Test - void multiplyTwoMinOk() { + void multiply_TwoMin_Ok() { firstValue = Double.MIN_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue,secondValue, MULTIPLICATION_OPERATOR); @@ -412,7 +412,7 @@ void multiplyTwoMinOk() { } @Test - void divideTwoPositiveOk() { + void divide_TwoPositive_Ok() { firstValue = 5; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -421,7 +421,7 @@ void divideTwoPositiveOk() { } @Test - void divideTwoNegativeOk() { + void divide_TwoNegative_Ok() { firstValue = -5; secondValue = -1; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -430,7 +430,7 @@ void divideTwoNegativeOk() { } @Test - void divideFirstNegativeSecondPositiveOk() { + void divide_FirstNegativeSecondPositive_Ok() { firstValue = -1; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -439,7 +439,7 @@ void divideFirstNegativeSecondPositiveOk() { } @Test - void divideFirstPositiveSecondNegativeOk() { + void divide_FirstPositiveSecondNegative_Ok() { firstValue = 1; secondValue = -4; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -448,7 +448,7 @@ void divideFirstPositiveSecondNegativeOk() { } @Test - void divideFirstPositiveSecondMinOk() { + void divide_FirstPositiveSecondMin_Ok() { firstValue = 1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -457,7 +457,7 @@ void divideFirstPositiveSecondMinOk() { } @Test - void divideFirstNegativeSecondMinOk() { + void divide_FirstNegativeSecondMin_Ok() { firstValue = -1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -466,7 +466,7 @@ void divideFirstNegativeSecondMinOk() { } @Test - void divideFirstPositiveSecondMaxOk() { + void divide_FirstPositiveSecondMax_Ok() { firstValue = 1; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -475,7 +475,7 @@ void divideFirstPositiveSecondMaxOk() { } @Test - void divideFirstZeroSecondMaxOk() { + void divide_FirstZeroSecondMax_Ok() { firstValue = 0; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -484,7 +484,7 @@ void divideFirstZeroSecondMaxOk() { } @Test - void divideFirstMaxSecondMinOk() { + void divide_FirstMaxSecondMin_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -493,7 +493,7 @@ void divideFirstMaxSecondMinOk() { } @Test - void divideTwoMaxOk() { + void divide_TwoMax_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -502,7 +502,7 @@ void divideTwoMaxOk() { } @Test - void divideTwoMinOk() { + void divide_TwoMin_Ok() { firstValue = Double.MIN_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue,secondValue, DIVISION_OPERATOR); @@ -511,7 +511,7 @@ void divideTwoMinOk() { } @Test - void divideFirstPositiveSecondZeroOK() { + void divide_FirstPositiveSecondZero_OK() { firstValue = 1; secondValue = 0; assertThrows(ArithmeticException.class, () -> { @@ -520,7 +520,7 @@ void divideFirstPositiveSecondZeroOK() { } @Test - void divideFirstNegativeSecondZeroOK() { + void divide_FirstNegativeSecondZero_OK() { firstValue = -1; secondValue = 0; assertThrows(ArithmeticException.class, () -> { @@ -529,7 +529,7 @@ void divideFirstNegativeSecondZeroOK() { } @Test - void divideFirstMaxSecondZeroOK() { + void divide_FirstMaxSecondZero_OK() { firstValue = Double.MAX_VALUE; secondValue = 0; assertThrows(ArithmeticException.class, () -> { @@ -538,7 +538,7 @@ void divideFirstMaxSecondZeroOK() { } @Test - void divideFirstMinSecondZeroOK() { + void divide_FirstMinSecondZero_OK() { firstValue = Double.MIN_VALUE; secondValue = 0; assertThrows(ArithmeticException.class, () -> { @@ -547,7 +547,7 @@ void divideFirstMinSecondZeroOK() { } @Test - void raisingFirstPositiveSecondPositiveOK() { + void raising_FirstPositiveSecondPositive_OK() { firstValue = 5.5; secondValue = 4; actual = calculator.calculate(firstValue,secondValue,RAISING_TO_POWER_OPERATOR); @@ -556,7 +556,7 @@ void raisingFirstPositiveSecondPositiveOK() { } @Test - void raisingFirstNegativeSecondPositiveOk() { + void raising_FirstNegativeSecondPositive_Ok() { firstValue = -1.1; secondValue = 3; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -565,7 +565,7 @@ void raisingFirstNegativeSecondPositiveOk() { } @Test - void raisingPositiveToNegative() { + void raising_PositiveToNegative_Ok() { firstValue = 1; secondValue = -1.5; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -574,7 +574,7 @@ void raisingPositiveToNegative() { } @Test - void raisingNegativeToNegative() { + void raising_NegativeToNegative_Ok() { firstValue = -1; secondValue = -5; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -583,7 +583,7 @@ void raisingNegativeToNegative() { } @Test - void raisingPositiveToZeroOK() { + void raising_PositiveToZero_OK() { firstValue = 1; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -592,7 +592,7 @@ void raisingPositiveToZeroOK() { } @Test - void raisingNegativeToZeroOK() { + void raising_NegativeToZero_OK() { firstValue = -2; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -601,7 +601,7 @@ void raisingNegativeToZeroOK() { } @Test - void raisingZeroToPositiveOk() { + void raising_ZeroToPositive_Ok() { firstValue = 0; secondValue = 8; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -610,7 +610,7 @@ void raisingZeroToPositiveOk() { } @Test - void raisingZeroToNegativeOk() { + void raising_ZeroToNegative_Ok() { firstValue = 0; secondValue = -3; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -619,7 +619,7 @@ void raisingZeroToNegativeOk() { } @Test - void raisingZeroToMaxOK() { + void raising_ZeroToMax_OK() { firstValue = 0; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -628,7 +628,7 @@ void raisingZeroToMaxOK() { } @Test - void raisingZeroToMinOk() { + void raising_ZeroToMin_Ok() { firstValue = -2; secondValue = Double.MIN_VALUE; assertThrows(IllegalValueException.class, () -> { From 91d6446348ed1ea5e64218e96002db755773030f Mon Sep 17 00:00:00 2001 From: Vitalii Mykh Date: Tue, 14 Sep 2021 17:18:07 +0300 Subject: [PATCH 4/4] method naming changed --- .../java/core/basesyntax/CalculatorTest.java | 136 +++++++++--------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/src/test/java/core/basesyntax/CalculatorTest.java b/src/test/java/core/basesyntax/CalculatorTest.java index 751b503a..329e4629 100644 --- a/src/test/java/core/basesyntax/CalculatorTest.java +++ b/src/test/java/core/basesyntax/CalculatorTest.java @@ -25,7 +25,7 @@ static void beforeAll() { } @Test - void check_Operator_NotOk() { + void calculate_checkOperator_NotOk() { firstValue = 1; secondValue = 4; assertThrows(IllegalOperatorException.class, () -> { @@ -34,7 +34,7 @@ void check_Operator_NotOk() { } @Test - void add_TwoPositive_Ok() { + void calculate_addTwoPositive_Ok() { firstValue = 5; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -43,7 +43,7 @@ void add_TwoPositive_Ok() { } @Test - void add_TwoNegative_Ok() { + void calculate_addTwoNegative_Ok() { firstValue = -5.1; secondValue = -1; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -52,7 +52,7 @@ void add_TwoNegative_Ok() { } @Test - void add_FirstNegativeSecondPositive_Ok() { + void calculate_addFirstNegativeSecondPositive_Ok() { firstValue = -1; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -61,7 +61,7 @@ void add_FirstNegativeSecondPositive_Ok() { } @Test - void add_FirstPositiveSecondBegative_Ok() { + void calculate_addFirstPositiveSecondBegative_Ok() { firstValue = 1; secondValue = -4; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -70,7 +70,7 @@ void add_FirstPositiveSecondBegative_Ok() { } @Test - void add_TwoZero_Ok() { + void calculate_addTwoZero_Ok() { firstValue = 0; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -79,7 +79,7 @@ void add_TwoZero_Ok() { } @Test - void add_FirstZero_Ok() { + void calculate_addFirstZero_Ok() { firstValue = 0; secondValue = 3; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -88,7 +88,7 @@ void add_FirstZero_Ok() { } @Test - void add_SecondZero_Ok() { + void calculate_addSecondZero_Ok() { firstValue = -4; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -97,7 +97,7 @@ void add_SecondZero_Ok() { } @Test - void add_FirstPositiveSecondMin_Ok() { + void calculate_addFirstPositiveSecondMin_Ok() { firstValue = 1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -106,7 +106,7 @@ void add_FirstPositiveSecondMin_Ok() { } @Test - void add_FirstNegativeSecondMin_Ok() { + void calculate_addFirstNegativeSecondMin_Ok() { firstValue = -1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -115,7 +115,7 @@ void add_FirstNegativeSecondMin_Ok() { } @Test - void add_FirstPositiveSecondMax_Ok() { + void calculate_addFirstPositiveSecondMax_Ok() { firstValue = 1; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -124,7 +124,7 @@ void add_FirstPositiveSecondMax_Ok() { } @Test - void add_FirstZeroSecondMax_Ok() { + void calculate_addFirstZeroSecondMax_Ok() { firstValue = 0; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -133,7 +133,7 @@ void add_FirstZeroSecondMax_Ok() { } @Test - void add_FirstMaxSecondMin_Ok() { + void calculate_addFirstMaxSecondMin_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -142,7 +142,7 @@ void add_FirstMaxSecondMin_Ok() { } @Test - void add_TwoMax_Ok() { + void calculate_addTwoMax_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, ADDITION_OPERATOR); @@ -151,7 +151,7 @@ void add_TwoMax_Ok() { } @Test - void add_TwoMin_Ok() { + void calculate_addTwoMin_Ok() { firstValue = Double.MIN_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue,secondValue, ADDITION_OPERATOR); @@ -160,7 +160,7 @@ void add_TwoMin_Ok() { } @Test - void sub_TwoPositive_Ok() { + void calculate_subTwoPositive_Ok() { firstValue = 5; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -169,7 +169,7 @@ void sub_TwoPositive_Ok() { } @Test - void sub_TwoNegative_Ok() { + void calculate_subTwoNegative_Ok() { firstValue = -5; secondValue = -1; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -178,7 +178,7 @@ void sub_TwoNegative_Ok() { } @Test - void sub_FirstNegativeSecondPositive_Ok() { + void calculate_subFirstNegativeSecondPositive_Ok() { firstValue = -1; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -187,7 +187,7 @@ void sub_FirstNegativeSecondPositive_Ok() { } @Test - void sub_FirstPositiveSecondNegative_Ok() { + void calculate_subFirstPositiveSecondNegative_Ok() { firstValue = 1; secondValue = -4; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -196,7 +196,7 @@ void sub_FirstPositiveSecondNegative_Ok() { } @Test - void sub_TwoZero_Ok() { + void calculate_subTwoZero_Ok() { firstValue = 0; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -205,7 +205,7 @@ void sub_TwoZero_Ok() { } @Test - void sub_FirstZero_Ok() { + void calculate_subFirstZero_Ok() { firstValue = 0; secondValue = 3; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -214,7 +214,7 @@ void sub_FirstZero_Ok() { } @Test - void sub_SecondZero_Ok() { + void calculate_subSecondZero_Ok() { firstValue = -4; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -223,7 +223,7 @@ void sub_SecondZero_Ok() { } @Test - void sub_FirstPositiveSecondMin_Ok() { + void calculate_subFirstPositiveSecondMin_Ok() { firstValue = 1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -232,7 +232,7 @@ void sub_FirstPositiveSecondMin_Ok() { } @Test - void sub_FirstNegativeSecondMin_Ok() { + void calculate_subFirstNegativeSecondMin_Ok() { firstValue = -1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -241,7 +241,7 @@ void sub_FirstNegativeSecondMin_Ok() { } @Test - void sub_FirstPositiveSecondMax_Ok() { + void calculate_subFirstPositiveSecondMax_Ok() { firstValue = 1; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -250,7 +250,7 @@ void sub_FirstPositiveSecondMax_Ok() { } @Test - void sub_FirstZeroSecondMax_Ok() { + void calculate_subFirstZeroSecondMax_Ok() { firstValue = 0; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -259,7 +259,7 @@ void sub_FirstZeroSecondMax_Ok() { } @Test - void sub_FirstMaxSecondMin_Ok() { + void calculate_subFirstMaxSecondMin_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -268,7 +268,7 @@ void sub_FirstMaxSecondMin_Ok() { } @Test - void sub_TwoMax_Ok() { + void calculate_subTwoMax_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, SUBTRACTION_OPERATOR); @@ -277,7 +277,7 @@ void sub_TwoMax_Ok() { } @Test - void sub_TwoMin_Ok() { + void calculate_subTwoMin_Ok() { firstValue = Double.MIN_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue,secondValue, SUBTRACTION_OPERATOR); @@ -286,7 +286,7 @@ void sub_TwoMin_Ok() { } @Test - void multiply_TwoPositive_Ok() { + void calculate_multiplyTwoPositive_Ok() { firstValue = 5; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -295,7 +295,7 @@ void multiply_TwoPositive_Ok() { } @Test - void multiply_TwoNegative_Ok() { + void calculate_multiplyTwoNegative_Ok() { firstValue = -5; secondValue = -1; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -304,7 +304,7 @@ void multiply_TwoNegative_Ok() { } @Test - void multiply_FirstNegativeSecondPositive_Ok() { + void calculate_multiplyFirstNegativeSecondPositive_Ok() { firstValue = -1; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -313,7 +313,7 @@ void multiply_FirstNegativeSecondPositive_Ok() { } @Test - void multiply_FirstPositiveSecondNegative_Ok() { + void calculate_multiplyFirstPositiveSecondNegative_Ok() { firstValue = 1; secondValue = -4; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -322,7 +322,7 @@ void multiply_FirstPositiveSecondNegative_Ok() { } @Test - void multiply_TwoZero_Ok() { + void calculate_multiplyTwoZero_Ok() { firstValue = 0; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -331,7 +331,7 @@ void multiply_TwoZero_Ok() { } @Test - void multiply_FirstZero_Ok() { + void calculate_multiplyFirstZero_Ok() { firstValue = 0; secondValue = 3; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -340,7 +340,7 @@ void multiply_FirstZero_Ok() { } @Test - void multiply_SecondZero_Ok() { + void calculate_multiplySecondZero_Ok() { firstValue = -4; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -349,7 +349,7 @@ void multiply_SecondZero_Ok() { } @Test - void multiply_FirstPositiveSecondMin_Ok() { + void calculate_multiplyFirstPositiveSecondMin_Ok() { firstValue = 1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -358,7 +358,7 @@ void multiply_FirstPositiveSecondMin_Ok() { } @Test - void multiply_FirstNegativeSecondMin_Ok() { + void calculate_multiplyFirstNegativeSecondMin_Ok() { firstValue = -1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -367,7 +367,7 @@ void multiply_FirstNegativeSecondMin_Ok() { } @Test - void multiply_FirstPositiveSecondMax_Ok() { + void calculate_multiplyFirstPositiveSecondMax_Ok() { firstValue = 1; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -376,7 +376,7 @@ void multiply_FirstPositiveSecondMax_Ok() { } @Test - void multiply_FirstZeroSecondMax_Ok() { + void calculate_multiplyFirstZeroSecondMax_Ok() { firstValue = 0; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -385,7 +385,7 @@ void multiply_FirstZeroSecondMax_Ok() { } @Test - void multiply_FirstMaxSecondMin_Ok() { + void calculate_multiplyFirstMaxSecondMin_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -394,7 +394,7 @@ void multiply_FirstMaxSecondMin_Ok() { } @Test - void multiply_TwoMax_Ok() { + void calculate_multiplyTwoMax_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, MULTIPLICATION_OPERATOR); @@ -403,7 +403,7 @@ void multiply_TwoMax_Ok() { } @Test - void multiply_TwoMin_Ok() { + void calculate_multiplyTwoMin_Ok() { firstValue = Double.MIN_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue,secondValue, MULTIPLICATION_OPERATOR); @@ -412,7 +412,7 @@ void multiply_TwoMin_Ok() { } @Test - void divide_TwoPositive_Ok() { + void calculate_divideTwoPositive_Ok() { firstValue = 5; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -421,7 +421,7 @@ void divide_TwoPositive_Ok() { } @Test - void divide_TwoNegative_Ok() { + void calculate_divideTwoNegative_Ok() { firstValue = -5; secondValue = -1; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -430,7 +430,7 @@ void divide_TwoNegative_Ok() { } @Test - void divide_FirstNegativeSecondPositive_Ok() { + void calculate_divideFirstNegativeSecondPositive_Ok() { firstValue = -1; secondValue = 1; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -439,7 +439,7 @@ void divide_FirstNegativeSecondPositive_Ok() { } @Test - void divide_FirstPositiveSecondNegative_Ok() { + void calculate_divideFirstPositiveSecondNegative_Ok() { firstValue = 1; secondValue = -4; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -448,7 +448,7 @@ void divide_FirstPositiveSecondNegative_Ok() { } @Test - void divide_FirstPositiveSecondMin_Ok() { + void calculate_divideFirstPositiveSecondMin_Ok() { firstValue = 1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -457,7 +457,7 @@ void divide_FirstPositiveSecondMin_Ok() { } @Test - void divide_FirstNegativeSecondMin_Ok() { + void calculate_divideFirstNegativeSecondMin_Ok() { firstValue = -1; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -466,7 +466,7 @@ void divide_FirstNegativeSecondMin_Ok() { } @Test - void divide_FirstPositiveSecondMax_Ok() { + void calculate_divideFirstPositiveSecondMax_Ok() { firstValue = 1; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -475,7 +475,7 @@ void divide_FirstPositiveSecondMax_Ok() { } @Test - void divide_FirstZeroSecondMax_Ok() { + void calculate_divideFirstZeroSecondMax_Ok() { firstValue = 0; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -484,7 +484,7 @@ void divide_FirstZeroSecondMax_Ok() { } @Test - void divide_FirstMaxSecondMin_Ok() { + void calculate_divideFirstMaxSecondMin_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -493,7 +493,7 @@ void divide_FirstMaxSecondMin_Ok() { } @Test - void divide_TwoMax_Ok() { + void calculate_divideTwoMax_Ok() { firstValue = Double.MAX_VALUE; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, DIVISION_OPERATOR); @@ -502,7 +502,7 @@ void divide_TwoMax_Ok() { } @Test - void divide_TwoMin_Ok() { + void calculate_divideTwoMin_Ok() { firstValue = Double.MIN_VALUE; secondValue = Double.MIN_VALUE; actual = calculator.calculate(firstValue,secondValue, DIVISION_OPERATOR); @@ -511,7 +511,7 @@ void divide_TwoMin_Ok() { } @Test - void divide_FirstPositiveSecondZero_OK() { + void calculate_divideFirstPositiveSecondZero_OK() { firstValue = 1; secondValue = 0; assertThrows(ArithmeticException.class, () -> { @@ -520,7 +520,7 @@ void divide_FirstPositiveSecondZero_OK() { } @Test - void divide_FirstNegativeSecondZero_OK() { + void calculate_divideFirstNegativeSecondZero_OK() { firstValue = -1; secondValue = 0; assertThrows(ArithmeticException.class, () -> { @@ -529,7 +529,7 @@ void divide_FirstNegativeSecondZero_OK() { } @Test - void divide_FirstMaxSecondZero_OK() { + void calculate_divideFirstMaxSecondZero_OK() { firstValue = Double.MAX_VALUE; secondValue = 0; assertThrows(ArithmeticException.class, () -> { @@ -538,7 +538,7 @@ void divide_FirstMaxSecondZero_OK() { } @Test - void divide_FirstMinSecondZero_OK() { + void calculate_divideFirstMinSecondZero_OK() { firstValue = Double.MIN_VALUE; secondValue = 0; assertThrows(ArithmeticException.class, () -> { @@ -547,7 +547,7 @@ void divide_FirstMinSecondZero_OK() { } @Test - void raising_FirstPositiveSecondPositive_OK() { + void calculate_raisingFirstPositiveSecondPositive_OK() { firstValue = 5.5; secondValue = 4; actual = calculator.calculate(firstValue,secondValue,RAISING_TO_POWER_OPERATOR); @@ -556,7 +556,7 @@ void raising_FirstPositiveSecondPositive_OK() { } @Test - void raising_FirstNegativeSecondPositive_Ok() { + void calculate_raisingFirstNegativeSecondPositive_Ok() { firstValue = -1.1; secondValue = 3; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -565,7 +565,7 @@ void raising_FirstNegativeSecondPositive_Ok() { } @Test - void raising_PositiveToNegative_Ok() { + void calculate_raisingPositiveToNegative_Ok() { firstValue = 1; secondValue = -1.5; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -574,7 +574,7 @@ void raising_PositiveToNegative_Ok() { } @Test - void raising_NegativeToNegative_Ok() { + void calculate_raisingNegativeToNegative_Ok() { firstValue = -1; secondValue = -5; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -583,7 +583,7 @@ void raising_NegativeToNegative_Ok() { } @Test - void raising_PositiveToZero_OK() { + void calculate_raisingPositiveToZero_OK() { firstValue = 1; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -592,7 +592,7 @@ void raising_PositiveToZero_OK() { } @Test - void raising_NegativeToZero_OK() { + void calculate_raisingNegativeToZero_OK() { firstValue = -2; secondValue = 0; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -601,7 +601,7 @@ void raising_NegativeToZero_OK() { } @Test - void raising_ZeroToPositive_Ok() { + void calculate_raisingZeroToPositive_Ok() { firstValue = 0; secondValue = 8; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -610,7 +610,7 @@ void raising_ZeroToPositive_Ok() { } @Test - void raising_ZeroToNegative_Ok() { + void calculate_raisingZeroToNegative_Ok() { firstValue = 0; secondValue = -3; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -619,7 +619,7 @@ void raising_ZeroToNegative_Ok() { } @Test - void raising_ZeroToMax_OK() { + void calculate_raisingZeroToMax_OK() { firstValue = 0; secondValue = Double.MAX_VALUE; actual = calculator.calculate(firstValue, secondValue, RAISING_TO_POWER_OPERATOR); @@ -628,7 +628,7 @@ void raising_ZeroToMax_OK() { } @Test - void raising_ZeroToMin_Ok() { + void calculate_raisingZeroToMin_Ok() { firstValue = -2; secondValue = Double.MIN_VALUE; assertThrows(IllegalValueException.class, () -> {