|
| 1 | +/* Copyright (C) 2013-2020 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.nlstar; |
| 17 | + |
| 18 | +import de.learnlib.oracle.equivalence.SampleSetEQOracle; |
| 19 | +import de.learnlib.oracle.membership.SimulatorOracle; |
| 20 | +import de.learnlib.util.Experiment; |
| 21 | +import net.automatalib.automata.fsa.NFA; |
| 22 | +import net.automatalib.automata.fsa.impl.compact.CompactNFA; |
| 23 | +import net.automatalib.util.automata.Automata; |
| 24 | +import net.automatalib.util.automata.builders.AutomatonBuilders; |
| 25 | +import net.automatalib.util.automata.fsa.NFAs; |
| 26 | +import net.automatalib.words.Alphabet; |
| 27 | +import net.automatalib.words.Word; |
| 28 | +import net.automatalib.words.impl.Alphabets; |
| 29 | +import org.testng.Assert; |
| 30 | +import org.testng.annotations.Test; |
| 31 | + |
| 32 | +public class NLStarTest { |
| 33 | + |
| 34 | + /** |
| 35 | + * Test case for the bug described in issue <a href="https://github.com/LearnLib/learnlib/issues/70">#70</a>. |
| 36 | + */ |
| 37 | + @Test |
| 38 | + public void testIssue70() { |
| 39 | + final Alphabet<Character> alphabet = Alphabets.characters('a', 'b'); |
| 40 | + |
| 41 | + // @formatter:off |
| 42 | + final CompactNFA<Character> nfa = AutomatonBuilders.newNFA(alphabet) |
| 43 | + .withInitial("q0") |
| 44 | + .from("q0") |
| 45 | + .on('a').to("q1") |
| 46 | + .on('b').to("q2") |
| 47 | + .from("q1").on('b').to("q1") |
| 48 | + .from("q2").on('a').to("q2") |
| 49 | + .withAccepting("q1", "q2") |
| 50 | + .create(); |
| 51 | + // @formatter:on |
| 52 | + |
| 53 | + final SimulatorOracle<Character, Boolean> mqOracle = new SimulatorOracle<>(nfa); |
| 54 | + |
| 55 | + final SampleSetEQOracle<Character, Boolean> eqOracle = new SampleSetEQOracle<>(false); |
| 56 | + eqOracle.addAll(mqOracle, |
| 57 | + Word.fromCharSequence("a"), |
| 58 | + Word.fromCharSequence("ab"), |
| 59 | + Word.fromCharSequence("aa"), |
| 60 | + Word.fromCharSequence("bab")); |
| 61 | + |
| 62 | + final NLStarLearner<Character> learner = new NLStarLearner<>(alphabet, mqOracle); |
| 63 | + |
| 64 | + final Experiment<NFA<?, Character>> experiment = new Experiment<>(learner, eqOracle, alphabet); |
| 65 | + experiment.run(); |
| 66 | + final NFA<?, Character> hyp = experiment.getFinalHypothesis(); |
| 67 | + |
| 68 | + Assert.assertEquals(nfa.size(), hyp.size()); |
| 69 | + Assert.assertTrue(Automata.testEquivalence(NFAs.determinize(nfa, false, false), |
| 70 | + NFAs.determinize(hyp, alphabet, false, false), |
| 71 | + alphabet)); |
| 72 | + } |
| 73 | +} |
0 commit comments