A Python calculator implementation with comprehensive test coverage and input validation. This Calculator can handle the values up to 1000000 (Not implemented yet on purpose)
- Basic Operations: Addition, subtraction, multiplication, division
- Fork and Clone the repository:
git clone https://github.com/Yutaro-Kashiwa/SystemDevelopment5th.git
cd SystemDevelopment5th- Create a virtual environment:
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies:
pip install pytest pytest-covfrom src.calculator.calculator import Calculator
# Create calculator instance
calc = Calculator()
# Basic operations
result = calc.add(5, 3) # 8
result = calc.subtract(10, 3) # 7
result = calc.multiply(4, 5) # 20
result = calc.divide(10, 2) # 5.0
# Advanced operations
result = calc.power(2, 3) # 8
result = calc.square_root(16) # 4.0
result = calc.modulo(10, 3) # 1pytest tests/pytest tests/test_calculator.py -vpytest --cov=src --cov-report=html tests/View the HTML report:
start htmlcov/index.htmlSystemDevelopment5th/
├── src/
│ └── calculator/
│ ├── __init__.py
│ └── calculator.py # Calculator implementation
├── tests/
│ ├── __init__.py
│ └── test_calculator.py # Test suite (67 tests)
├── .gitignore
├── .coveragerc # Coverage configuration
├── setup.cfg # Project configuration
└── README.md
add(a, b)
- Adds two numbers
- Raises
InvalidInputExceptionif inputs are outside valid range - Returns: Sum of a and b
subtract(a, b)
- Subtracts b from a
- Raises
InvalidInputExceptionif inputs are outside valid range - Returns: Difference of a and b
multiply(a, b)
- Multiplies two numbers
- Raises
InvalidInputExceptionif inputs are outside valid range - Returns: Product of a and b
divide(a, b)
- Divides a by b
- Raises
InvalidInputExceptionif inputs are outside valid range - Raises
ValueErrorif b is zero - Returns: Quotient of a and b
MAX_VALUE = 1000000: Maximum allowed input valueMIN_VALUE = -1000000: Minimum allowed input value
InvalidInputException
- Raised when input values are outside the valid range [-1000000, 1000000]
- Inherits from
Exception
The project follows Python best practices:
- Comprehensive docstrings for all methods
- Type hints where applicable
- Error handling for edge cases
- Input validation
- AAA test pattern
- Python 3.12+
- pytest 9.0+
- pytest-cov 7.0+
This project is for educational purposes.
Contributions are welcome! Please ensure:
- All tests pass
- New features include tests
- Tests follow AAA pattern
- Code includes proper documentation
Yutaro Kashiwa