-
Notifications
You must be signed in to change notification settings - Fork 0
Low Test Coverage: calculator.py #4
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
hiroshinishio
wants to merge
8
commits into
main
Choose a base branch
from
gitauto/dashboard-20260226-203013-4plx
base: main
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
8 commits
Select commit
Hold shift + click to select a range
c1564d9
Initial empty commit to create PR [skip ci]
hiroshinishio d878b71
Update test_calculator.py [skip ci]
gitauto-ai[bot] 0c17abe
Replace content of test_calculator.py [skip ci]
gitauto-ai[bot] 1cc6c11
Replace content of test_calculator.py [skip ci]
gitauto-ai[bot] 9b0e724
Empty commit to trigger final tests
gitauto-ai[bot] 52b1e36
Update test_calculator.py [skip ci]
gitauto-ai[bot] 124ecba
Replace content of test_calculator.py [skip ci]
gitauto-ai[bot] 43bb57c
Empty commit to trigger final tests
gitauto-ai[bot] 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,120 @@ | ||
| # pylint: disable=redefined-outer-name, unused-argument | ||
| from unittest.mock import patch | ||
|
|
||
| from calculator import add, divide, main, multiply, subtract | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| class TestAdd: | ||
| def test_positive_numbers(self): | ||
| assert add(2, 3) == 5 | ||
|
|
||
| def test_negative_numbers(self): | ||
| assert add(-1, -2) == -3 | ||
|
|
||
| def test_mixed_sign(self): | ||
| assert add(-1, 3) == 2 | ||
|
|
||
| def test_zeros(self): | ||
| assert add(0, 0) == 0 | ||
|
|
||
| def test_floats(self): | ||
| assert add(1.5, 2.5) == 4.0 | ||
|
|
||
|
|
||
| class TestSubtract: | ||
| def test_positive_numbers(self): | ||
| assert subtract(5, 3) == 2 | ||
|
|
||
| def test_negative_result(self): | ||
| assert subtract(3, 5) == -2 | ||
|
|
||
| def test_zeros(self): | ||
| assert subtract(0, 0) == 0 | ||
|
|
||
| def test_floats(self): | ||
| assert subtract(5.5, 2.5) == 3.0 | ||
|
|
||
|
|
||
| class TestMultiply: | ||
| def test_positive_numbers(self): | ||
| assert multiply(3, 4) == 12 | ||
|
|
||
| def test_by_zero(self): | ||
| assert multiply(5, 0) == 0 | ||
|
|
||
| def test_negative_numbers(self): | ||
| assert multiply(-2, -3) == 6 | ||
|
|
||
| def test_mixed_sign(self): | ||
| assert multiply(-2, 3) == -6 | ||
|
|
||
| def test_floats(self): | ||
| assert multiply(2.5, 4) == 10.0 | ||
|
|
||
|
|
||
| class TestDivide: | ||
| def test_even_division(self): | ||
| assert divide(10, 2) == 5.0 | ||
|
|
||
| def test_fractional_result(self): | ||
| assert divide(7, 2) == 3.5 | ||
|
|
||
| def test_repeating_decimal(self): | ||
| assert divide(10, 3) == pytest.approx(10 / 3) | ||
|
|
||
| def test_divide_by_zero_raises(self): | ||
| with pytest.raises(ValueError, match="Cannot divide by zero"): | ||
| divide(1, 0) | ||
|
|
||
| def test_negative_numbers(self): | ||
| assert divide(-6, 3) == -2.0 | ||
|
|
||
| def test_zero_numerator(self): | ||
| assert divide(0, 5) == 0.0 | ||
|
|
||
|
|
||
| class TestMain: | ||
| @patch("builtins.input", side_effect=["5", "+", "3"]) | ||
| @patch("builtins.print") | ||
| def test_addition_operation(self, mock_print, _mock_input): | ||
| main() | ||
| mock_print.assert_any_call("5.0 + 3.0 = 8.0") | ||
|
|
||
| @patch("builtins.input", side_effect=["10", "-", "4"]) | ||
| @patch("builtins.print") | ||
| def test_subtraction_operation(self, mock_print, _mock_input): | ||
| main() | ||
| mock_print.assert_any_call("10.0 - 4.0 = 6.0") | ||
|
|
||
| @patch("builtins.input", side_effect=["3", "*", "7"]) | ||
| @patch("builtins.print") | ||
| def test_multiplication_operation(self, mock_print, _mock_input): | ||
| main() | ||
| mock_print.assert_any_call("3.0 * 7.0 = 21.0") | ||
|
|
||
| @patch("builtins.input", side_effect=["8", "/", "2"]) | ||
| @patch("builtins.print") | ||
| def test_division_operation(self, mock_print, _mock_input): | ||
| main() | ||
| mock_print.assert_any_call("8.0 / 2.0 = 4.0") | ||
|
|
||
| @patch("builtins.input", side_effect=["10", "/", "3"]) | ||
| @patch("builtins.print") | ||
| def test_division_repeating_decimal_operation(self, mock_print, _mock_input): | ||
| main() | ||
| mock_print.assert_any_call(f"10.0 / 3.0 = {10.0 / 3.0}") | ||
|
|
||
| @patch("builtins.input", side_effect=["5", "%", "3"]) | ||
| @patch("builtins.print") | ||
| def test_unknown_operation(self, mock_print, _mock_input): | ||
| main() | ||
| mock_print.assert_any_call("Unknown operation: %") | ||
|
|
||
| @patch("builtins.input", side_effect=["5", "+", "3"]) | ||
| @patch("builtins.print") | ||
| def test_prints_header(self, mock_print, _mock_input): | ||
| main() | ||
| mock_print.assert_any_call("Simple Calculator") | ||
| mock_print.assert_any_call("Operations: +, -, *, /") |
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.
test patterns you cant divide like 10 / 3 too
Uh oh!
There was an error while loading. Please reload this page.
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.
Resolved your feedback! Looks good?