-
Notifications
You must be signed in to change notification settings - Fork 131
Feat: calculator implementation #305
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
SimoneAvellino
wants to merge
6
commits into
UNICT-Quality-Development:main
Choose a base branch
from
SimoneAvellino:calculator
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 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
69bc11c
feat: implement basic arithmetic operations with enum support
SimoneAvellino 3765f38
feat: refactor operation handling and add unit tests for calculator
SimoneAvellino ade9ff7
refactor: enhance type hints and error handling in calculator operations
SimoneAvellino 6c86e91
refactorx: solved pylint errors
SimoneAvellino 32a4350
fix(tests): add missing newline at end of test_calculator.py
SimoneAvellino 3e81c12
fix(tests): simplify exception handling in test_calculator_operations
SimoneAvellino 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
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,44 @@ | ||
| from src.calculator import operation, OperationType | ||
|
|
||
| def test_calculator_operations() -> None: | ||
| assert operation(4, 2, op=OperationType.SUM) == 6 # SUM | ||
| assert operation(4, 2, op=OperationType.DIFFERENCE) == 2 # DIFFERENCE | ||
| assert operation(4, 2, op=OperationType.MULTIPLICATION) == 8 # MULTIPLICATION | ||
| assert operation(4, 2, op=OperationType.DIVISION) == 2 # DIVISION | ||
| try: | ||
| operation(4, 0, op=OperationType.DIVISION) | ||
| except ValueError as e: | ||
| assert str(e) == "Error: Division by zero" # DIVISION by zero | ||
| try: | ||
| operation(4, 2, op=None) # Invalid operation | ||
| except ValueError as e: | ||
| assert str(e) == "Invalid operation" | ||
|
|
||
| def test_calculator_main() -> None: | ||
| import builtins | ||
| import io | ||
| import sys | ||
Helias marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| input_values = ["4", "2"] | ||
| output = io.StringIO() | ||
| sys.stdout = output | ||
|
|
||
| def mock_input(s): | ||
| return input_values.pop(0) | ||
|
|
||
| builtins.input = mock_input | ||
|
|
||
| # Re-import the main module to run the main function | ||
| import src.calculator as calculator_module | ||
|
|
||
| # Restore stdout | ||
| sys.stdout = sys.__stdout__ | ||
|
|
||
| expected_output = ( | ||
| "Insert first number: Insert second number: SUM: 6.0\n" | ||
| "Difference: 2.0\n" | ||
| "Multiplication: 8.0\n" | ||
| "Division: 2.0\n" | ||
| ) | ||
|
|
||
| assert output.getvalue() == expected_output | ||
Helias marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.