Created a calculator and wrote tests for it#291
Conversation
| return getTheExponentiationResult(firstNumber, secondNumber); | ||
| default: | ||
| throw new NoSuchElementException("Incorrect operation"); | ||
|
|
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class CalculateTest { | ||
| private static final Calculate calculate = new Calculate(); |
There was a problem hiding this comment.
Let's rename this constant, because when we write calculate.calculate it's confusing. And also constants should be with only uppercase chars and _.
|
|
||
| @Test | ||
| void additionWithTwoPositiveOperands_Ok() { | ||
| double actual = calculate.calculate(6, 8, Calculate.PLUS); |
There was a problem hiding this comment.
Let's create fields answer and actual in class and in tests we only initialize them
| double actual = calculate.calculate(0, 8, Calculate.PLUS); | ||
| double answer = 8; | ||
| assertEquals(answer,actual); | ||
|
|
There was a problem hiding this comment.
I don't think that it is good to use whitespaces between tests in one method. Maybe is not a mistake, and that is more readable, better to ask a mentor.
There was a problem hiding this comment.
Agree, lets remove redundant empty lines
| case EXPONENTIATION: | ||
| return getTheExponentiationResult(firstNumber, secondNumber); | ||
| default: | ||
| throw new NoSuchElementException("Incorrect operation"); |
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class CalculateTest { | ||
| private static final Calculate CALCULATOR = new Calculate(); |
There was a problem hiding this comment.
I dont think we should make calculator as constant. Lets make it as private static variable and initialize it in @BeforeAll method
| class CalculateTest { | ||
| private static final Calculate CALCULATOR = new Calculate(); | ||
| private double actual; | ||
| private double answer; |
There was a problem hiding this comment.
| private double answer; | |
| private double expected; | |
answer less informative name
| private double answer; | ||
|
|
||
| @Test | ||
| void additionWithTwoPositiveOperands_Ok() { |
There was a problem hiding this comment.
Let's name our methods based on the pattern <methodUnderTest>_<state>_<expectedBehavior>
| double actual = calculate.calculate(0, 8, Calculate.PLUS); | ||
| double answer = 8; | ||
| assertEquals(answer,actual); | ||
|
|
There was a problem hiding this comment.
Agree, lets remove redundant empty lines
| actual = CALCULATOR.calculate(-6, 8, Calculate.MINUS); | ||
| answer = -14; | ||
| assertEquals(answer, actual); |
There was a problem hiding this comment.
we can add to this test check for first negative and second positive operands
| import java.util.NoSuchElementException; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class CalculateTest { |
There was a problem hiding this comment.
what about addition for min and max double values;?

No description provided.