Skip to content

Commit d3a192d

Browse files
committed
test api conformance
when provided with a non-counterexample, refineHypothesis should return false and not throw an exception.
1 parent 9909fdd commit d3a192d

File tree

10 files changed

+48
-14
lines changed

10 files changed

+48
-14
lines changed

algorithms/active/dhc/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ limitations under the License.
5959
<artifactId>automata-commons-util</artifactId>
6060
</dependency>
6161

62-
<dependency>
63-
<groupId>org.checkerframework</groupId>
64-
<artifactId>checker-qual</artifactId>
65-
</dependency>
66-
6762
<!-- build -->
6863
<dependency>
6964
<groupId>de.learnlib.tooling</groupId>
7065
<artifactId>annotations</artifactId>
7166
</dependency>
7267

68+
<dependency>
69+
<groupId>org.checkerframework</groupId>
70+
<artifactId>checker-qual</artifactId>
71+
</dependency>
72+
7373
<!-- test -->
7474
<dependency>
7575
<groupId>de.learnlib</groupId>

algorithms/active/dhc/src/main/java/de/learnlib/algorithm/dhc/mealy/MealyDHC.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ private void scheduleSuccessors(QueueElement<I, O> elem,
232232
public boolean refineHypothesis(DefaultQuery<I, Word<O>> ceQuery) {
233233
checkInternalState();
234234

235+
if (hypothesis.computeSuffixOutput(ceQuery.getPrefix(), ceQuery.getSuffix()).equals(ceQuery.getOutput())) {
236+
return false;
237+
}
238+
235239
Collection<Word<I>> ceSuffixes = suffixFinder.findSuffixes(ceQuery, this, hypothesis, oracle);
236240

237241
return addSuffixesUnchecked(ceSuffixes);

algorithms/active/procedural/src/main/java/de/learnlib/algorithm/procedural/sba/SBALearner.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,21 @@ public void startLearning() {
117117
@Override
118118
public boolean refineHypothesis(DefaultQuery<I, Boolean> defaultQuery) {
119119

120+
if (!MQUtil.isCounterexample(defaultQuery, getHypothesisModel())) {
121+
return false;
122+
}
123+
120124
assert this.alphabet.isReturnMatched(defaultQuery.getInput());
121125

122-
boolean changed = this.extractUsefulInformationFromCounterExample(defaultQuery);
126+
boolean changed = extractUsefulInformationFromCounterExample(defaultQuery);
123127

124128
while (refineHypothesisInternal(defaultQuery)) {
125129
changed = true;
126130
}
127131

128132
ensureCallAndReturnClosure();
129133

130-
assert SBAs.isValid(this.getHypothesisModel());
134+
assert SBAs.isValid(getHypothesisModel());
131135

132136
return changed;
133137
}

algorithms/active/procedural/src/main/java/de/learnlib/algorithm/procedural/spa/SPALearner.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,13 @@ public void startLearning() {
106106
@Override
107107
public boolean refineHypothesis(DefaultQuery<I, Boolean> defaultQuery) {
108108

109+
if (!MQUtil.isCounterexample(defaultQuery, getHypothesisModel())) {
110+
return false;
111+
}
112+
109113
assert this.alphabet.isWellMatched(defaultQuery.getInput());
110114

111-
boolean changed = this.extractUsefulInformationFromCounterExample(defaultQuery);
115+
boolean changed = extractUsefulInformationFromCounterExample(defaultQuery);
112116

113117
while (refineHypothesisInternal(defaultQuery)) {
114118
changed = true;

algorithms/active/procedural/src/main/java/de/learnlib/algorithm/procedural/spmm/SPMMLearner.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,14 @@ public void startLearning() {
118118
@Override
119119
public boolean refineHypothesis(DefaultQuery<I, Word<O>> defaultQuery) {
120120

121+
if (!MQUtil.isCounterexample(defaultQuery, getHypothesisModel())) {
122+
return false;
123+
}
124+
121125
assert defaultQuery.getPrefix().isEmpty() : "Counterexamples need to provide full trace information";
122126
assert this.alphabet.isReturnMatched(defaultQuery.getInput()) : "Counterexample has unmatched return symbols";
123127

124-
boolean changed = this.extractUsefulInformationFromCounterExample(defaultQuery);
128+
boolean changed = extractUsefulInformationFromCounterExample(defaultQuery);
125129

126130
while (refineHypothesisInternal(defaultQuery)) {
127131
changed = true;

test-support/learner-it-support/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ limitations under the License.
6565
<groupId>net.automatalib</groupId>
6666
<artifactId>automata-api</artifactId>
6767
</dependency>
68+
<dependency>
69+
<groupId>net.automatalib</groupId>
70+
<artifactId>automata-commons-util</artifactId>
71+
</dependency>
6872
<dependency>
6973
<groupId>net.automatalib</groupId>
7074
<artifactId>automata-core</artifactId>

test-support/learner-it-support/src/main/java/de/learnlib/testsupport/it/learner/AbstractLearnerVariantITCase.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,27 @@
1515
*/
1616
package de.learnlib.testsupport.it.learner;
1717

18+
import java.util.ArrayList;
19+
import java.util.List;
20+
import java.util.Random;
21+
1822
import de.learnlib.algorithm.LearningAlgorithm;
1923
import de.learnlib.logging.Category;
2024
import de.learnlib.oracle.EquivalenceOracle;
2125
import de.learnlib.query.DefaultQuery;
2226
import de.learnlib.testsupport.example.LearningExample;
2327
import net.automatalib.alphabet.Alphabet;
2428
import net.automatalib.automaton.concept.FiniteRepresentation;
29+
import net.automatalib.automaton.concept.Output;
30+
import net.automatalib.common.util.random.RandomUtil;
2531
import net.automatalib.word.Word;
2632
import org.slf4j.Logger;
2733
import org.slf4j.LoggerFactory;
2834
import org.testng.Assert;
2935
import org.testng.ITest;
3036
import org.testng.annotations.Test;
3137

32-
abstract class AbstractLearnerVariantITCase<I, D, M extends FiniteRepresentation> implements ITest {
38+
abstract class AbstractLearnerVariantITCase<I, D, M extends FiniteRepresentation & Output<I, D>> implements ITest {
3339

3440
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractLearnerVariantITCase.class);
3541

@@ -81,6 +87,11 @@ public void testLearning() {
8187
Assert.assertEquals(hypothesis.size(), reference.size());
8288
Assert.assertNull(checkEquivalence(hypothesis), "Final hypothesis does not match reference automaton");
8389

90+
final List<I> trace = RandomUtil.sample(new Random(42), new ArrayList<>(alphabet), 5);
91+
final D output = reference.computeOutput(trace);
92+
93+
Assert.assertFalse(learner.refineHypothesis(new DefaultQuery<>(Word.fromList(trace), output)));
94+
8495
long duration = (System.nanoTime() - start) / NANOS_PER_MILLISECOND;
8596
LOGGER.info(Category.EVENT,
8697
"Passed learner integration test {} ... took [{}]",

test-support/learner-it-support/src/main/java/de/learnlib/testsupport/it/learner/LearnerITUtil.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import net.automatalib.automaton.UniversalAutomaton;
3838
import net.automatalib.automaton.UniversalDeterministicAutomaton;
3939
import net.automatalib.automaton.concept.FiniteRepresentation;
40+
import net.automatalib.automaton.concept.Output;
4041
import net.automatalib.automaton.concept.SuffixOutput;
4142
import net.automatalib.automaton.procedural.SBA;
4243
import net.automatalib.automaton.procedural.SPA;
@@ -78,7 +79,7 @@ private LearnerITUtil() {
7879
*
7980
* @return the list of test cases, one for each example
8081
*/
81-
public static <I, D, A extends UniversalDeterministicAutomaton<?, I, ?, ?, ?>> List<UniversalDeterministicLearnerITCase<I, D, A>> createExampleITCases(
82+
public static <I, D, A extends UniversalDeterministicAutomaton<?, I, ?, ?, ?> & Output<I, D>> List<UniversalDeterministicLearnerITCase<I, D, A>> createExampleITCases(
8283
UniversalDeterministicLearningExample<I, ? extends A> example,
8384
LearnerVariantListImpl<A, I, D> variants,
8485
EquivalenceOracle<? super A, I, D> eqOracle) {
@@ -192,7 +193,7 @@ public static <I> List<OneSEVPALearnerITCase<I>> createExampleITCases(OneSEVPALe
192193
OneSEVPALearnerITCase::new);
193194
}
194195

195-
private static <I, D, M extends FiniteRepresentation, L extends LearningExample<I, ? extends M>, C extends AbstractLearnerVariantITCase<I, D, M>> List<C> createExampleITCasesInternal(
196+
private static <I, D, M extends FiniteRepresentation & Output<I, D>, L extends LearningExample<I, ? extends M>, C extends AbstractLearnerVariantITCase<I, D, M>> List<C> createExampleITCasesInternal(
196197
L example,
197198
LearnerVariantListImpl<M, I, D> variants,
198199
EquivalenceOracle<? super M, I, D> eqOracle,
@@ -265,7 +266,7 @@ public static <I, D, A extends SuffixOutput<I, D>> List<PassiveLearnerVariantITC
265266
}
266267

267268
@FunctionalInterface
268-
private interface ITCaseBuilder<I, D, M extends FiniteRepresentation, L extends LearningExample<I, ? extends M>, C extends AbstractLearnerVariantITCase<I, D, M>> {
269+
private interface ITCaseBuilder<I, D, M extends FiniteRepresentation & Output<I, D>, L extends LearningExample<I, ? extends M>, C extends AbstractLearnerVariantITCase<I, D, M>> {
269270

270271
C build(LearnerVariant<M, I, D> variant, L example, EquivalenceOracle<? super M, I, D> eqOracle);
271272
}

test-support/learner-it-support/src/main/java/de/learnlib/testsupport/it/learner/UniversalDeterministicLearnerITCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
import de.learnlib.oracle.EquivalenceOracle;
1919
import de.learnlib.testsupport.example.LearningExample.UniversalDeterministicLearningExample;
2020
import net.automatalib.automaton.UniversalDeterministicAutomaton;
21+
import net.automatalib.automaton.concept.Output;
2122
import net.automatalib.util.automaton.Automata;
2223
import net.automatalib.word.Word;
2324

24-
public class UniversalDeterministicLearnerITCase<I, D, M extends UniversalDeterministicAutomaton<?, I, ?, ?, ?>>
25+
public class UniversalDeterministicLearnerITCase<I, D, M extends UniversalDeterministicAutomaton<?, I, ?, ?, ?> & Output<I, D>>
2526
extends AbstractLearnerVariantITCase<I, D, M> {
2627

2728
private final UniversalDeterministicLearningExample<I, ? extends M> example;

test-support/learner-it-support/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
requires de.learnlib.oracle.equivalence;
3838
requires de.learnlib.testsupport.example;
3939
requires net.automatalib.api;
40+
requires net.automatalib.common.util;
4041
requires net.automatalib.util;
4142
requires org.slf4j;
4243
requires org.testng;

0 commit comments

Comments
 (0)