• 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/WMethodEQOracle.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.WMethodTestsIterator;
39
import net.automatalib.word.Word;
40

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

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

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

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

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

129
    /**
130
     * Constructor. Uses
131
     * {@link Math#max(int, int) Math.max}{@code (lookahead, expectedSize - }{@link
132
     * UniversalDeterministicAutomaton#size() hypothesis.size()}{@code )} to determine the maximum length of sequences,
133
     * that should be appended to the transition-cover part of the test sequence to account for the fact that the system
134
     * under learning may have more states than the current 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 WMethodTestsIterator
146
     */
147
    public WMethodEQOracle(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 WMethodTestsIterator<>(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