Skip to content

add calc+test#2

Open
TarasHryts wants to merge 4 commits into
mate-academy:masterfrom
TarasHryts:hw-291
Open

add calc+test#2
TarasHryts wants to merge 4 commits into
mate-academy:masterfrom
TarasHryts:hw-291

Conversation

@TarasHryts

Copy link
Copy Markdown

No description provided.


@Test(expected = IllegalArgumentException.class)
public void checkIllegalArg() {
double number1 = Math.random();

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.

can we use random values in tests?

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.

done

Assert.assertEquals(expected, actual, 0);
expected = number1 - number2;
actual = calculator.calculate(number1, number2, '3');
Assert.assertEquals(expected, actual, 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.

чи потрібні нам наступні тестові дані, якщо перший уже викине помилку

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.

deleted, done


@Test
public void checkNotCorrectOperation() {
double number1 = Math.random();

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 the purpose of this 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.

we do not need it, deleted done

expected = Math.pow(number1, number2);
actual = calculator.calculate(number1, number2, '^');
Assert.assertEquals(actual, expected, 0);
number1 = -Math.random();

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.

better divide this test into two separate with positive and negative numbers

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.

done

expected = number1 * number2;
actual = calculator.calculate(number1, number2, '*');
Assert.assertEquals(actual, expected, 0);
expected = number1 / number2;

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.

will we have excaption here?

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.

no, the result will be infinity


@Test
public void CheckNullPointer() {
Double number1 = null;

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 this 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.

changed

Double number2 = null;

}
} No newline at end of file

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.

add a blank line

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.

done

import org.junit.Test;

public class CalculatorTest {
private Calculator calculator = new Calculator();

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.

create before

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.

done


@Test
public void checkCorrectNegative() {
double number1 = -Math.random();

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.

remove Math.random()

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.

removed

@Test(expected = NullPointerException.class)
public void CheckNullPointer() {

Double number1 = 1.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.

?

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.

deleted

import org.junit.Test;

public class CalculatorTest {
Calculator calculator = null;

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.

add access modifier

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.

done

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