• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LearnLib / learnlib / 13034511199

29 Jan 2025 03:18PM UTC coverage: 94.304% (-0.09%) from 94.389%
13034511199

push

github

mtf90
spmm: improve assertions

2 of 2 new or added lines in 1 file covered. (100.0%)

24 existing lines in 7 files now uncovered.

12417 of 13167 relevant lines covered (94.3%)

1.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/oracles/equivalence-oracles/src/main/java/de/learnlib/oracle/equivalence/WpMethodEQOracle.java
1
/* Copyright (C) 2013-2025 TU Dortmund University
2
 * This file is part of LearnLib <https://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.oracle.equivalence;
17

18
import java.util.Collection;
19
import java.util.stream.Stream;
20

21
import de.learnlib.oracle.EquivalenceOracle.DFAEquivalenceOracle;
22
import de.learnlib.oracle.EquivalenceOracle.MealyEquivalenceOracle;
23
import de.learnlib.oracle.EquivalenceOracle.MooreEquivalenceOracle;
24
import de.learnlib.oracle.MembershipOracle;
25
import de.learnlib.oracle.MembershipOracle.DFAMembershipOracle;
26
import de.learnlib.oracle.MembershipOracle.MealyMembershipOracle;
27
import de.learnlib.oracle.MembershipOracle.MooreMembershipOracle;
28
import de.learnlib.tooling.annotation.refinement.GenerateRefinement;
29
import de.learnlib.tooling.annotation.refinement.Generic;
30
import de.learnlib.tooling.annotation.refinement.Interface;
31
import de.learnlib.tooling.annotation.refinement.Mapping;
32
import net.automatalib.automaton.UniversalDeterministicAutomaton;
33
import net.automatalib.automaton.concept.Output;
34
import net.automatalib.automaton.fsa.DFA;
35
import net.automatalib.automaton.transducer.MealyMachine;
36
import net.automatalib.automaton.transducer.MooreMachine;
37
import net.automatalib.common.util.collection.IteratorUtil;
38
import net.automatalib.util.automaton.conformance.WpMethodTestsIterator;
39
import net.automatalib.word.Word;
40

41
/**
42
 * Implements an equivalence test by applying the Wp-method test on the given hypothesis automaton, as described in <a
43
 * href="https://doi.org/10.1109/32.87284">Test selection based on finite state models</a> by S.&nbsp;Fujiwara et al.
44
 *
45
 * @param <A>
46
 *         automaton type
47
 * @param <I>
48
 *         input symbol type
49
 * @param <D>
50
 *         output domain type
51
 */
52
@GenerateRefinement(name = "DFAWpMethodEQOracle",
53
                    generics = @Generic(value = "I", desc = "input symbol type"),
54
                    parentGenerics = {@Generic(clazz = DFA.class, generics = {"?", "I"}),
55
                                      @Generic("I"),
56
                                      @Generic(clazz = Boolean.class)},
57
                    typeMappings = @Mapping(from = MembershipOracle.class,
58
                                            to = DFAMembershipOracle.class,
59
                                            generics = @Generic("I")),
60
                    interfaces = @Interface(clazz = DFAEquivalenceOracle.class, generics = @Generic("I")))
61
@GenerateRefinement(name = "MealyWpMethodEQOracle",
62
                    generics = {@Generic(value = "I", desc = "input symbol type"),
63
                                @Generic(value = "O", desc = "output symbol type")},
64
                    parentGenerics = {@Generic(clazz = MealyMachine.class, generics = {"?", "I", "?", "O"}),
65
                                      @Generic("I"),
66
                                      @Generic(clazz = Word.class, generics = "O")},
67
                    typeMappings = @Mapping(from = MembershipOracle.class,
68
                                            to = MealyMembershipOracle.class,
69
                                            generics = {@Generic("I"), @Generic("O")}),
70
                    interfaces = @Interface(clazz = MealyEquivalenceOracle.class,
71
                                            generics = {@Generic("I"), @Generic("O")}))
72
@GenerateRefinement(name = "MooreWpMethodEQOracle",
73
                    generics = {@Generic(value = "I", desc = "input symbol type"),
74
                                @Generic(value = "O", desc = "output symbol type")},
75
                    parentGenerics = {@Generic(clazz = MooreMachine.class, generics = {"?", "I", "?", "O"}),
76
                                      @Generic("I"),
77
                                      @Generic(clazz = Word.class, generics = "O")},
78
                    typeMappings = @Mapping(from = MembershipOracle.class,
79
                                            to = MooreMembershipOracle.class,
80
                                            generics = {@Generic("I"), @Generic("O")}),
81
                    interfaces = @Interface(clazz = MooreEquivalenceOracle.class,
82
                                            generics = {@Generic("I"), @Generic("O")}))
83
public class WpMethodEQOracle<A extends UniversalDeterministicAutomaton<?, I, ?, ?, ?> & Output<I, D>, I, D>
84
        extends AbstractTestWordEQOracle<A, I, D> {
85

86
    private final int lookahead;
87
    private final int expectedSize;
88

89
    /**
90
     * Constructor. Convenience method for {@link #WpMethodEQOracle(MembershipOracle, int)} that sets {@code lookahead}
91
     * to 1.
92
     *
93
     * @param sulOracle
94
     *         interface to the system under learning
95
     */
96
    public WpMethodEQOracle(MembershipOracle<I, D> sulOracle) {
UNCOV
97
        this(sulOracle, 1);
×
UNCOV
98
    }
×
99

100
    /**
101
     * Constructor. Convenience method for {@link #WpMethodEQOracle(MembershipOracle, int, int)} that sets
102
     * {@code expectedSize} to 0.
103
     *
104
     * @param sulOracle
105
     *         interface to the system under learning
106
     * @param lookahead
107
     *         the maximum length of the "middle" part of the test cases
108
     */
109
    public WpMethodEQOracle(MembershipOracle<I, D> sulOracle, int lookahead) {
110
        this(sulOracle, lookahead, 0);
1✔
111
    }
1✔
112

113
    /**
114
     * Constructor. Convenience method for {@link #WpMethodEQOracle(MembershipOracle, int, int, int)} that sets
115
     * {@code batchSize} to 1.
116
     *
117
     * @param sulOracle
118
     *         interface to the system under learning
119
     * @param lookahead
120
     *         the (minimal) maximum length of the "middle" part of the test cases
121
     * @param expectedSize
122
     *         the expected size of the system under learning
123
     */
124
    public WpMethodEQOracle(MembershipOracle<I, D> sulOracle, int lookahead, int expectedSize) {
125
        this(sulOracle, lookahead, expectedSize, 1);
1✔
126
    }
1✔
127

128
    /**
129
     * Constructor. Uses
130
     * {@link Math#max(int, int) Math.max}{@code (lookahead, expectedSize - }{@link
131
     * UniversalDeterministicAutomaton#size() hypothesis.size()}{@code )} to determine the maximum length of sequences,
132
     * that should be appended to the state-cover (first phase) and remaining transition-cover (second phase) part of
133
     * the test sequence to account for the fact that the system under learning may have more states than the current
134
     * hypothesis.
135
     *
136
     * @param sulOracle
137
     *         interface to the system under learning
138
     * @param lookahead
139
     *         the (minimal) maximum length of the "middle" part of the test cases
140
     * @param expectedSize
141
     *         the expected size of the system under learning
142
     * @param batchSize
143
     *         size of the batches sent to the membership oracle
144
     *
145
     * @see WpMethodTestsIterator
146
     */
147
    public WpMethodEQOracle(MembershipOracle<I, D> sulOracle, int lookahead, int expectedSize, int batchSize) {
148
        super(sulOracle, batchSize);
1✔
149
        this.lookahead = lookahead;
1✔
150
        this.expectedSize = expectedSize;
1✔
151
    }
1✔
152

153
    @Override
154
    protected Stream<Word<I>> generateTestWords(A hypothesis, Collection<? extends I> inputs) {
155
        return IteratorUtil.stream(new WpMethodTestsIterator<>(hypothesis,
1✔
156
                                                               inputs,
157
                                                               Math.max(lookahead, expectedSize - hypothesis.size())));
1✔
158
    }
159
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc