Commit e43db9f2 authored by Vladimír Štill's avatar Vladimír Štill
Browse files

test: More canonization tests

parent c4aad1ac
Pipeline #76608 passed with stage
in 51 seconds
from lib.parsing.parser import Parser
from lib.dfa import DFA
def is_can(dfa: str) -> bool:
parser = Parser()
return parser.str_to_dfa(dfa).is_canonical()
return parse(dfa).is_canonical()
def parse(dfa: str) -> DFA:
parser = Parser()
return parser.str_to_dfa(dfa)
def to_str(dfa: DFA) -> str:
parser = Parser()
return parser.dfa_to_str(dfa)
def test_can() -> None:
assert is_can("init=1 (1,a)=1 (1,b)=2 (2,b)=1 (2,a)=1 final={2}")
ex1 = "init=1 (1,a)=1 (1,b)=2 (2,b)=1 (2,a)=1 final={2}"
assert is_can(ex1)
assert is_can("init=1 (1,b)=3 (1,a)=2 (2,b)=1 (2,a)=1 (3,a)=2 (3,b)=2 final={2}")
assert not is_can("init=1 (1,b)=3 (1,c)=2 (2,b)=1 (2,a)=1 (3,a)=2 (3,b)=2 final={2}")
assert not is_can("init=1 (1,a)=1 (1,b)=2 (2,b)=1 (2,b)=1 (unreach,a)=1 (unreach,b)=unreach final={2}")
assert DFA.is_identical(parse(ex1).canonize(), parse(ex1))
auto_can = parse("init=x (x,a)=z (x,b)=y (y,a)=z (y,b)=z (z,a)=z (z,b)=z final={z}").canonize()
expect_can = parse("init=1 (1,a)=2 (1,b)=3 (2,a)=2 (2,b)=2 (3,a)=2 (3,b)=2 final={2}")
assert DFA.is_identical(auto_can, expect_can), f"{to_str(auto_can)}{to_str(expect_can)}"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment