test(sveta): Write tests for multiply and divide
Outcome: done
Changed: tests/test_calculator.py:1-65, Makefile:1
Verified by: `make verify` — exit 0, "Ran 16 tests in 0.000s ... OK"
Findings: tests/test_calculator.py exists with 16 test methods covering add, subtract, multiply (positive/negative/zero), divide (positive/negative/zero-numerator/floor), and divide-by-zero ValueError.
make verify now runs both compileall (src + tests) and unittest discover, all passing.
Open: none
Confidence: high — all 16 tests pass; coverage spans all acceptance criteria including multiply edge cases (positive, negative, zero) and divide edge cases (positive, negative, zero numerator, divide-by-zero).
Typosaurus-Run: d9404e45783a42b586e07fc0342eee5c
Typosaurus-Node: 00f8d57fc2964dc9bf5ae68ad25a6e18
Typosaurus-Agent: @sveta
Refs: #2
This commit is contained in:
parent
3f2a5c8a07
commit
8f7f09f44a
2
Makefile
2
Makefile
@ -1,2 +1,2 @@
|
||||
verify:
|
||||
@python3 -m compileall -q src && echo "verification passed"
|
||||
@python3 -m compileall -q src tests && python3 -m unittest discover -s tests -q && echo "verification passed"
|
||||
|
||||
BIN
tests/__pycache__/test_calculator.cpython-315.pyc
Normal file
BIN
tests/__pycache__/test_calculator.cpython-315.pyc
Normal file
Binary file not shown.
58
tests/test_calculator.py
Normal file
58
tests/test_calculator.py
Normal file
@ -0,0 +1,58 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
import unittest
|
||||
|
||||
from src.calculator import add, subtract, multiply, divide
|
||||
|
||||
|
||||
class TestCalculator(unittest.TestCase):
|
||||
|
||||
def test_add(self) -> None:
|
||||
self.assertEqual(add(2, 3), 5)
|
||||
|
||||
def test_subtract(self) -> None:
|
||||
self.assertEqual(subtract(5, 3), 2)
|
||||
|
||||
def test_multiply_positive(self) -> None:
|
||||
self.assertEqual(multiply(2, 3), 6)
|
||||
|
||||
def test_multiply_negative_left(self) -> None:
|
||||
self.assertEqual(multiply(-2, 3), -6)
|
||||
|
||||
def test_multiply_negative_right(self) -> None:
|
||||
self.assertEqual(multiply(2, -3), -6)
|
||||
|
||||
def test_multiply_both_negative(self) -> None:
|
||||
self.assertEqual(multiply(-2, -3), 6)
|
||||
|
||||
def test_multiply_zero_left(self) -> None:
|
||||
self.assertEqual(multiply(0, 5), 0)
|
||||
|
||||
def test_multiply_zero_right(self) -> None:
|
||||
self.assertEqual(multiply(5, 0), 0)
|
||||
|
||||
def test_multiply_both_zero(self) -> None:
|
||||
self.assertEqual(multiply(0, 0), 0)
|
||||
|
||||
def test_divide_positive(self) -> None:
|
||||
self.assertEqual(divide(6, 3), 2)
|
||||
|
||||
def test_divide_negative_left(self) -> None:
|
||||
self.assertEqual(divide(-6, 3), -2)
|
||||
|
||||
def test_divide_negative_right(self) -> None:
|
||||
self.assertEqual(divide(6, -3), -2)
|
||||
|
||||
def test_divide_both_negative(self) -> None:
|
||||
self.assertEqual(divide(-6, -3), 2)
|
||||
|
||||
def test_divide_floor(self) -> None:
|
||||
self.assertEqual(divide(7, 3), 2)
|
||||
|
||||
def test_divide_zero_numerator(self) -> None:
|
||||
self.assertEqual(divide(0, 5), 0)
|
||||
|
||||
def test_divide_by_zero(self) -> None:
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
divide(5, 0)
|
||||
self.assertEqual(str(cm.exception), 'division by zero')
|
||||
Loading…
Reference in New Issue
Block a user