-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
86 lines (58 loc) · 2.28 KB
/
tests.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
Library of tests of library.py
Classes: None
:func: test_binary_search : check if binary_search returns right value
:func: test_linear_search : check if linear_search returns right value
:raises: AssertionError : tested function returned wrong value
:raises: AssertionError : tested function took too long
"""
import pytest
import library
import test_parameters
import time
# RESULT TESTING
@pytest.mark.parametrize("test_inputs, expected", test_parameters.arr())
def test_binary_search(test_inputs, expected):
"""
Asserts that binary_search returns right value.
Assert that the result of binary search is the search parameter.
:param test_inputs: any
:param expected: any
:raises: AssertionError: binary_search returned wrong value
"""
assert library.binary_search(*test_inputs) == expected
@pytest.mark.parametrize("test_inputs, expected", test_parameters.arr())
def test_linear_search(test_inputs, expected):
"""
Asserts that linear_search returns right value.
Assert that the result of binary search is the search parameter.
:param test_inputs: any
:param expected: any
:raises: AssertionError: binary_search returned wrong value
"""
assert library.linear_search(*test_inputs) == expected
# PERFORMANCE TESTING
@pytest.mark.parametrize("test_inputs, expected", test_parameters.arr())
def test_binary_search_performance(test_inputs, expected):
"""
Asserts that binary_search works fast enough.
Assert that the time of binary_search is tolerable.
:param test_inputs: any
:param expected: any
:raises: AssertionError: binary_search was too slow
"""
start = time.time()
result = library.binary_search(*test_inputs)
assert abs(time.time() - start) < 0.01
@pytest.mark.parametrize("test_inputs, expected", test_parameters.arr())
def test_linear_search_performance(test_inputs, expected):
"""
Asserts that linear_search works fast enough.
Assert that the time of linear_search is tolerable.
:param test_inputs: any
:param expected: any
:raises: AssertionError: linear_search was too slow
"""
start = time.time()
result = library.linear_search(*test_inputs)
assert abs(time.time() - start) < 0.01