Commit 1bb14e0b authored by Akim Demaille's avatar Akim Demaille
Browse files

tests: fix is-equivalent

* tests/python/is-equivalent.py: Since we move to more `trivial`
identities, this test was weakened, as the expressions were not just
equivalent, but equal.
parent 9ae4dc69
......@@ -242,15 +242,17 @@ def can_test_equivalence(a):
def CHECK_EQUIV(a1, a2):
'''Check that `a1` and `a2` are equivalent. Also works for
expressions.'''
'''Check that `a1` and `a2` are equivalent. Works for
two automata, or two expressions.'''
num = 20
# Cannot compute equivalence on Zmin, approximate with shortest.
try:
if can_test_equivalence(a1) and can_test_equivalence(a2):
res = a1.is_equivalent(a2)
via = '(via is_equivalent)'
else:
res = a1.proper().shortest(num) == a2.proper().shortest(num)
via = '(via shortests)'
except RuntimeError as e:
FAIL("cannot check equivalence: " + str(e))
res = False
......@@ -258,7 +260,7 @@ def CHECK_EQUIV(a1, a2):
if res:
PASS()
else:
FAIL("not equivalent")
FAIL("not equivalent", via)
rst_file("Left", format(a1))
rst_file("Right", format(a2))
try:
......
......@@ -3,25 +3,34 @@
import vcsn
from test import *
# check EXPECTED RAT1 RAT2
# check EXPECTED EXP1 EXP2
# ------------------------
#
# Check that are-equivalent(RAT1, RAT2) == EXPECTED. Because
# Check that are-equivalent(EXP1, EXP2) == EXPECTED. Because
# is-equivalent on expressions uses is-equivalent on automata under
# the hood, this also checks the case of automata equivalence tests.
def check(exp, r1, r2):
r1 = ctx.expression(r1)
r2 = ctx.expression(r2)
r1 = ctx.expression(r1, 'trivial')
r2 = ctx.expression(r2, 'trivial')
print('check({:u}, {:u})'.format(r1, r2))
CHECK_EQ(exp, r1.is_equivalent(r2))
# We use inductive because (i) it covers all the operators, (ii)
# it introduces less equivalences than derived-term (which, for
# instance, builds the same automata for `a` and `a+a`.
a1 = r1.automaton('inductive')
a2 = r2.automaton('inductive')
CHECK_EQ(exp, a1.is_equivalent(a2))
ctx = vcsn.context('lal_char(ab), b')
check(True, r'\z', r'\z')
check(True, r'\e', r'\e')
check(True, 'a', 'a')
check(True, 'a+a', 'a')
check(True, 'a+b', 'b+a')
check(True, 'a+b+a', 'a+b')
check(True, 'ab', 'a.b')
check(True, 'a*', r'\e+(a.(a*))')
check(True, 'a+b', 'b+a')
check(True, r'a*+a*+(\e+aa*)', 'a*')
check(False, r'\z', r'\e')
......@@ -32,6 +41,7 @@ check(False, 'aa*', 'a*')
ctx = vcsn.context('lal_char(ab), z')
check(True, 'a+b+a', '<2>a+b')
check(True, 'a*+b+a*', '<2>a*+b')
check(False, 'a*+a*', 'a*')
ctx = vcsn.context('lat<lan_char, lan_char>,b')
a = ctx.expression('a|x')
......
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