forked from Chloe22204/pawpingphils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_triage_engine.py
More file actions
196 lines (174 loc) · 6.32 KB
/
test_triage_engine.py
File metadata and controls
196 lines (174 loc) · 6.32 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
"""
test_triage_engine.py
─────────────────────
Unit tests for triage_engine.py covering 6 required scenarios + extras.
Run with: python3 test_triage_engine.py
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from triage_engine import run_triage
PASS = "✅ PASS"
FAIL = "❌ FAIL"
results = []
def test(name, inputs, expected_priority, expected_flags=None, expected_escalated=None):
result = run_triage(inputs)
ok = result["priority_level"] == expected_priority
if expected_flags is not None:
for flag in expected_flags:
if flag not in result["flags"]:
ok = False
if expected_escalated is not None:
if result["escalated"] != expected_escalated:
ok = False
status = PASS if ok else FAIL
results.append(ok)
print(f"{status} {name}")
print(f" Expected : {expected_priority} | Got: {result['priority_level']}")
print(f" Flags : {result['flags']}")
print(f" Path : {' → '.join(result['trigger_path'])}")
print(f" Dispatch : {result['dispatch_action']}")
if not ok:
print(f" ⚠ MISMATCH — full result: {result}")
print()
print("=" * 60)
print(" PAB TRIAGE ENGINE — UNIT TESTS")
print("=" * 60 + "\n")
# ── TEST 1: No audio detected → AUTO P1 ──────────────────────
test(
name = "Scenario 1 — No audio / recording failure",
inputs = {
"audio_present": False,
"breathing_state": "normal",
"vocal_tone": "calm",
"matched_keywords": [],
"background_cues": [],
},
expected_priority = "P1",
expected_flags = ["NO_AUDIO"],
)
# ── TEST 2: Agonal breathing → P1 ────────────────────────────
test(
name = "Scenario 2 — Agonal breathing detected",
inputs = {
"audio_present": True,
"breathing_state": "agonal",
"vocal_tone": "calm",
"matched_keywords": [],
"background_cues": [],
},
expected_priority = "P1",
expected_flags = ["BREATHING_EMERGENCY"],
)
# ── TEST 3: Slurred speech → P1 + STROKE_PROTOCOL ────────────
test(
name = "Scenario 3 — Slurred / dysarthric speech",
inputs = {
"audio_present": True,
"breathing_state": "normal",
"vocal_tone": "slurred",
"matched_keywords": [],
"background_cues": [],
},
expected_priority = "P1",
expected_flags = ["STROKE_PROTOCOL"],
)
# ── TEST 4: Fall keyword → P2 ─────────────────────────────────
test(
name = "Scenario 4 — Fall keyword detected",
inputs = {
"audio_present": True,
"breathing_state": "normal",
"vocal_tone": "calm",
"matched_keywords": ["fell down", "can't get up"],
"background_cues": [],
},
expected_priority = "P2",
)
# ── TEST 5: Accidental activation → P4 ───────────────────────
test(
name = "Scenario 5 — Accidental button press",
inputs = {
"audio_present": True,
"breathing_state": "normal",
"vocal_tone": "calm",
"matched_keywords": ["sorry", "wrong button", "i'm fine"],
"background_cues": [],
},
expected_priority = "P4",
expected_flags = ["ACCIDENTAL"],
)
# ── TEST 6: Background escalation ────────────────────────────
test(
name = "Scenario 6 — Background impact escalates P2 → P1",
inputs = {
"audio_present": True,
"breathing_state": "normal",
"vocal_tone": "calm",
"matched_keywords": ["fell down"],
"background_cues": ["impact"],
},
expected_priority = "P1",
expected_escalated = True,
)
# ── BONUS TEST 7: Cardiac keywords → P1 + CARDIAC_PROTOCOL ───
test(
name = "Bonus 7 — Chest pain keyword",
inputs = {
"audio_present": True,
"breathing_state": "normal",
"vocal_tone": "distressed",
"matched_keywords": ["chest pain"],
"background_cues": [],
},
expected_priority = "P1",
expected_flags = ["CARDIAC_PROTOCOL"],
)
# ── BONUS TEST 8: Smoke alarm override ────────────────────────
test(
name = "Bonus 8 — Smoke alarm overrides P3 → P1",
inputs = {
"audio_present": True,
"breathing_state": "normal",
"vocal_tone": "calm",
"matched_keywords": ["help"],
"background_cues": ["alarm"],
},
expected_priority = "P1",
expected_escalated = True,
)
# ── BONUS TEST 9: No keywords → default P3 ───────────────────
test(
name = "Bonus 9 — No keywords detected, default medium",
inputs = {
"audio_present": True,
"breathing_state": "normal",
"vocal_tone": "calm",
"matched_keywords": [],
"background_cues": [],
},
expected_priority = "P3",
)
# ── BONUS TEST 10: Laboured breathing → P1 ───────────────────
test(
name = "Bonus 10 — Laboured breathing",
inputs = {
"audio_present": True,
"breathing_state": "laboured",
"vocal_tone": "calm",
"matched_keywords": [],
"background_cues": [],
},
expected_priority = "P1",
expected_flags = ["BREATHING_EMERGENCY"],
)
# ── Summary ───────────────────────────────────────────────────
passed = sum(results)
total = len(results)
print("=" * 60)
print(f" RESULTS: {passed}/{total} tests passed")
if passed == total:
print(" 🎉 All tests passed!")
else:
print(f" ⚠ {total - passed} test(s) failed — review output above")
print("=" * 60)