Commit 20202e4d authored by Akim Demaille's avatar Akim Demaille
Browse files

style: tests: refactor

* tests/bin/test.py (mefile, metext, meaut): New.
* tests/python/determinize.py: Use them.
* tests/python/standard.py: Use them, and prefer automata in files
instead of inline.
parent 7c207e04
......@@ -21,6 +21,22 @@ srcdir = os.environ['abs_srcdir'] if 'abs_srcdir' in os.environ \
medir = sys.argv[0].replace(".py", ".dir")
def mefile(fn, ext=None):
'''The path to the test's file `fn.ext`,
where `ext` is possibly empty.'''
return medir + '/' + fn + ('.' + ext if ext else '')
def metext(fn, ext=None):
'''The content of the test's file `fn.ext`,
where `ext` is possibly empty.'''
return open(mefile(fn, ext)).read().strip()
def meaut(fn, ext=None):
'''The automaton stored in the test's file `fn.ext`,
where `ext` is possibly empty.'''
return vcsn.automaton(filename=mefile(fn, ext))
# http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
def which(program):
'Return the file name for program if it exists, None otherwise.'
......
......@@ -3,11 +3,6 @@
import vcsn
from test import *
def gv(file):
return "{}/{}.gv".format(medir, file)
def load(file):
return open(gv(file)).read().strip()
# check AUT EXP ALGO = "auto" DETERMINISTIC = False
# -------------------------------------------------
......@@ -21,7 +16,7 @@ def check(aut, expfile, algo="auto", deterministic=False):
CHECK_EQ(deterministic, aut.transpose().strip().is_codeterministic())
det = aut.determinize(algo)
exp = load(expfile + '-det')
exp = metext(expfile + '-det', 'gv')
CHECK_EQ(exp, det)
CHECK(det.is_deterministic())
# Idempotence.
......@@ -56,7 +51,7 @@ check(ctx.ladybird(8), 'ladybird-8')
## ------------------------------- ##
for name in ['deterministic', 'empty', 'epsilon']:
aut = vcsn.automaton(filename=gv(name))
aut = meaut(name, 'gv')
check(aut, name, deterministic=True)
check(aut, name, deterministic=True, algo='weighted')
......@@ -66,7 +61,7 @@ for name in ['deterministic', 'empty', 'epsilon']:
## ------------------- ##
for name in ['q', 'z', 'zmin']:
aut = vcsn.automaton(filename=gv(name))
aut = meaut(name, 'gv')
check(aut, name)
......@@ -75,8 +70,8 @@ for name in ['q', 'z', 'zmin']:
## ----------------------------- ##
for name in ['b', 'f2']:
aut = meaut(name, 'gv')
for algo in ['auto', 'boolean', 'weighted']:
aut = vcsn.automaton(filename=gv(name))
check(aut, name, algo=algo)
......
......@@ -267,6 +267,10 @@ EXTRA_DIST += \
%D%/prefix.dir/aut4-suffix.gv \
%D%/prefix.dir/aut4.gv \
%D%/rdivide.dir/aut1.gv \
%D%/standard.dir/1.in.gv \
%D%/standard.dir/1.out.gv \
%D%/standard.dir/2.in.gv \
%D%/standard.dir/2.out.gv \
%D%/standard.dir/complement-1.gv \
%D%/standard.dir/compose-1.gv \
%D%/standard.dir/conjunction-1.gv \
......
digraph
{
vcsn_context = "lal_char(ab), q"
rankdir = LR
{
node [shape = point, width = 0]
I0
I2
F
}
{
node [shape = circle]
0
1
2
}
I0 -> 0 [label = "<1/2>"]
I2 -> 2 [label = "<1/4>"]
0 -> 0 [label = "a, <2>b"]
0 -> 1 [label = "<3>a"]
1 -> 2 [label = "b"]
2 -> 2 [label = "a, b"]
2 -> F
}
digraph
{
vcsn_context = "letterset<char_letters(ab)>, q"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
node [shape = point, width = 0]
I3
F2
F3
}
{
node [shape = circle, style = rounded, width = 0.5]
0
1
2
3
}
I3 -> 3
0 -> 0 [label = "a, <2>b"]
0 -> 1 [label = "<3>a"]
1 -> 2 [label = "b"]
2 -> F2
2 -> 2 [label = "a, b"]
3 -> F3 [label = "<1/4>"]
3 -> 0 [label = "<1/2>a, b"]
3 -> 1 [label = "<3/2>a"]
3 -> 2 [label = "<1/4>a, <1/4>b"]
}
digraph
{
vcsn_context = "lal_char(a), expressionset<lal_char(xyz), b>"
rankdir = LR
{
node [shape = point, width = 0]
I0
F0
F1
}
{
node [shape = circle]
0
}
I0 -> 0 [label = "<x>"]
0 -> F0 [label = "<y>"]
}
digraph
{
vcsn_context = "letterset<char_letters(a)>, expressionset<letterset<char_letters(xyz)>, b>"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
node [shape = point, width = 0]
I1
F1
}
{
node [shape = circle, style = rounded, width = 0.5]
1
}
I1 -> 1
1 -> F1 [label = "<xy>"]
}
......@@ -10,107 +10,19 @@ ctx = vcsn.context('lal_char(ab), b')
## standard(aut). ##
## --------------- ##
# Try to be exhaustive: Several initials states, with weights, one of
# which is final, the other has a loop.
a = vcsn.automaton('''
digraph
{
vcsn_context = "lal_char(ab), q"
rankdir = LR
{
node [shape = point, width = 0]
I0
I2
F
}
{
node [shape = circle]
0
1
2
}
I0 -> 0 [label = "<1/2>"]
I2 -> 2 [label = "<1/4>"]
0 -> 0 [label = "a, <2>b"]
0 -> 1 [label = "<3>a"]
1 -> 2 [label = "b"]
2 -> 2 [label = "a, b"]
2 -> F
}''')
exp = vcsn.automaton('''
digraph
{
vcsn_context = "lal_char(ab), q"
rankdir = LR
{
node [shape = point, width = 0]
I3
F2
F3
}
{
node [shape = circle]
0
1
2
3
}
I3 -> 3
0 -> 0 [label = "a, <2>b"]
0 -> 1 [label = "<3>a"]
1 -> 2 [label = "b"]
2 -> F2
2 -> 2 [label = "a, b"]
3 -> F3 [label = "<1/4>"]
3 -> 0 [label = "<1/2>a, b"]
3 -> 1 [label = "<3/2>a"]
3 -> 2 [label = "<1/4>a, <1/4>b"]
}''')
CHECK_EQ(exp, a.standard())
CHECK_EQ(a.transpose().standard().transpose(), a.costandard())
CHECK_EQ(a.transpose().is_standard(), a.is_costandard())
# Make sure we deleted former initial states that become inaccessible.
a = vcsn.automaton('''digraph
{
vcsn_context = "lal_char(a), expressionset<lal_char(xyz), b>"
rankdir = LR
{
node [shape = point, width = 0]
I0
F0
F1
}
{
node [shape = circle]
0
}
I0 -> 0 [label = "<x>"]
0 -> F0 [label = "<y>"]
}
''')
exp = '''digraph
{
vcsn_context = "letterset<char_letters(a)>, expressionset<letterset<char_letters(xyz)>, b>"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
node [shape = point, width = 0]
I1
F1
}
{
node [shape = circle, style = rounded, width = 0.5]
1
}
I1 -> 1
1 -> F1 [label = "<xy>"]
}'''
CHECK_EQ(exp, str(a.standard()))
CHECK_EQ(a.transpose().standard().transpose(), a.costandard())
CHECK_EQ(a.transpose().is_standard(), a.is_costandard())
# Automata:
#
# 1. Try to be exhaustive: Several initials states, with weights, one
# of which is final, the other has a loop.
#
# 2. Make sure we deleted former initial states that become
# inaccessible.
for fs in ['1', '2']:
a = meaut(fs, 'in.gv')
exp = metext(fs, 'out.gv')
CHECK_EQ(exp, a.standard())
CHECK_EQ(a.transpose().standard().transpose(), a.costandard())
CHECK_EQ(a.transpose().is_standard(), a.is_costandard())
## --------------- ##
......
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