-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_simple_rfc.py
More file actions
102 lines (88 loc) · 3.05 KB
/
test_simple_rfc.py
File metadata and controls
102 lines (88 loc) · 3.05 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
from src.llm import HFLLMConverter
from unittest.mock import patch
def test_simple_requirements():
"""Test converter with simple RFC requirements using mock responses"""
# Test cases with expected outputs
test_cases = [
{
"requirement": "A server MUST send an error response if the request is invalid.",
"fol_response": "∀s∀r (Server(s) ∧ Request(r) ∧ ¬ValidRequest(r) → ∃resp (Response(resp) ∧ Error(resp) ∧ Send(s,resp)))",
"smt_response": """
(declare-sort Device)
(declare-sort Request)
(declare-sort Response)
(declare-fun Server (Device) Bool)
(declare-fun ValidRequest (Request) Bool)
(declare-fun Send (Device Response) Bool)
(declare-fun Error (Response) Bool)
(assert
(forall ((s Device) (r Request))
(=>
(and
(Server s)
(not (ValidRequest r))
)
(exists ((resp Response))
(and
(Error resp)
(Send s resp)
)
)
)
)
)"""
},
{
"requirement": "A client MUST wait at least 3 seconds before retrying.",
"fol_response": "∀c (Client(c) → (Retry(c) → After(Retry(c), Retry(c), 3)))",
"smt_response": """
(declare-sort Device)
(declare-fun Client (Device) Bool)
(declare-fun RetryTime (Device) Int)
(declare-const min_wait Int)
(assert
(forall ((c Device))
(=>
(Client c)
(>= (RetryTime c) 3)
)
)
)"""
}
]
print("\nTesting simple RFC requirements with mock responses:")
print("=" * 50)
successes = 0
failures = 0
for i, test_case in enumerate(test_cases, 1):
print(f"\nTest {i}/{len(test_cases)}")
print(f"Requirement: {test_case['requirement']}")
print("-" * 40)
try:
# Test FOL format
with patch('huggingface_hub.InferenceClient.text_generation') as mock_gen:
mock_gen.return_value = test_case['fol_response']
converter = HFLLMConverter()
converter.set_output_format("FOL")
fol = converter.extract_fol(test_case['requirement'])
print(f"FOL Format:\n{fol}")
# Test SMT-LIB format
with patch('huggingface_hub.InferenceClient.text_generation') as mock_gen:
mock_gen.return_value = test_case['smt_response']
converter.set_output_format("SMT-LIB")
smt = converter.extract_fol(test_case['requirement'])
print(f"\nSMT-LIB Format:\n{smt}")
print("\nStatus: Conversion successful! ✅")
successes += 1
except Exception as e:
print(f"Status: Failed - {str(e)} ❌")
failures += 1
print("=" * 50)
# Print summary
print("\nTest Summary:")
print(f"Total tests: {len(test_cases)}")
print(f"Successes: {successes}")
print(f"Failures: {failures}")
print(f"Success rate: {(successes/len(test_cases))*100:.1f}%")
if __name__ == "__main__":
test_simple_requirements()