Skip to content

implemented method Calculate and created tests#303

Open
mykolaskrypka wants to merge 2 commits into
mate-academy:masterfrom
mykolaskrypka:hw-1
Open

implemented method Calculate and created tests#303
mykolaskrypka wants to merge 2 commits into
mate-academy:masterfrom
mykolaskrypka:hw-1

Conversation

@mykolaskrypka
Copy link
Copy Markdown

No description provided.

Comment on lines +225 to +228
void illegal_operation() {
try {
calculator.calculate(posA, posB, '?');
} catch (IllegalOperationException e) {
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
void illegal_operation() {
try {
calculator.calculate(posA, posB, '?');
} catch (IllegalOperationException e) {
void illegal_operation() {
char illegalOperation = '?'
try {
calculator.calculate(posA, posB, illegalOperation);
} catch (IllegalOperationException e) {

для кращої читаймості неочевидні речі краще в неймінгу вказувати

@@ -0,0 +1,7 @@
package exceptions;

public class IllegalOperationException extends Exception {
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.

тут краще unchecked ексепшин робити, нам нема сенсу змушувати юзера всюди покривати виклики в трай кетч

@Test
void power_negative() throws IllegalOperationException {
double expected = Math.pow(negA, negB);
Double actual = calculator.calculate(negA, negB, '^');
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.

чому тут Double обгортка?

void adition_positive() throws IllegalOperationException {
double expected = posA + posB;
Double actual = calculator.calculate(posA, posB, '+');
Assertions.assertEquals(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.

при порівняння чисел з плаваючою точкою краще дельту використовувати, наприклад
...equals(expected, actual, 0.0001) щоб задавати точність

private final double zero = 0;
private final double minDouble = Double.MIN_VALUE;
private final double maxDouble = Double.MAX_VALUE;
private final double accuracy = 0.0001;
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
private final double accuracy = 0.0001;
private static final double DELTA = 0.0001;

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.

2 participants