initial commit

This commit is contained in:
Djalim Simaila 2023-12-21 09:44:19 +01:00
commit 5872f210c9
5 changed files with 31 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
venv*

1
pytest.ini Normal file
View File

@ -0,0 +1 @@
junit_family = xunit1

0
src/__init__.py Normal file
View File

19
src/calculator.py Normal file
View File

@ -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!")

10
test_addition.py Normal file
View File

@ -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)