commit 5872f210c9dcf83d3817910a264bb45875dbc86b Author: Djalim Simaila Date: Thu Dec 21 09:44:19 2023 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9e3d04c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv* diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..4d11943 --- /dev/null +++ b/pytest.ini @@ -0,0 +1 @@ +junit_family = xunit1 diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/calculator.py b/src/calculator.py new file mode 100644 index 0000000..d545193 --- /dev/null +++ b/src/calculator.py @@ -0,0 +1,19 @@ +def add(a, b): + checkInputs(a, b) + return a + b + +def subtract(a, b): + checkInputs(a, b) + return a - b + +def multiply(a, b): + checkInputs(a, b) + return a * b + +def divide(a, b): + checkInputs(a, b) + return a / b + +def checkInputs(a, b): + if not isinstance(a, (int, float)) or not isinstance(b, (int, float)): + raise TypeError("Inputs must be either int or float!") diff --git a/test_addition.py b/test_addition.py new file mode 100644 index 0000000..7d14170 --- /dev/null +++ b/test_addition.py @@ -0,0 +1,10 @@ +from src.calculator import add +import pytest + +def test_add(): + result = add(3, 4) + assert result == 7 + +def test_add_string(): + with pytest.raises(TypeError): + add("string", 4)