Add calculator core: constants, operations and tests

MIL-002 Calculator core.

- Add constants.py with operation symbols, answers, prompts, messages
  and the ASCII title and calculator
- Add add, subtract, multiply and divide, and the OPERATIONS dictionary
  that maps each symbol to its function without calling it
- Add tests for each operation, division by zero and the dictionary

Closes #19
Closes #20
Closes #21

Task: MIL-002#1
Task: MIL-002#2
Task: MIL-002#3
This commit is contained in:
2026-10-04 20:49:38 +08:00
parent c90e5afb7c
commit 5e1067b4f3
3 changed files with 153 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
"""!
@file test_operations.py
@brief Tests for the arithmetic operations.
"""
import pytest
from calc.operations import OPERATIONS, add, divide, multiply, subtract
def test_add_returns_sum() -> None:
assert add(2, 3) == 5
def test_subtract_returns_difference() -> None:
assert subtract(2, 3) == -1
def test_multiply_returns_product() -> None:
assert multiply(4, 2.5) == 10
def test_divide_returns_quotient() -> None:
assert divide(9, 3) == 3
def test_divide_when_divisor_is_zero() -> None:
with pytest.raises(ZeroDivisionError):
divide(1, 0)
def test_operations_maps_symbols_to_functions() -> None:
assert OPERATIONS == {"+": add, "-": subtract, "*": multiply, "/": divide}