-
Notifications
You must be signed in to change notification settings - Fork 257
jv-lambda-calc task completed #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Gleb-Kreshchuk
wants to merge
6
commits into
mate-academy:master
Choose a base branch
from
Gleb-Kreshchuk:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
94dcd83
Task completed according requirements
Gleb-Kreshchuk ccb7025
Task completed according requirements
Gleb-Kreshchuk b051fa0
Task completed according requirements
Gleb-Kreshchuk 31bf680
Merge remote-tracking branch 'origin/master'
Gleb-Kreshchuk b6574b8
jv-lambda-calculator task completed
Gleb-Kreshchuk f7c8672
Merge remote-tracking branch 'origin/master'
Gleb-Kreshchuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package core.basesyntax; | ||
|
|
||
| public interface Calculate { | ||
| double calculate(double a, double b, char c); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package core.basesyntax; | ||
|
|
||
| public class Calculator implements Calculate { | ||
|
|
||
| @Override | ||
| public double calculate(double firstParameter, double secondParameter, char operation) { | ||
| switch (operation) { | ||
| case '+': | ||
| return firstParameter + secondParameter; | ||
| case '-': | ||
| return firstParameter - secondParameter; | ||
| case '*': | ||
| return firstParameter * secondParameter; | ||
| case '^': | ||
| return Math.pow(firstParameter, secondParameter); | ||
| case '/': | ||
| if (secondParameter == 0) { | ||
| throw new ArithmeticException("Division by zero is not allowed."); | ||
| } | ||
| return firstParameter / secondParameter; | ||
| default: | ||
| throw new IllegalArgumentException("Invalid operation"); | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| package core.basesyntax; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class CalculatorTest { | ||
| private static final double DELTA = 0.0001; | ||
| private Calculate calculator = new Calculator(); | ||
| private double expected; | ||
| private double actual; | ||
|
|
||
| @Test | ||
| void calculate_additionWithTwoPositiveOperands_Ok() { | ||
| expected = 100.0; | ||
| actual = calculator.calculate(90.0, 10.0, '+'); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_additionWithTwoNegativeOperands_Ok() { | ||
| expected = - 150.0; | ||
| actual = calculator.calculate(-100.0, -50.0, '+'); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_additionWithPositiveAndNegativeOperands_Ok() { | ||
| expected = - 150.0; | ||
| actual = calculator.calculate(-200.0, 50.0, '+'); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_additionWithFirstOperandIsZero_Ok() { | ||
| expected = 50.0; | ||
| actual = calculator.calculate(0.0, 50.0, '+'); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_additionWithSecondOperandIsZero_Ok() { | ||
| expected = 60.0; | ||
| actual = calculator.calculate(60.0, 0.0, '+'); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_additionWithMinAndMaxDoubleValues_Ok() { | ||
| expected = Double.MAX_VALUE + Double.MIN_VALUE; | ||
| actual = calculator.calculate(Double.MAX_VALUE, Double.MIN_VALUE, '+'); | ||
| assertEquals(expected, actual, DELTA); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_subtractionWithMinAndMaxDoubleValues_Ok() { | ||
| expected = Double.MAX_VALUE - Double.MIN_VALUE; | ||
| actual = calculator.calculate(Double.MAX_VALUE, Double.MIN_VALUE, '-'); | ||
| assertEquals(expected, actual, DELTA); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_multiplicationWithMinAndMaxDoubleValues_Ok() { | ||
| expected = Double.MAX_VALUE * Double.MIN_VALUE; | ||
| actual = calculator.calculate(Double.MAX_VALUE, Double.MIN_VALUE, '*'); | ||
| assertEquals(expected, actual, DELTA); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_divisionWithMinAndMaxDoubleValues_Ok() { | ||
| expected = Double.MAX_VALUE / Double.MIN_VALUE; | ||
| actual = calculator.calculate(Double.MAX_VALUE, Double.MIN_VALUE, '/'); | ||
| assertEquals(expected, actual, DELTA); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_divisionByZero_NotOk() { | ||
| assertThrows(ArithmeticException.class, () -> { | ||
| calculator.calculate(2.0, 0.0, '/'); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_raisingPositiveValueToThePositivePower_Ok() { | ||
| expected = 64.0; | ||
| actual = calculator.calculate(8.0, 2.0, '^'); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_raisingNegativeValueToThePositivePower_Ok() { | ||
| expected = 64.0; | ||
| actual = calculator.calculate(-8.0, 2.0, '^'); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_raisingPositiveValueToTheNegativePower_Ok() { | ||
| expected = 0.015625; | ||
| actual = calculator.calculate(8.0, -2.0, '^'); | ||
| assertEquals(expected, actual, DELTA); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_raisingNegativeValueToTheNegativePower_Ok() { | ||
| expected = 0.015625; | ||
| actual = calculator.calculate(-8.0, -2.0, '^'); | ||
| assertEquals(expected, actual, DELTA); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_raisingPositiveValueToZeroPower_Ok() { | ||
| expected = 1.0; | ||
| actual = calculator.calculate(8.0, 0.0, '^'); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_raisingNegativeValueToZeroPower_Ok() { | ||
| expected = 1.0; | ||
| actual = calculator.calculate(-8.0, 0.0, '^'); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_raisingZeroToPower_Ok() { | ||
| expected = 0.0; | ||
| actual = calculator.calculate(0.0, 10.0, '^'); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| void calculate_raisingZeroToNegativePower() { | ||
| expected = Double.POSITIVE_INFINITY; | ||
| actual = calculator.calculate(0, -2, '^'); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| void illegalOperation_NotOk() { | ||
| assertThrows(IllegalArgumentException.class, () -> { | ||
| calculator.calculate(2.0, 3.0, '#'); | ||
| }); | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а что если первый операнд 0, а второй -2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
добавлена проверка Double.POSITIVE_INFINITY