Commit abde4bf7 authored by gonczor's avatar gonczor

Added unit tests

parent 2d42de7d
......@@ -5,3 +5,8 @@ build/
dist/
mymath.egg-info/
venv/
.vscode/
.mypy_cache/
.pytest_cache/
from .my_math import add, sub, div, mul
......@@ -11,5 +11,9 @@ def mul(a: int, b: int) -> int:
def div(a: int, b: int) -> float:
return a / b
some_very_long_and_meaningless_variable = 1
some_another_very_long_an_meaningless_variable = 2
if some_another_very_long_an_meaningless_variable + some_very_long_and_meaningless_variable > 2:
return a / b
else:
return 0.5
import pytest
from my_math import (
add,
div,
mul,
sub,
)
@pytest.mark.parametrize("a,b,expected", [(1, 2, 3), (4, -1, 3)])
def test_add(a: int, b: int, expected: int):
assert add(a, b) == expected
@pytest.mark.parametrize("a,b,expected", [(3, 2, 1), (4, -1, 5)])
def test_sub(a: int, b: int, expected: int):
assert sub(a, b) == expected
@pytest.mark.parametrize("a,b,expected", [(1, 2, 2), (4, -1, -4), (2, 0, 0)])
def test_mul(a: int, b: int, expected: int):
assert mul(a, b) == expected
@pytest.mark.parametrize("a,b,expected", [(6, 4, 1.5), (2, 1, 2)])
def test_div(a: int, b: int, expected: float):
assert div(a, b) == expected
def test_div_by_zero():
with pytest.raises(ZeroDivisionError):
div(2, 0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment