Skip to content

added calculator solution#286

Open
andrii-demchenko wants to merge 3 commits into
mate-academy:masterfrom
andrii-demchenko:lambda
Open

added calculator solution#286
andrii-demchenko wants to merge 3 commits into
mate-academy:masterfrom
andrii-demchenko:lambda

Conversation

@andrii-demchenko
Copy link
Copy Markdown

No description provided.

return firstValue * secondValue;
}
case '/' : {
if (secondValue == 0) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Division by zero is not always forbidden.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

Comment on lines +49 to +51
assertEquals(expectedFirstZero, actualFirstZero);
assertEquals(expectedSecondZero, actualSecondZero);
assertEquals(expectedBothZero, actualBothZero);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not sure that we should use few assertions in one test.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

As i can see multiple assertions are used in tests from previous homeworks, so I decided to use them too.

Comment on lines +179 to +183
void multiplyTwoMinNumbers_Ok() {
actual = calculatorService.calculate(Double.MIN_VALUE, Double.MIN_VALUE, '-');
expected = 0;
assertEquals(expected, 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.

How do we denote multiplication?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed, didn't notice it. Thank you.

Comment on lines +248 to +252
void raiseNegativeNumberToNegativePower_Ok() {
actual = calculatorService.calculate(-4, -2, '^');
expected = 0.0625;
assertEquals(expected, 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.

Maybe we should use delta in such cases?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Worked fine for me without delta, but added it anyway

Copy link
Copy Markdown

@lavrivskyi lavrivskyi left a comment

Choose a reason for hiding this comment

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

Looks good.

return firstValue * secondValue;
}
case '/' : {
if (firstValue != 0.0d && secondValue == 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (firstValue != 0.0d && secondValue == 0) {
if (firstValue != 0 && secondValue == 0) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

double actualBothZero = calculatorService.calculate(0, 0, '+');
double expectedFirstZero = 5;
double expectedSecondZero = 50;
double expectedBothZero = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you have expected variable. you can reassign value after each assertion

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

void additionWithZero_Ok() {
double actualFirstZero = calculatorService.calculate(0, 5, '+');
double actualSecondZero = calculatorService.calculate(50, 0, '+');
double actualBothZero = calculatorService.calculate(0, 0, '+');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same with actual

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

}

@Test
void addTwoPositiveNumbers_Ok() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what method co we test?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

Comment on lines +57 to +59
actual = calculatorService.calculate(0, 0, '+');
expected = 55;
assertNotEquals(expected, actual);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what is this test? how should it fail?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

Comment on lines +110 to +115
@Test
void subtractTwoZeroNumbers_NotOk() {
actual = calculatorService.calculate(0, 0, '-');
expected = 5555;
assertNotEquals(expected, actual);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

}

@Test
void raisingNegativeToZeroPower_Ok() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what about zeroToNegativePower?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

added new test

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