forked from souryma/Antoine-MARTIN-tp-python-algo-tri
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
78 lines (64 loc) · 1.74 KB
/
test.py
File metadata and controls
78 lines (64 loc) · 1.74 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from typing import Callable
from sort.insertion import sort as insertion_sort
from sort.selection import sort as selection_sort
from sort.recursion import get_factorial
from sort.fusion import sort as fusion_sort
tests: list[dict] = [
{
"input": [1, 2, 3, 4, 5],
"expected": [1, 2, 3, 4, 5]
},
{
"input": [73, 16, 829, 2, 6],
"expected": [2, 6, 16, 73, 829]
},
{
"input": [-4, -282, 0, 7, 0],
"expected": [-282, -4, 0, 0, 7]
},
{
"input": [1, 1, 1, 1, 1],
"expected": [1, 1, 1, 1, 1]
},
{
"input": [],
"expected": []
},
{
"input": [8],
"expected": [8]
}
]
def test_sort_function(sort_function: Callable, label: str):
error = False
test = {}
result = []
for test in tests:
result = sort_function(test["input"].copy())
print(result)
if len(result) != len(test["expected"]):
error = True
else:
for index, number in enumerate(result):
if number != test["expected"][index]:
error = True
break
if error:
print(f"{label}: {test['input']} devient {result}, tri incorrect")
break
print(label, '\033[91m❌KO\033[00m' if error else '\033[92m✓ OK\033[00m')
def test_factorial():
correct: bool = (
get_factorial(1) == 1
and get_factorial(2) == 2
and get_factorial(5) == 120
and get_factorial(10) == 3628800
)
print(
"Factorielle",
'\033[92m✓ OK\033[00m' if correct else '\033[91m❌KO\033[00m'
)
test_sort_function(selection_sort, "Test par sélection")
test_sort_function(insertion_sort, "Test par insertion")
test_factorial()
test_sort_function(fusion_sort, "Test par fusion")