diff --git a/tests/autotests/test_task02.py b/tests/autotests/test_task02.py index ea1f3e670..a340cbd55 100644 --- a/tests/autotests/test_task02.py +++ b/tests/autotests/test_task02.py @@ -14,7 +14,8 @@ # Fix import statements in try block to run tests try: - from project.task2 import regex_to_dfa, graph_to_nfa + from project.graph_utils import graph_to_nfa + from project.regex_utils import regex_to_dfa except ImportError: pytestmark = pytest.mark.skip("Task 2 is not ready to test!") diff --git a/tests/test_data/test_graph_utils/expected_graph_1.dot b/tests/test_data/test_graph_utils/graph_example_1.dot similarity index 100% rename from tests/test_data/test_graph_utils/expected_graph_1.dot rename to tests/test_data/test_graph_utils/graph_example_1.dot diff --git a/tests/test_data/test_graph_utils/expected_graph_2.dot b/tests/test_data/test_graph_utils/graph_example_2.dot similarity index 100% rename from tests/test_data/test_graph_utils/expected_graph_2.dot rename to tests/test_data/test_graph_utils/graph_example_2.dot diff --git a/tests/test_graph_utils.py b/tests/test_graph_utils.py index a696d507d..abe578d52 100644 --- a/tests/test_graph_utils.py +++ b/tests/test_graph_utils.py @@ -1,9 +1,11 @@ import pytest import networkx as nx +import cfpq_data from pathlib import Path from project.graph_utils import ( get_graph_basic_info, create_and_save_labeled_two_cycles_graph, + graph_to_nfa, GraphBasicInfo, ) @@ -62,12 +64,12 @@ def test_get_graph_basic_info( @pytest.mark.parametrize( "first_cycle_nodes_number, second_cycle_nodes_number, labels, expected_graph_path", [ - (5, 2, ("7", "8"), Path(EXPECTED_PATH, "expected_graph_1.dot")), + (5, 2, ("7", "8"), Path(EXPECTED_PATH, "graph_example_1.dot")), ( 1, 5, ("8", "1"), - Path(EXPECTED_PATH, "expected_graph_2.dot"), + Path(EXPECTED_PATH, "graph_example_2.dot"), ), ], ) @@ -83,3 +85,20 @@ def test_create_and_save_labeled_two_cycles_graph( actual_graph = nx.nx_pydot.read_dot(tmp_filepath) assert nx.utils.graphs_equal(expected_graph, actual_graph) + + +@pytest.mark.parametrize( + "graph_path, start_states, final_states", + [ + (Path(EXPECTED_PATH, "graph_example_1.dot"), {4}, {6}), + (Path(EXPECTED_PATH, "graph_example_2.dot"), {0, 1}, {5, 4}), + ], +) +def test_graph_to_nfa(graph_path, start_states, final_states): + graph = nx.nx_pydot.read_dot(graph_path) + + res = graph_to_nfa(graph, start_states, final_states) + + assert res.start_states == start_states + assert res.final_states == final_states + assert res.symbols == set(cfpq_data.get_sorted_labels(graph)) diff --git a/tests/test_regex_utils.py b/tests/test_regex_utils.py new file mode 100644 index 000000000..328fdd697 --- /dev/null +++ b/tests/test_regex_utils.py @@ -0,0 +1,11 @@ +from project.regex_utils import regex_to_dfa + + +def test_regex_to_dfa(): + res = regex_to_dfa("a.b.c*|d") + + assert res.is_equivalent_to(res.minimize()) + assert res.is_deterministic() + assert res.accepts("abccc") + assert res.accepts("d") + assert not res.accepts("cd")