1
0
mirror of https://gitlab.com/MisterBiggs/testing-framework-comparison.git synced 2025-06-15 17:06:39 +00:00
2025-05-16 14:35:04 -06:00

50 lines
872 B
Python

import pytest
# Thanks to https://pydevtools.com/handbook/tutorial/setting-up-testing-with-pytest-and-uv/
# for the guide
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
def test_add():
assert add(1, 2) == 3
assert add(-1, 1) == 0
assert add(-1, -1) == -2
def test_subtract():
assert subtract(3, 2) == 1
assert subtract(2, 3) == -1
assert subtract(0, 0) == 0
def test_multiply():
assert multiply(2, 3) == 6
assert multiply(-2, 3) == -6
assert multiply(-2, -3) == 6
def test_divide():
assert divide(6, 3) == 2
assert divide(6, -3) == -2
assert divide(-6, -3) == 2
def test_divide_by_zero():
with pytest.raises(ValueError):
divide(5, 0)