Coverage for tests\test_calc_func.py: 100%
29 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-26 20:30 +0800
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-26 20:30 +0800
1"""
2test_calc_func.py contains pytest tests for math functions.
3pytest discovers tests named "test_*".
4Each function in this module is a test case.
5"""
7import pytest
8from com.automationpanda.example.calc_func import *
10NUMBER_1 = 3.0
11NUMBER_2 = 2.0
14def test_add():
15 value = add(NUMBER_1, NUMBER_2)
16 assert value == 5.0
19def test_subtract():
20 value = subtract(NUMBER_1, NUMBER_2)
21 assert value == 1.0
24def test_subtract_negative():
25 value = subtract(NUMBER_2, NUMBER_1)
26 assert value == -1.0
29def test_multiply():
30 value = multiply(NUMBER_1, NUMBER_2)
31 assert value == 6.0
34def test_divide():
35 value = divide(NUMBER_1, NUMBER_2)
36 assert value == 1.5
39# Test for dividing by zero catches the exception
40# http://doc.pytest.org/en/latest/assert.html#assertions-about-expected-exceptions
42def test_divide_by_zero():
43 with pytest.raises(ZeroDivisionError) as e:
44 divide(NUMBER_1, 0)
45 assert "division by zero" in str(e.value)
48# Tests for maximum and minimum use parameters
49# http://doc.pytest.org/en/latest/parametrize.html
51@pytest.mark.parametrize("a,b,expected", [
52 (NUMBER_1, NUMBER_2, NUMBER_1),
53 (NUMBER_2, NUMBER_1, NUMBER_1),
54 (NUMBER_1, NUMBER_1, NUMBER_1),
55])
56def test_maximum(a, b, expected):
57 assert maximum(a, b) == expected
60@pytest.mark.parametrize("a,b,expected", [
61 (NUMBER_1, NUMBER_2, NUMBER_2),
62 (NUMBER_2, NUMBER_1, NUMBER_2),
63 (NUMBER_2, NUMBER_2, NUMBER_2),
64])
65def test_minimum(a, b, expected):
66 assert minimum(a, b) == expected