Some more tests

This commit is contained in:
Robin Jadoul 2016-05-29 14:40:56 +02:00
parent 9392afc74c
commit a24320099c
13 changed files with 70 additions and 16 deletions

View File

@ -4,7 +4,9 @@ import unittest, subprocess, filecmp, argparse, os.path, os, shutil
REFERENCE_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), "tests")
REGEXES_DATA = [ #TODO
[r"[a-zA-Z0-9]*"]
[r"[a-zA-Z0-9]*"],
[r"a", r"a|b"],
[r"a|b", r"a"],
]
def make_test(regexes, idx):
@ -13,10 +15,10 @@ def make_test(regexes, idx):
p.communicate(bytes("\n".join(regexes), "utf-8"))
self.assertEqual(0, p.returncode)
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.re" % idx), os.path.join(data_dir, "test_%s.re" % idx)))
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.enfa" % idx), os.path.join(data_dir, "test_%s.enfa" % idx)))
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.mssc" % idx), os.path.join(data_dir, "test_%s.mssc" % idx)))
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.min" % idx), os.path.join(data_dir, "test_%s.min" % idx)))
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.re" % idx), os.path.join(data_dir, "test_%s.re" % idx)), "The regex for testcase %s is incorrect" % idx)
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.enfa" % idx), os.path.join(data_dir, "test_%s.enfa" % idx)), "The eNFA for testcase %s is incorrect" % idx)
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.mssc" % idx), os.path.join(data_dir, "test_%s.mssc" % idx)), "The mssc'd DFA for testcase %s is incorrect" % idx)
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.min" % idx), os.path.join(data_dir, "test_%s.min" % idx)), "The minimized DFA for testcase %s is incorrect" % idx)
return test

View File

@ -17,12 +17,12 @@ namespace lxs {
std::string label = std::to_string(state);
s += std::to_string(state) + " [";
if (state == d.starting)
s += "color=yellow";
s += "color=yellow ";
if (d.accepting.count(state) > 0) {
s += "color=green shape=doublecircle";
s += "color=green shape=doublecircle ";
label += "\\np=" + std::to_string(d.priority.find(state)->second) + "\\nac=" + d.acceptingToken.find(state)->second;
}
s += " label=\"" + label + "\"]\n";
s += "label=\"" + label + "\"]\n";
}
for (const auto& tmp : d.delta)
@ -47,12 +47,12 @@ namespace lxs {
std::string label = std::to_string(state);
s += std::to_string(state) + " [";
if (state == n.starting)
s += "color=yellow";
s += "color=yellow ";
if (n.accepting.count(state) > 0) {
s += "color=green shape=doublecircle";
s += "color=green shape=doublecircle ";
label += "\\np=" + std::to_string(n.priority.find(state)->second) + "\\nac=" + n.acceptingToken.find(state)->second;
}
s += " label=\"" + label + "\"]\n";
s += "label=\"" + label + "\"]\n";
}
for (const auto& tmp : n.delta)
@ -78,12 +78,12 @@ namespace lxs {
std::string label = std::to_string(state);
s += std::to_string(state) + " [";
if (state == e.starting)
s += "color=yellow";
s += "color=yellow ";
if (e.accepting.count(state) > 0) {
s += "color=green shape=doublecircle";
s += "color=green shape=doublecircle ";
label += "\\np=" + std::to_string(e.priority.find(state)->second) + "\\nac=" + e.acceptingToken.find(state)->second;
}
s += " label=\"" + label + "\"]\n";
s += "label=\"" + label + "\"]\n";
}
for (const auto& tmp : e.delta)

View File

@ -1,11 +1,11 @@
digraph {
rankdir=LR
in [shape=point style=invis]
0 [label="0" color=yellow]
0 [color=yellow label="0"]
1 [label="1"]
2 [label="2"]
3 [label="3"]
4 [label="4" color=green shape=doublecircle]
4 [color=green shape=doublecircle label="4\np=0\nac=0"]
2 -> 3 [label="0"]
2 -> 3 [label="1"]
2 -> 3 [label="2"]

Binary file not shown.

Binary file not shown.

24
tests/test_1.enfa Normal file
View File

@ -0,0 +1,24 @@
digraph {
rankdir=LR
in [shape=point style=invis]
0 [color=yellow label="0"]
1 [label="1"]
2 [color=green shape=doublecircle label="2\np=0\nac=0"]
3 [label="3"]
4 [label="4"]
5 [label="5"]
6 [label="6"]
7 [label="7"]
8 [color=green shape=doublecircle label="8\np=1\nac=1"]
1 -> 2 [label="a"]
4 -> 5 [label="a"]
6 -> 7 [label="b"]
0 -> 1 [label="ε"]
0 -> 3 [label="ε"]
3 -> 4 [label="ε"]
3 -> 6 [label="ε"]
5 -> 8 [label="ε"]
7 -> 8 [label="ε"]
in -> 0
}

BIN
tests/test_1.min Normal file

Binary file not shown.

BIN
tests/test_1.mssc Normal file

Binary file not shown.

2
tests/test_1.re Normal file
View File

@ -0,0 +1,2 @@
a
(a|b)

24
tests/test_2.enfa Normal file
View File

@ -0,0 +1,24 @@
digraph {
rankdir=LR
in [shape=point style=invis]
0 [color=yellow label="0"]
1 [label="1"]
2 [label="2"]
3 [label="3"]
4 [label="4"]
5 [label="5"]
6 [color=green shape=doublecircle label="6\np=0\nac=0"]
7 [label="7"]
8 [color=green shape=doublecircle label="8\np=1\nac=1"]
2 -> 3 [label="a"]
4 -> 5 [label="b"]
7 -> 8 [label="a"]
0 -> 1 [label="ε"]
0 -> 7 [label="ε"]
1 -> 2 [label="ε"]
1 -> 4 [label="ε"]
3 -> 6 [label="ε"]
5 -> 6 [label="ε"]
in -> 0
}

BIN
tests/test_2.min Normal file

Binary file not shown.

BIN
tests/test_2.mssc Normal file

Binary file not shown.

2
tests/test_2.re Normal file
View File

@ -0,0 +1,2 @@
(a|b)
a