initial commit
This commit is contained in:
commit
6c0b9453f9
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
venv*
|
BIN
__pycache__/test_addition.cpython-311-pytest-7.4.3.pyc
Normal file
BIN
__pycache__/test_addition.cpython-311-pytest-7.4.3.pyc
Normal file
Binary file not shown.
2
pytest.ini
Normal file
2
pytest.ini
Normal file
@ -0,0 +1,2 @@
|
||||
[pytest]
|
||||
junit_family = xunit1
|
0
src/__init__.py
Normal file
0
src/__init__.py
Normal file
BIN
src/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
src/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
src/__pycache__/calculator.cpython-311.pyc
Normal file
BIN
src/__pycache__/calculator.cpython-311.pyc
Normal file
Binary file not shown.
19
src/calculator.py
Normal file
19
src/calculator.py
Normal 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
10
test_addition.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user