commit 6c0b9453f9e7a6ff8b638bc6be2e1aef9efd40e7 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/__pycache__/test_addition.cpython-311-pytest-7.4.3.pyc b/__pycache__/test_addition.cpython-311-pytest-7.4.3.pyc new file mode 100644 index 0000000..b299ee5 Binary files /dev/null and b/__pycache__/test_addition.cpython-311-pytest-7.4.3.pyc differ diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..3654234 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +junit_family = xunit1 diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/__pycache__/__init__.cpython-311.pyc b/src/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..ec8bb51 Binary files /dev/null and b/src/__pycache__/__init__.cpython-311.pyc differ diff --git a/src/__pycache__/calculator.cpython-311.pyc b/src/__pycache__/calculator.cpython-311.pyc new file mode 100644 index 0000000..b8b736c Binary files /dev/null and b/src/__pycache__/calculator.cpython-311.pyc differ 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)