-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
to check the problems reported in LearnLib/automatalib#46
- Loading branch information
Showing
2 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...s/property-oracles/src/test/java/de/learnlib/oracle/property/MealyPropertyOracleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* Copyright (C) 2013-2021 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.oracle.property; | ||
|
||
import java.util.function.Function; | ||
|
||
import de.learnlib.api.oracle.EmptinessOracle.MealyEmptinessOracle; | ||
import de.learnlib.api.oracle.InclusionOracle.MealyInclusionOracle; | ||
import de.learnlib.api.oracle.LassoEmptinessOracle.MealyLassoEmptinessOracle; | ||
import de.learnlib.api.oracle.MembershipOracle.MealyMembershipOracle; | ||
import de.learnlib.api.oracle.OmegaMembershipOracle.MealyOmegaMembershipOracle; | ||
import de.learnlib.api.oracle.PropertyOracle.MealyPropertyOracle; | ||
import de.learnlib.api.query.DefaultQuery; | ||
import de.learnlib.examples.mealy.ExampleTinyMealy; | ||
import de.learnlib.oracle.emptiness.MealyBFEmptinessOracle; | ||
import de.learnlib.oracle.emptiness.MealyLassoEmptinessOracleImpl; | ||
import de.learnlib.oracle.equivalence.MealyBFInclusionOracle; | ||
import de.learnlib.oracle.membership.SimulatorOmegaOracle.MealySimulatorOmegaOracle; | ||
import de.learnlib.oracle.membership.SimulatorOracle.MealySimulatorOracle; | ||
import net.automatalib.automata.transducers.MealyMachine; | ||
import net.automatalib.automata.transducers.impl.compact.CompactMealy; | ||
import net.automatalib.modelcheckers.ltsmin.LTSminUtil; | ||
import net.automatalib.modelcheckers.ltsmin.LTSminVersion; | ||
import net.automatalib.modelcheckers.ltsmin.ltl.LTSminLTLIOBuilder; | ||
import net.automatalib.modelcheckers.ltsmin.monitor.LTSminMonitorIOBuilder; | ||
import net.automatalib.modelchecking.ModelChecker.MealyModelChecker; | ||
import net.automatalib.modelchecking.ModelCheckerLasso.MealyModelCheckerLasso; | ||
import net.automatalib.util.automata.builders.AutomatonBuilders; | ||
import net.automatalib.words.Alphabet; | ||
import net.automatalib.words.Word; | ||
import net.automatalib.words.impl.Alphabets; | ||
import org.testng.Assert; | ||
import org.testng.SkipException; | ||
import org.testng.annotations.Test; | ||
|
||
public class MealyPropertyOracleTest { | ||
|
||
private static final Function<String, Character> EDGE_PARSER = s -> s.charAt(0); | ||
|
||
// @formatter:off | ||
private static final CompactMealy<Character, Character> HYP = | ||
AutomatonBuilders.<Character, Character>newMealy(Alphabets.singleton('a')) | ||
.withInitial("q0") | ||
.from("q0").on('a').withOutput('1').loop() | ||
.create(); | ||
// @formatter:on | ||
|
||
@Test | ||
public void testTinyExample() { | ||
if (!LTSminUtil.supports(LTSminVersion.of(3, 0, 0))) { | ||
throw new SkipException("LTSmin is not installed in the proper version"); | ||
} | ||
|
||
final ExampleTinyMealy example = ExampleTinyMealy.createExample(); | ||
final Alphabet<Character> inputAlphabet = example.getAlphabet(); | ||
|
||
final MealyMachine<?, Character, ?, Character> sys = example.getReferenceAutomaton(); | ||
|
||
final MealyOmegaMembershipOracle<?, Character, Character> omqo = new MealySimulatorOmegaOracle<>(sys); | ||
final MealyMembershipOracle<Character, Character> mqo = omqo.getMembershipOracle(); | ||
|
||
final MealyLassoEmptinessOracle<Character, Character> emptinessOracle = | ||
new MealyLassoEmptinessOracleImpl<>(omqo); | ||
final MealyInclusionOracle<Character, Character> inclusionOracle = new MealyBFInclusionOracle<>(mqo, 1.0); | ||
|
||
final MealyModelCheckerLasso<Character, Character, String> modelChecker = | ||
new LTSminLTLIOBuilder<Character, Character>().withString2Input(EDGE_PARSER) | ||
.withString2Output(EDGE_PARSER) | ||
.create(); | ||
|
||
final MealyPropertyOracle<Character, Character, String> propertyOracle = | ||
new MealyLassoPropertyOracle<>("X output==\"2\"", inclusionOracle, emptinessOracle, modelChecker); | ||
|
||
final DefaultQuery<Character, Word<Character>> ce = propertyOracle.findCounterExample(HYP, inputAlphabet); | ||
|
||
Assert.assertNotNull(ce); | ||
Assert.assertNotEquals(ce.getOutput(), HYP.computeOutput(ce.getInput())); | ||
} | ||
|
||
/** | ||
* Test-case issue <a href="https://github.com/LearnLib/automatalib/issues/46">#46</a>. | ||
*/ | ||
@Test | ||
public void testIssue46() { | ||
if (!LTSminUtil.supports(LTSminVersion.of(3, 1, 0))) { | ||
throw new SkipException("LTSmin is not installed in the proper version"); | ||
} | ||
|
||
final ExampleTinyMealy example = ExampleTinyMealy.createExample(); | ||
final Alphabet<Character> inputAlphabet = example.getAlphabet(); | ||
final MealyMachine<?, Character, ?, Character> sys = example.getReferenceAutomaton(); | ||
|
||
final int multiplier = 1; | ||
final MealyMembershipOracle<Character, Character> mqo = new MealySimulatorOracle<>(sys); | ||
|
||
final MealyEmptinessOracle<Character, Character> emptinessOracle = | ||
new MealyBFEmptinessOracle<>(mqo, multiplier); | ||
final MealyInclusionOracle<Character, Character> inclusionOracle = | ||
new MealyBFInclusionOracle<>(mqo, multiplier); | ||
|
||
final MealyModelChecker<Character, Character, String, MealyMachine<?, Character, ?, Character>> modelChecker = | ||
new LTSminMonitorIOBuilder<Character, Character>().withString2Input(EDGE_PARSER) | ||
.withString2Output(EDGE_PARSER) | ||
.create(); | ||
|
||
final MealyFinitePropertyOracle<Character, Character, String> propertyOracle = | ||
new MealyFinitePropertyOracle<>("X (output == \"2\")", inclusionOracle, emptinessOracle, modelChecker); | ||
|
||
final DefaultQuery<Character, Word<Character>> ce = propertyOracle.findCounterExample(HYP, inputAlphabet); | ||
|
||
Assert.assertNotNull(ce); | ||
Assert.assertNotEquals(ce.getOutput(), HYP.computeOutput(ce.getInput())); | ||
} | ||
} |