initial commit

This commit is contained in:
Djalim Simaila 2023-12-21 09:44:19 +01:00
commit 6c0b9453f9
8 changed files with 32 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
venv*

Binary file not shown.

2
pytest.ini Normal file
View File

@ -0,0 +1,2 @@
[pytest]
junit_family = xunit1

0
src/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

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)