-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_arithmetic.py
More file actions
42 lines (28 loc) · 956 Bytes
/
test_arithmetic.py
File metadata and controls
42 lines (28 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# tests/test_arithmetic.py
import pytest
from pymath import add, subtract, multiply, divide
class TestAdd:
def test_positive_numbers(self):
assert add(2, 3) == 5
def test_negative_numbers(self):
assert add(-1, -2) == -3
def test_floats(self):
assert add(0.1, 0.2) == pytest.approx(0.3) # ← important!
class TestSubtract:
def test_basic(self):
assert subtract(10, 4) == 6
def test_result_is_negative(self):
assert subtract(2, 5) == -3
class TestMultiply:
def test_basic(self):
assert multiply(3, 4) == 12
def test_by_zero(self):
assert multiply(99, 0) == 0
class TestDivide:
def test_basic(self):
assert divide(10, 2) == 5.0
def test_returns_float(self):
assert isinstance(divide(7, 2), float)
def test_divide_by_zero_raises(self):
with pytest.raises(ValueError, match="Cannot divide by zero"):
divide(5, 0)