diff --git a/automathon/finiteAutomata/dfa.py b/automathon/finiteAutomata/dfa.py index a2dd3ab..12edc91 100644 --- a/automathon/finiteAutomata/dfa.py +++ b/automathon/finiteAutomata/dfa.py @@ -1,4 +1,6 @@ # Exceptions module +from __future__ import annotations + from automathon.errors.errors import * from collections import deque from graphviz import Digraph @@ -218,8 +220,8 @@ def union(self, M: 'DFA') -> 'DFA': return tmp_nfa.get_dfa() - def view(self, fileName: str): - dot = Digraph(name=fileName, format='png') + def view(self, file_name: str, node_attr: dict[str, str] | None = None, edge_attr: dict[str, str] | None = None): + dot = Digraph(name=file_name, format='png', node_attr=node_attr, edge_attr=edge_attr) dot.graph_attr['rankdir'] = 'LR' diff --git a/automathon/finiteAutomata/nfa.py b/automathon/finiteAutomata/nfa.py index d0d0c94..ba88362 100644 --- a/automathon/finiteAutomata/nfa.py +++ b/automathon/finiteAutomata/nfa.py @@ -1,4 +1,6 @@ # Exceptions module +from __future__ import annotations + from automathon.errors.errors import * from collections import deque from graphviz import Digraph @@ -400,8 +402,8 @@ def product(self, M: 'NFA') -> 'NFA': return nfa - def view(self, file_name: str): - dot = Digraph(name=file_name, format='png') + def view(self, file_name: str, node_attr: dict[str, str] | None = None, edge_attr: dict[str, str] | None = None): + dot = Digraph(name=file_name, format='png', node_attr=node_attr, edge_attr=edge_attr) dot.graph_attr['rankdir'] = 'LR' diff --git a/tests/test_dfa.py b/tests/test_dfa.py index 283c920..fa4c047 100644 --- a/tests/test_dfa.py +++ b/tests/test_dfa.py @@ -132,6 +132,10 @@ def test_union(self): self.assertTrue(union_result.accept("00010010")) self.assertTrue(union_result.accept("0011000")) + def test_view(self): + self.fa.view(file_name="test_dfa_view_attrs", node_attr={'fontsize': '40pt'}, edge_attr={'fontsize': '10pt'}) + self.fa.view(file_name="test_dfa_view_no_attrs") + if __name__ == '__main__': unittest.main() diff --git a/tests/test_nfa.py b/tests/test_nfa.py index 793d2e1..3874b5d 100644 --- a/tests/test_nfa.py +++ b/tests/test_nfa.py @@ -181,3 +181,11 @@ def test_renumber(self): automata_4.renumber() self.assertTrue(automata_4.is_valid()) + + def test_view(self): + self.fa.view(file_name="test_nfa_view_attrs", node_attr={'fontsize': '40pt'}, edge_attr={'fontsize': '10pt'}) + self.fa.view(file_name="test_nfa_view_no_attrs") + + +if __name__ == '__main__': + unittest.main()