Skip to content

Created a calculator and wrote tests for it#291

Open
ivashchenko5 wants to merge 4 commits into
mate-academy:masterfrom
ivashchenko5:hw-jv-lambda-calculate
Open

Created a calculator and wrote tests for it#291
ivashchenko5 wants to merge 4 commits into
mate-academy:masterfrom
ivashchenko5:hw-jv-lambda-calculate

Conversation

@ivashchenko5
Copy link
Copy Markdown

No description provided.

Comment thread src/main/java/Calculate.java Outdated
return getTheExponentiationResult(firstNumber, secondNumber);
default:
throw new NoSuchElementException("Incorrect operation");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need whitespace here

Comment thread src/test/java/CalculateTest.java Outdated
import org.junit.jupiter.api.Test;

class CalculateTest {
private static final Calculate calculate = new Calculate();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this constant, because when we write calculate.calculate it's confusing. And also constants should be with only uppercase chars and _.

Comment thread src/test/java/CalculateTest.java Outdated

@Test
void additionWithTwoPositiveOperands_Ok() {
double actual = calculate.calculate(6, 8, Calculate.PLUS);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, lets remove redundant empty lines

Comment thread src/main/java/Calculate.java Outdated
case EXPONENTIATION:
return getTheExponentiationResult(firstNumber, secondNumber);
default:
throw new NoSuchElementException("Incorrect operation");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe IllegalArgumentException would be better here?
image

Comment thread src/test/java/CalculateTest.java Outdated
import org.junit.jupiter.api.Test;

class CalculateTest {
private static final Calculate CALCULATOR = new Calculate();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we should make calculator as constant. Lets make it as private static variable and initialize it in @BeforeAll method

Comment thread src/test/java/CalculateTest.java Outdated
class CalculateTest {
private static final Calculate CALCULATOR = new Calculate();
private double actual;
private double answer;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private double answer;
private double expected;

answer less informative name

Comment thread src/test/java/CalculateTest.java Outdated
private double answer;

@Test
void additionWithTwoPositiveOperands_Ok() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, lets remove redundant empty lines

Comment thread src/test/java/CalculateTest.java Outdated
Comment on lines +64 to +66
actual = CALCULATOR.calculate(-6, 8, Calculate.MINUS);
answer = -14;
assertEquals(answer, actual);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about addition for min and max double values;?

Copy link
Copy Markdown

@MaliukDaria MaliukDaria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis failed....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants