Skip to content

Commit

Permalink
add tests for PropertyOracles
Browse files Browse the repository at this point in the history
to check the problems reported in LearnLib/automatalib#46
  • Loading branch information
mtf90 committed Aug 21, 2021
1 parent 02d9d40 commit efccb42
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 0 deletions.
36 changes: 36 additions & 0 deletions oracles/property-oracles/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,42 @@
</dependency>

<!-- test -->
<dependency>
<groupId>de.learnlib</groupId>
<artifactId>learnlib-emptiness-oracles</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.learnlib</groupId>
<artifactId>learnlib-equivalence-oracles</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.learnlib.testsupport</groupId>
<artifactId>learnlib-learning-examples</artifactId>
</dependency>
<dependency>
<groupId>de.learnlib</groupId>
<artifactId>learnlib-membership-oracles</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.automatalib</groupId>
<artifactId>automata-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.automatalib</groupId>
<artifactId>automata-modelchecking-ltsmin</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>
Expand Down
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()));
}
}

0 comments on commit efccb42

Please sign in to comment.