diff --git a/tests/autotests/grammars_constants.py b/tests/autotests/grammars_constants.py index aee8e8b60..485b142ef 100644 --- a/tests/autotests/grammars_constants.py +++ b/tests/autotests/grammars_constants.py @@ -1,5 +1,6 @@ from pyformlang.cfg import cfg from constants import * +from random import sample GRAMMARS_TABLE: list[dict[str, list[str | cfg.CFG]]] = [ { @@ -326,7 +327,7 @@ GRAMMARS_DIFFERENT: list[cfg.CFG] = [ ds[CFG][0] for ds in GRAMMARS_TABLE if len(ds[CFG]) >= 1 ] -CFG_EBNF: list[tuple[list[cfg.CFG], list[str]]] = [ - (ds[CFG], ds[EBNF]) for ds in GRAMMARS_TABLE -] -REGEXES = [regex_str for ds in GRAMMARS_TABLE for regex_str in ds[REGEXP]] +CFG_EBNF: list[tuple[list[cfg.CFG], list[str]]] = sample( + [(ds[CFG], ds[EBNF]) for ds in GRAMMARS_TABLE], 15 +) +REGEXES = sample([regex_str for ds in GRAMMARS_TABLE for regex_str in ds[REGEXP]], 15) diff --git a/tests/autotests/rpq_template_test.py b/tests/autotests/rpq_template_test.py index 9e8a96585..a5eef0c9e 100644 --- a/tests/autotests/rpq_template_test.py +++ b/tests/autotests/rpq_template_test.py @@ -16,8 +16,11 @@ def rpq_cfpq_test( graph: MultiDiGraph, regex_str: str, - cfg_list: Iterable[CFG], - function: Callable[[CFG, MultiDiGraph, set[int], set[int]], set[tuple[int, int]]], + cfg_list: Iterable[CFG | RecursiveAutomaton], + function: Callable[ + [CFG | RecursiveAutomaton, MultiDiGraph, set[int], set[int]], + set[tuple[int, int]], + ], ) -> None: start_nodes, final_nodes = generate_rnd_start_and_final(graph) for cf_gram in cfg_list: @@ -35,8 +38,11 @@ def rpq_cfpq_test( def different_grammars_test( graph: MultiDiGraph, - eq_grammars: Iterable[CFG], - function: Callable[[CFG, MultiDiGraph, set[int], set[int]], set[tuple[int, int]]], + eq_grammars: Iterable[CFG | RecursiveAutomaton], + function: Callable[ + [CFG | RecursiveAutomaton, MultiDiGraph, set[int], set[int]], + set[tuple[int, int]], + ], ) -> None: start_nodes, final_nodes = generate_rnd_start_and_final(graph) eq_cfpqs = [ diff --git a/tests/autotests/test_task8.py b/tests/autotests/test_task8.py index 9cd44710c..170df8433 100644 --- a/tests/autotests/test_task8.py +++ b/tests/autotests/test_task8.py @@ -28,11 +28,13 @@ class TestReachabilityTensorAlgorithm: @pytest.mark.parametrize("regex_str, cfg_list", REGEXP_CFG) def test_rpq_cfpq_tensor(self, graph, regex_str, cfg_list) -> None: - rpq_cfpq_test(graph, regex_str, cfg_list, cfpq_with_tensor) + cfg_list_rsm = [cfg_to_rsm(grammar) for grammar in cfg_list] + rpq_cfpq_test(graph, regex_str, cfg_list_rsm, cfpq_with_tensor) @pytest.mark.parametrize("eq_grammars", GRAMMARS) def test_different_grammars(self, graph, eq_grammars): - different_grammars_test(graph, eq_grammars, cfpq_with_tensor) + eq_grammars_rsm = [cfg_to_rsm(grammar) for grammar in eq_grammars] + different_grammars_test(graph, eq_grammars_rsm, cfpq_with_tensor) @pytest.mark.parametrize("cfg_list, ebnf_list", CFG_EBNF) def test_cfpq_tensor(self, graph, cfg_list, ebnf_list): diff --git a/tests/autotests/test_task9.py b/tests/autotests/test_task9.py index 3bdfac5c3..cfd5818ef 100644 --- a/tests/autotests/test_task9.py +++ b/tests/autotests/test_task9.py @@ -29,11 +29,13 @@ class TestReachabilityGllAlgorithm: @pytest.mark.parametrize("regex_str, cfg_list", REGEXP_CFG) def test_rpq_cfpq_gll(self, graph, regex_str, cfg_list) -> None: - rpq_cfpq_test(graph, regex_str, cfg_list, cfpq_with_gll) + rsm_list = [cfg_to_rsm(grammar) for grammar in cfg_list] + rpq_cfpq_test(graph, regex_str, rsm_list, cfpq_with_gll) @pytest.mark.parametrize("eq_grammars", GRAMMARS) def test_different_grammars(self, graph, eq_grammars): - different_grammars_test(graph, eq_grammars, cfpq_with_gll) + eq_grammars_rsm = [cfg_to_rsm(grammar) for grammar in eq_grammars] + different_grammars_test(graph, eq_grammars_rsm, cfpq_with_gll) @pytest.mark.parametrize("cfg_list, ebnf_list", CFG_EBNF) def test_cfpq_gll(self, graph, cfg_list, ebnf_list):