test_cicd / tests /test_calc.py
rassulya's picture
Add unit tests for calculator functions
d9f69bd
raw
history blame contribute delete
754 Bytes
import pytest
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from calculator import add, subtract, multiply, divide, is_even
def test_add():
assert add(2, 3) == 5
assert add(-1, 1) == 0
assert add(0, 0) == 0
def test_subtract():
assert subtract(5, 3) == 2
assert subtract(0, 5) == -5
assert subtract(-2, -3) == 1
def test_multiply():
assert multiply(3, 4) == 12
assert multiply(-2, 3) == -6
assert multiply(0, 5) == 0
def test_divide():
assert divide(10, 2) == 5
assert divide(7, 2) == 3.5
with pytest.raises(ValueError):
divide(5, 0)
def test_is_even():
assert is_even(4) == True
assert is_even(3) == False
assert is_even(0) == True