Skip to content

Commit

Permalink
add test case for NL* bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mtf90 committed Mar 17, 2020
1 parent 8efdb67 commit 0b5d660
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
5 changes: 5 additions & 0 deletions algorithms/active/nlstar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ limitations under the License.
<groupId>de.learnlib.testsupport</groupId>
<artifactId>learnlib-learner-it-support</artifactId>
</dependency>
<dependency>
<groupId>de.learnlib</groupId>
<artifactId>learnlib-equivalence-oracles</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.learnlib</groupId>
<artifactId>learnlib-membership-oracles</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* Copyright (C) 2013-2020 TU Dortmund
* 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.algorithms.nlstar;

import de.learnlib.oracle.equivalence.SampleSetEQOracle;
import de.learnlib.oracle.membership.SimulatorOracle;
import de.learnlib.util.Experiment;
import net.automatalib.automata.fsa.NFA;
import net.automatalib.automata.fsa.impl.compact.CompactNFA;
import net.automatalib.util.automata.Automata;
import net.automatalib.util.automata.builders.AutomatonBuilders;
import net.automatalib.util.automata.fsa.NFAs;
import net.automatalib.words.Alphabet;
import net.automatalib.words.Word;
import net.automatalib.words.impl.Alphabets;
import org.testng.Assert;
import org.testng.annotations.Test;

public class NLStarTest {

/**
* Test case for the bug described in issue <a href="https://github.com/LearnLib/learnlib/issues/70">#70</a>.
*/
@Test
public void testIssue70() {
final Alphabet<Character> alphabet = Alphabets.characters('a', 'b');

// @formatter:off
final CompactNFA<Character> nfa = AutomatonBuilders.newNFA(alphabet)
.withInitial("q0")
.from("q0")
.on('a').to("q1")
.on('b').to("q2")
.from("q1").on('b').to("q1")
.from("q2").on('a').to("q2")
.withAccepting("q1", "q2")
.create();
// @formatter:on

final SimulatorOracle<Character, Boolean> mqOracle = new SimulatorOracle<>(nfa);

final SampleSetEQOracle<Character, Boolean> eqOracle = new SampleSetEQOracle<>(false);
eqOracle.addAll(mqOracle,
Word.fromCharSequence("a"),
Word.fromCharSequence("ab"),
Word.fromCharSequence("aa"),
Word.fromCharSequence("bab"));

final NLStarLearner<Character> learner = new NLStarLearner<>(alphabet, mqOracle);

final Experiment<NFA<?, Character>> experiment = new Experiment<>(learner, eqOracle, alphabet);
experiment.run();
final NFA<?, Character> hyp = experiment.getFinalHypothesis();

Assert.assertEquals(nfa.size(), hyp.size());
Assert.assertTrue(Automata.testEquivalence(NFAs.determinize(nfa, false, false),
NFAs.determinize(hyp, alphabet, false, false),
alphabet));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.learnlib.algorithms.nlstar;
package de.learnlib.algorithms.nlstar.it;

import de.learnlib.algorithms.nlstar.NLStarLearner;
import de.learnlib.api.oracle.MembershipOracle.DFAMembershipOracle;
import de.learnlib.testsupport.it.learner.AbstractDFALearnerIT;
import de.learnlib.testsupport.it.learner.LearnerVariantList.DFALearnerVariantList;
Expand Down

0 comments on commit 0b5d660

Please sign in to comment.