Skip to content

Commit 99dc7ca

Browse files
committed
add serialization tests for discrimination trees
1 parent 2e1ccf2 commit 99dc7ca

File tree

6 files changed

+1171
-2
lines changed

6 files changed

+1171
-2
lines changed

algorithms/active/discrimination-tree-vpda/pom.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ limitations under the License.
7575
<groupId>net.automatalib</groupId>
7676
<artifactId>automata-commons-smartcollections</artifactId>
7777
</dependency>
78+
<dependency>
79+
<groupId>net.automatalib</groupId>
80+
<artifactId>automata-commons-util</artifactId>
81+
</dependency>
82+
<dependency>
83+
<groupId>net.automatalib</groupId>
84+
<artifactId>automata-util</artifactId>
85+
</dependency>
7886

7987
<!-- build -->
8088
<dependency>
@@ -83,10 +91,31 @@ limitations under the License.
8391
</dependency>
8492

8593
<!-- test -->
94+
<dependency>
95+
<groupId>de.learnlib</groupId>
96+
<artifactId>learnlib-equivalence-oracles</artifactId>
97+
<scope>test</scope>
98+
</dependency>
8699
<dependency>
87100
<groupId>de.learnlib.testsupport</groupId>
88101
<artifactId>learnlib-learner-it-support</artifactId>
89102
</dependency>
103+
<dependency>
104+
<groupId>de.learnlib</groupId>
105+
<artifactId>learnlib-membership-oracles</artifactId>
106+
<scope>test</scope>
107+
</dependency>
108+
<dependency>
109+
<groupId>de.learnlib</groupId>
110+
<artifactId>learnlib-util</artifactId>
111+
<scope>test</scope>
112+
</dependency>
113+
114+
<dependency>
115+
<groupId>net.automatalib</groupId>
116+
<artifactId>automata-serialization-dot</artifactId>
117+
<scope>test</scope>
118+
</dependency>
90119

91120
<dependency>
92121
<groupId>org.testng</groupId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* Copyright (C) 2013-2022 TU Dortmund
2+
* This file is part of LearnLib, http://www.learnlib.de/.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package de.learnlib.algorithms.discriminationtree;
17+
18+
import java.io.IOException;
19+
import java.io.InputStream;
20+
import java.io.StringWriter;
21+
import java.util.Random;
22+
23+
import com.google.common.io.CharStreams;
24+
import de.learnlib.acex.analyzers.AcexAnalyzers;
25+
import de.learnlib.algorithms.discriminationtree.vpda.DTLearnerVPDA;
26+
import de.learnlib.oracle.equivalence.vpda.SimulatorEQOracle;
27+
import de.learnlib.oracle.membership.SimulatorOracle;
28+
import de.learnlib.util.Experiment;
29+
import net.automatalib.automata.vpda.DefaultOneSEVPA;
30+
import net.automatalib.automata.vpda.OneSEVPA;
31+
import net.automatalib.commons.util.IOUtil;
32+
import net.automatalib.serialization.dot.GraphDOT;
33+
import net.automatalib.util.automata.random.RandomAutomata;
34+
import net.automatalib.words.impl.Alphabets;
35+
import net.automatalib.words.impl.DefaultVPDAlphabet;
36+
import org.testng.Assert;
37+
import org.testng.annotations.Test;
38+
39+
/**
40+
* @author frohme
41+
*/
42+
public class DTVisualizationTest {
43+
44+
private final DTLearnerVPDA<Character> learner;
45+
46+
public DTVisualizationTest() {
47+
final DefaultVPDAlphabet<Character> alphabet = new DefaultVPDAlphabet<>(Alphabets.characters('a', 'c'),
48+
Alphabets.characters('1', '3'),
49+
Alphabets.characters('x', 'z'));
50+
final DefaultOneSEVPA<Character> vpa =
51+
RandomAutomata.randomOneSEVPA(new Random(42), 10, alphabet, 0.5, 0.5, true);
52+
53+
final SimulatorOracle<Character, Boolean> mqo = new SimulatorOracle<>(vpa);
54+
final SimulatorEQOracle<Character> eqo = new SimulatorEQOracle<>(vpa);
55+
this.learner = new DTLearnerVPDA<>(alphabet, mqo, AcexAnalyzers.BINARY_SEARCH_FWD);
56+
57+
final Experiment<OneSEVPA<?, Character>> exp = new Experiment<>(learner, eqo, alphabet);
58+
exp.run();
59+
}
60+
61+
@Test
62+
public void testVisualizeHyp() throws IOException {
63+
final String expectedHyp = resourceAsString("/hyp.dot");
64+
65+
final StringWriter actualHyp = new StringWriter();
66+
GraphDOT.write(this.learner.getHypothesisModel(), actualHyp);
67+
68+
Assert.assertEquals(actualHyp.toString(), expectedHyp);
69+
}
70+
71+
@Test
72+
public void testVisualizeDT() throws IOException {
73+
final String expectedDT = resourceAsString("/dt.dot");
74+
75+
final StringWriter actualDT = new StringWriter();
76+
GraphDOT.write(this.learner.getDiscriminationTree(), actualDT);
77+
78+
Assert.assertEquals(actualDT.toString(), expectedDT);
79+
}
80+
81+
private String resourceAsString(String resourceName) throws IOException {
82+
try (InputStream is = getClass().getResourceAsStream(resourceName)) {
83+
assert is != null;
84+
return CharStreams.toString(IOUtil.asBufferedUTF8Reader(is));
85+
}
86+
}
87+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
digraph g {
2+
3+
s0 [shape="oval" label="<ε, ε>"];
4+
s1 [shape="oval" label="<ε, a>"];
5+
s2 [shape="oval" label="<ε, b>"];
6+
s3 [shape="box" label="4"];
7+
s4 [shape="oval" label="<ε, b>"];
8+
s5 [shape="oval" label="<ε, 1 a x>"];
9+
s6 [shape="oval" label="<ε, c>"];
10+
s7 [shape="oval" label="<ε, 1 x>"];
11+
s8 [shape="box" label="0"];
12+
s9 [shape="box" label="5"];
13+
s10 [shape="oval" label="<ε, c>"];
14+
s11 [shape="box" label="1"];
15+
s12 [shape="oval" label="<ε, 1 x>"];
16+
s13 [shape="box" label="6"];
17+
s14 [shape="box" label="7"];
18+
s15 [shape="box" label="9"];
19+
s16 [shape="box" label="2"];
20+
s17 [shape="box" label="8"];
21+
s18 [shape="box" label="3"];
22+
s0 -> s1 [label="false"];
23+
s0 -> s2 [label="true"];
24+
s1 -> s3 [label="false"];
25+
s1 -> s4 [label="true"];
26+
s2 -> s5 [label="false"];
27+
s2 -> s6 [label="true"];
28+
s4 -> s7 [label="false"];
29+
s4 -> s8 [label="true"];
30+
s5 -> s9 [label="false"];
31+
s5 -> s10 [label="true"];
32+
s6 -> s11 [label="false"];
33+
s6 -> s12 [label="true"];
34+
s7 -> s13 [label="false"];
35+
s7 -> s14 [label="true"];
36+
s10 -> s15 [label="false"];
37+
s10 -> s16 [label="true"];
38+
s12 -> s17 [label="false"];
39+
s12 -> s18 [label="true"];
40+
41+
}

0 commit comments

Comments
 (0)