-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_example_code.py
More file actions
65 lines (47 loc) · 1.95 KB
/
test_example_code.py
File metadata and controls
65 lines (47 loc) · 1.95 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Тесты для демонстрации coverage в Python
"""
import pytest
from example_code import calculate_sum, process_data, complex_function
class TestCalculateSum:
"""Тесты функции calculate_sum"""
def test_positive_numbers(self):
"""Сложение положительных чисел"""
assert calculate_sum(2, 3) == 5
assert calculate_sum(10, 20) == 30
def test_negative_numbers(self):
"""Сложение отрицательных чисел"""
assert calculate_sum(-1, -1) == -2
assert calculate_sum(-5, 3) == -2
def test_zero(self):
"""Сложение с нулем"""
assert calculate_sum(0, 0) == 0
assert calculate_sum(5, 0) == 5
class TestProcessData:
"""Тесты функции process_data"""
def test_positive_values(self):
"""Обработка положительных значений"""
result = process_data([1, 2, 3])
assert result == [2, 4, 6]
def test_mixed_values(self):
"""Обработка смешанных значений"""
result = process_data([1, -2, 3, -4, 5])
assert result == [2, 6, 10]
def test_empty_list(self):
"""Обработка пустого списка"""
result = process_data([])
assert result == []
class TestComplexFunction:
"""Тесты функции complex_function"""
def test_all_positive(self):
"""Все параметры положительные"""
assert complex_function(1, 2, 3) == 6
def test_mixed_values(self):
"""Смешанные значения"""
assert complex_function(5, -1, 3) == 8
assert complex_function(5, 2, -1) == 7
def test_negative_x(self):
"""Отрицательный x"""
assert complex_function(-1, 2, 3) == 0
if __name__ == "__main__":
pytest.main([__file__, "-v"])