Skip to content

Commit 6d4c2cc

Browse files
authored
Make hW test more comprehensive
1 parent 8af8f20 commit 6d4c2cc

1 file changed

Lines changed: 46 additions & 15 deletions

File tree

tests/test_hW.py

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import pytest
2+
23
from aalpy import generate_random_deterministic_automata, bisimilar, run_hW
34
from aalpy.SULs import MealySUL
45

5-
66
SEEDS = list(range(50))
77
MODEL_SIZES = [
88
(2, 2, 2),
@@ -13,43 +13,40 @@
1313
(4, 2, 3),
1414
(4, 3, 2),
1515
(5, 3, 3),
16-
(5, 5, 5),
1716
(6, 2, 3),
18-
(6, 4, 2),
17+
(6, 3, 2),
1918
(10, 2, 3),
2019
(10, 2, 4),
2120
(10, 2, 2),
22-
(10, 4, 3),
23-
(12, 2, 3),
24-
(12, 2, 4),
25-
(12, 2, 3),
26-
(15, 2, 4),
27-
(15, 4, 2),
28-
(20, 4, 4),
21+
(10, 2, 3),
22+
(20, 5, 5),
23+
(30, 3, 4),
2924
]
3025

3126
TEST_CASES = [
3227
pytest.param(
28+
automaton_type,
3329
seed_val,
3430
num_states,
3531
input_size,
3632
output_size,
37-
id=f"states={num_states}-inputs={input_size}-outputs={output_size}-seed={seed_val}",
33+
id=f"states={num_states}-inputs={input_size}-outputs={output_size}-seed={seed_val}-automaton_type={automaton_type}",
3834
)
3935
for num_states, input_size, output_size in MODEL_SIZES
4036
for seed_val in SEEDS
37+
for automaton_type in ['dfa', 'moore', 'mealy']
4138
]
4239

4340

44-
@pytest.mark.parametrize("seed_val,num_states,input_size,output_size", TEST_CASES)
45-
@pytest.mark.timeout(10)
46-
def test_hw_seed(seed_val, num_states, input_size, output_size):
41+
@pytest.mark.parametrize("automaton_type,seed_val,num_states,input_size,output_size", TEST_CASES)
42+
@pytest.mark.timeout(5)
43+
def test_hw_seed(automaton_type, seed_val, num_states, input_size, output_size):
4744
from random import seed
4845

4946
seed(seed_val)
5047

5148
model = generate_random_deterministic_automata(
52-
'mealy',
49+
automaton_type,
5350
num_states=num_states,
5451
input_alphabet_size=input_size,
5552
output_alphabet_size=output_size,
@@ -65,9 +62,11 @@ def test_hw_seed(seed_val, num_states, input_size, output_size):
6562
sul = MealySUL(model)
6663
input_alphabet = model.get_input_alphabet()
6764

65+
6866
learned_model = run_hW(input_alphabet,
6967
sul,
7068
num_testing_steps=1000 * num_states,
69+
automaton_type=automaton_type,
7170
reset_testing_counter=True,
7271
query_for_initial_state=True)
7372

@@ -76,3 +75,35 @@ def test_hw_seed(seed_val, num_states, input_size, output_size):
7675
print(learned_model)
7776
print(model)
7877
assert bisimilar(model, learned_model)
78+
79+
80+
def test_hw_uses_user_provided_h_and_w():
81+
from aalpy import bisimilar, generate_random_deterministic_automata, run_hW, AutomatonSUL
82+
from random import seed
83+
seed(1)
84+
85+
model = generate_random_deterministic_automata(
86+
'mealy',
87+
num_states=100,
88+
input_alphabet_size=4,
89+
output_alphabet_size=4,
90+
)
91+
92+
sul = AutomatonSUL(model)
93+
input_alphabet = model.get_input_alphabet()
94+
95+
char_set = model.compute_characterization_set()
96+
97+
assert model.is_minimal() and model.is_minimal()
98+
99+
learned_model = run_hW(input_alphabet,
100+
sul,
101+
automaton_type='mealy',
102+
provided_characterization_set=char_set,
103+
num_testing_steps=2000,
104+
reset_testing_counter=True,
105+
query_for_initial_state=True)
106+
107+
assert learned_model.is_minimal()
108+
assert bisimilar(model, learned_model)
109+

0 commit comments

Comments
 (0)