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

LearnLib / learnlib / 6605620268

22 Oct 2023 06:53PM UTC coverage: 93.218% (+0.9%) from 92.296%
6605620268

push

github

mtf90
cleanup passive integration tests

11546 of 12386 relevant lines covered (93.22%)

1.68 hits per line

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

76.92
/api/src/main/java/de/learnlib/api/algorithm/PassiveLearningAlgorithm.java
1
/* Copyright (C) 2013-2023 TU Dortmund
2
 * This file is part of LearnLib, http://www.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.api.algorithm;
17

18
import java.util.ArrayList;
19
import java.util.Arrays;
20
import java.util.Collection;
21
import java.util.Collections;
22
import java.util.List;
23

24
import de.learnlib.api.query.DefaultQuery;
25
import net.automatalib.automaton.fsa.DFA;
26
import net.automatalib.automaton.fsa.FiniteStateAcceptor;
27
import net.automatalib.automaton.fsa.NFA;
28
import net.automatalib.automaton.transducer.MealyMachine;
29
import net.automatalib.word.Word;
30

31
public interface PassiveLearningAlgorithm<M, I, D> {
32

33
    void addSamples(Collection<? extends DefaultQuery<I, D>> samples);
34

35
    @SuppressWarnings("unchecked")
36
    default void addSamples(DefaultQuery<I, D>... samples) {
37
        addSamples(Arrays.asList(samples));
×
38
    }
×
39

40
    @SuppressWarnings("unchecked")
41
    default void addSamples(D output, Word<I>... words) {
42
        addSamples(output, Arrays.asList(words));
1✔
43
    }
1✔
44

45
    default void addSamples(D output, Collection<? extends Word<I>> words) {
46
        List<DefaultQuery<I, D>> queries = new ArrayList<>(words.size());
1✔
47
        for (Word<I> word : words) {
1✔
48
            queries.add(new DefaultQuery<>(word, output));
1✔
49
        }
1✔
50

51
        addSamples(queries);
1✔
52
    }
1✔
53

54
    default void addSample(Word<I> input, D output) {
55
        addSample(new DefaultQuery<>(input, output));
1✔
56
    }
1✔
57

58
    default void addSample(DefaultQuery<I, D> sample) {
59
        addSamples(Collections.singleton(sample));
1✔
60
    }
1✔
61

62
    /**
63
     * Computes the model given the previously added samples.
64
     * <p>
65
     * <b>Implementation note:</b> It is up to the implementation if this operation is repeatable or not, An
66
     * implementation may throw an {@link IllegalStateException} if additional samples are added after the first model
67
     * construction.
68
     *
69
     * @return the computed model
70
     */
71
    M computeModel();
72

73
    /**
74
     * Basic interface for passive learning algorithms that infer {@link DFA}s.
75
     *
76
     * @param <I>
77
     *         input symbol type
78
     */
79
    interface PassiveDFALearner<I> extends PassiveAcceptorLearner<DFA<?, I>, I> {}
80

81
    /**
82
     * Basic interface for passive learning algorithms that infer {@link MealyMachine Mealy machines}.
83
     *
84
     * @param <I>
85
     *         input symbol type
86
     * @param <O>
87
     *         output symbol type
88
     */
89
    interface PassiveMealyLearner<I, O> extends PassiveLearningAlgorithm<MealyMachine<?, I, ?, O>, I, Word<O>> {}
90

91
    /**
92
     * Basic interface for passive learning algorithms that infer finite-state acceptors ({@link DFA}s or {@link
93
     * NFA}s).
94
     *
95
     * @param <M>
96
     *         model type
97
     * @param <I>
98
     *         input symbol type
99
     */
100
    interface PassiveAcceptorLearner<M extends FiniteStateAcceptor<?, I>, I>
101
            extends PassiveLearningAlgorithm<M, I, Boolean> {
102

103
        default void addPositiveSample(Word<I> word) {
104
            addSample(word, true);
×
105
        }
×
106

107
        default void addPositiveSamples(Collection<? extends Word<I>> words) {
108
            addSamples(true, words);
1✔
109
        }
1✔
110

111
        @SuppressWarnings("unchecked")
112
        default void addPositiveSamples(Word<I>... words) {
113
            addSamples(true, words);
1✔
114
        }
1✔
115

116
        default void addNegativeSample(Word<I> word) {
117
            addSample(word, false);
×
118
        }
×
119

120
        default void addNegativeSamples(Collection<? extends Word<I>> words) {
121
            addSamples(false, words);
1✔
122
        }
1✔
123

124
        @SuppressWarnings("unchecked")
125
        default void addNegativeSamples(Word<I>... words) {
126
            addSamples(false, words);
1✔
127
        }
1✔
128
    }
129

130
}
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