Repository navigation
Expand file tree
/
Copy pathtest_phase1.py
More file actions
76 lines (61 loc) · 2.11 KB
/
Copy pathtest_phase1.py
File metadata and controls
76 lines (61 loc) · 2.11 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
"""Tests rapides de la phase 1 :
- lecture des 12 fichiers problem_XX.txt
- verification de l'equilibre sum(P_i) == sum(C_j)
- affichage visuel du probleme 5
"""
from __future__ import annotations
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent
sys.path.insert(0, str(ROOT / "src"))
from io_utils import ( # noqa: E402 import apres modification de sys.path
display_cost_matrix,
display_marginal_costs,
display_potentials,
display_proposition,
read_problem,
)
def test_all_problems_balanced() -> None:
print("=== Verification des 12 problemes ===\n")
files = sorted((ROOT / "problems").glob("problem_*.txt"))
assert len(files) == 12, f"attendu 12 fichiers, trouve {len(files)}"
for f in files:
p = read_problem(f)
sp, sc = sum(p["provisions"]), sum(p["commands"])
status = "OK" if sp == sc else "DESEQUILIBRE"
print(
f"{f.name:20s} n={p['n']:>3d} m={p['m']:>3d} "
f"sum(P)={sp:>5d} sum(C)={sc:>5d} -> {status}"
)
assert sp == sc, f"{f.name} n'est pas equilibre"
def test_visual_problem_05() -> None:
print("\n=== Affichage visuel du probleme 5 ===\n")
p = read_problem(ROOT / "problems" / "problem_05.txt")
display_cost_matrix(p)
def test_display_helpers() -> None:
"""Verification visuelle des autres fonctions d'affichage avec des donnees factices."""
print("\n=== Test des fonctions d'affichage (donnees factices) ===\n")
p = read_problem(ROOT / "problems" / "problem_05.txt")
# Proposition factice : repartition uniforme tronquee (juste pour voir l'alignement)
proposition = [
[25, 0, 0],
[10, 15, 0],
[0, 5, 20],
]
display_proposition(p, proposition)
print()
display_potentials(
potentials_sources=[-1, 0, 1],
potentials_targets=[6, 7, 6],
)
print()
display_marginal_costs([
[0, 0, 1],
[0, 1, -2],
[-1, 0, 0],
])
if __name__ == "__main__":
test_all_problems_balanced()
test_visual_problem_05()
test_display_helpers()
print("\nTous les tests sont passes.")