-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_explanation.py
More file actions
48 lines (41 loc) · 1.62 KB
/
test_explanation.py
File metadata and controls
48 lines (41 loc) · 1.62 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
"""Test: verify regime-aware explanation generation."""
from sorting.recommender import SortingRecommender
r = SortingRecommender()
r.load_model()
print("=" * 70)
print("TEST 1: Small random array (n=10) - should get justification")
print("=" * 70)
res = r.recommend([5, 2, 8, 1, 9, 3, 7, 4, 6, 10])
print(f"Algorithm: {res['algorithm']}")
print(f"Explanation:\n{res['explanation']}")
print("\n" + "=" * 70)
print("TEST 2: Small array (n=30) - should get justification")
print("=" * 70)
res = r.recommend(list(range(1, 31)))
print(f"Algorithm: {res['algorithm']}")
print(f"Explanation:\n{res['explanation']}")
print("\n" + "=" * 70)
print("TEST 3: Large random array (n=5000) - NO justification")
print("=" * 70)
import random; random.seed(42)
res = r.recommend([random.random() for _ in range(5000)])
print(f"Algorithm: {res['algorithm']}")
print(f"Explanation:\n{res['explanation']}")
print("\n" + "=" * 70)
print("TEST 4: Small array but merge_sort selected (reverse) - NO justification")
print("=" * 70)
res = r.recommend(list(range(30, 0, -1)))
print(f"Algorithm: {res['algorithm']}")
print(f"Explanation:\n{res['explanation']}")
print("\n" + "=" * 70)
print("TEST 5: _n_from_features round-trip check")
print("=" * 70)
from sorting.features import SortingFeatureExtractor
ext = SortingFeatureExtractor()
for test_n in [5, 10, 20, 30, 40, 50, 100, 1000]:
arr = list(range(test_n))
feats = ext.extract(arr)
recovered = r._n_from_features(feats)
match = "OK" if recovered == test_n else f"MISMATCH (got {recovered})"
print(f" n={test_n:5d} -> size_log={feats['size_log']:.6f} -> recovered={recovered:5d} {match}")
print("\nDone.")