Merge pull request 'feat: Add multiply and divide to the calculator' (#3) from typosaurus/2-add-multiply-and-divide-to-the-calculator into main
Reviewed-on: #3
This commit is contained in:
commit
d5861fb2e3
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
src/__pycache__/calculator.cpython-315.pyc
Normal file
BIN
src/__pycache__/calculator.cpython-315.pyc
Normal file
Binary file not shown.
@ -6,3 +6,13 @@ def add(left: int, right: int) -> int:
|
||||
|
||||
def subtract(left: int, right: int) -> int:
|
||||
return left - right
|
||||
|
||||
|
||||
def multiply(left: int, right: int) -> int:
|
||||
return left * right
|
||||
|
||||
|
||||
def divide(left: int, right: int) -> int:
|
||||
if right == 0:
|
||||
raise ValueError('division by zero')
|
||||
return left // right
|
||||
|
||||
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