Skip to content

Commit

Permalink
oml: add tests for CE management
Browse files Browse the repository at this point in the history
  • Loading branch information
mtf90 committed Oct 2, 2024
1 parent 0c2007f commit a5661e4
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 1 deletion.
31 changes: 30 additions & 1 deletion algorithms/active/oml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ limitations under the License.
</dependency>

<!-- test -->
<dependency>
<groupId>de.learnlib</groupId>
<artifactId>learnlib-equivalence-oracles</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.learnlib</groupId>
<artifactId>learnlib-membership-oracles</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.learnlib.testsupport</groupId>
<artifactId>learnlib-learner-it-support</artifactId>
Expand All @@ -83,11 +93,30 @@ limitations under the License.
<artifactId>automata-serialization-dot</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.automatalib</groupId>
<artifactId>automata-util</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>

</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- append to existing argLine to nicely work together with jacoco plugin -->
<argLine>@{argLine} --add-reads=de.learnlib.algorithm.oml=net.automatalib.util</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* Copyright (C) 2013-2024 TU Dortmund University
* This file is part of LearnLib, http://www.learnlib.de/.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.learnlib.algorithm.oml;

import de.learnlib.algorithm.LearningAlgorithm.DFALearner;
import de.learnlib.oracle.MembershipOracle.DFAMembershipOracle;
import de.learnlib.oracle.equivalence.SampleSetEQOracle;
import de.learnlib.oracle.membership.DFASimulatorOracle;
import de.learnlib.util.Experiment.DFAExperiment;
import net.automatalib.alphabet.Alphabet;
import net.automatalib.alphabet.impl.Alphabets;
import net.automatalib.automaton.fsa.DFA;
import net.automatalib.automaton.fsa.impl.CompactDFA;
import net.automatalib.util.automaton.Automata;
import net.automatalib.util.automaton.builder.AutomatonBuilders;
import net.automatalib.word.Word;
import net.automatalib.word.WordBuilder;
import org.testng.Assert;
import org.testng.annotations.Test;

/**
* Test cases for testing counterexample management.
*/
public abstract class AbstractCounterexampleQueueTest {

private static final CompactDFA<Character> DFA;

static {
final Alphabet<Character> alphabet = Alphabets.characters('a', 'b');
// @formatter:off
DFA = AutomatonBuilders.newDFA(alphabet)
.withInitial("q0")
.from("q0")
.on('a').to("q1")
.on('b').to("q1'")
.from("q1")
.on('a').to("q2")
.on('b').loop()
.from("q1'")
.on('a').loop()
.on('b').to("q2'")
.from("q2")
.on('a').to("q3")
.on('b').loop()
.from("q2'")
.on('a', 'b').loop()
.from("q3")
.on('a').to("q0")
.on('b').loop()
.withAccepting("q0", "q2'")
.create();
//@formatter:on
}

/**
* Simulates a learning setup in which intermediate counterexamples are discarded (popped from the stack) and the
* main counterexample needs to be re-evaluated twice.
*/
@Test
public void testPop() {
final Alphabet<Character> alphabet = DFA.getInputAlphabet();
final DFAMembershipOracle<Character> mqOracle = new DFASimulatorOracle<>(DFA);
final DFALearner<Character> learner = getLearner(alphabet, mqOracle);

final SampleSetEQOracle<Character, Boolean> eqOracle = new SampleSetEQOracle<>(false);
final Word<Character> a = Word.fromLetter('a');
final Word<Character> b = new WordBuilder<>('b', 9).toWord();
eqOracle.addAll(mqOracle, Word.fromWords(b, a, b, a, b, a, b, a));

final DFAExperiment<Character> experiment = new DFAExperiment<>(learner, eqOracle, alphabet);
experiment.run();

final DFA<?, Character> result = experiment.getFinalHypothesis();

Assert.assertTrue(Automata.testEquivalence(DFA, result, alphabet));
}

protected abstract <I> DFALearner<I> getLearner(Alphabet<I> alphabet, DFAMembershipOracle<I> oracle);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright (C) 2013-2024 TU Dortmund University
* This file is part of LearnLib, http://www.learnlib.de/.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.learnlib.algorithm.oml.lstar.dfa;

import de.learnlib.algorithm.LearningAlgorithm.DFALearner;
import de.learnlib.algorithm.oml.AbstractCounterexampleQueueTest;
import de.learnlib.algorithm.oml.lstar.OptimalLStarDFA;
import de.learnlib.oracle.MembershipOracle.DFAMembershipOracle;
import net.automatalib.alphabet.Alphabet;

public class OptimalLStarDFACounterexampleQueueTest extends AbstractCounterexampleQueueTest {

@Override
protected <I> DFALearner<I> getLearner(Alphabet<I> alphabet, DFAMembershipOracle<I> oracle) {
return new OptimalLStarDFA<>(alphabet, oracle);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Copyright (C) 2013-2024 TU Dortmund University
* This file is part of LearnLib, http://www.learnlib.de/.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.learnlib.algorithm.oml.ttt.dfa;

import de.learnlib.algorithm.LearningAlgorithm.DFALearner;
import de.learnlib.algorithm.oml.AbstractCounterexampleQueueTest;
import de.learnlib.oracle.MembershipOracle.DFAMembershipOracle;
import net.automatalib.alphabet.Alphabet;

public class OptimalTTTDFACounterexampleQueueTest extends AbstractCounterexampleQueueTest {

@Override
protected <I> DFALearner<I> getLearner(Alphabet<I> alphabet, DFAMembershipOracle<I> oracle) {
return new OptimalTTTDFA<>(alphabet, oracle);
}
}

0 comments on commit a5661e4

Please sign in to comment.