A calculator library with multiple bugs for educational purposes. Students should clone this repository and fix all the issues.
- File:
calculator.py-add()function - Problem: The
add()function incorrectly handles negative numbers by using absolute values - Expected:
add(-2, 3)should return1, not5 - Test:
test_negative_numbersinTestAddclass
- File:
calculator.py-multiply()function - Problem: Uses slow iterative approach for large numbers
- Expected: Should use direct multiplication operator
* - Test:
test_large_numbersinTestMultiplyclass
- File:
calculator.py-divide()function - Problem: Returns
infinstead of raising an exception for division by zero - Expected: Should raise
ValueErrorwith message "Cannot divide by zero" - Test:
test_division_by_zeroinTestDivideclass
- File:
calculator.py-power()function - Problem: Recursive call with negative exponent causes infinite recursion
- Expected: Should handle negative exponents correctly
- Test:
test_negative_exponentinTestPowerclass
- File:
calculator.py-factorial()function - Problem: Returns
-1for negative inputs instead of raising exception - Expected: Should raise
ValueErrorfor negative inputs - Test:
test_negative_numbersinTestFactorialclass
- File:
calculator.py-is_prime()function - Problem: Inefficient and may have logical errors
- Expected: Should correctly identify prime numbers
- Tests: All tests in
TestIsPrimeclass
- Clone the repository:
git clone <repository-url>
cd calculator-multi-issues