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

LearnLib / learnlib / 6433387082

06 Oct 2023 03:10PM UTC coverage: 92.296% (-0.007%) from 92.303%
6433387082

push

github

mtf90
update Falk's developer id

11573 of 12539 relevant lines covered (92.3%)

1.67 hits per line

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

94.29
/drivers/simulator/src/main/java/de/learnlib/driver/util/MealySimulatorSUL.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.driver.util;
17

18
import de.learnlib.api.SUL;
19
import net.automatalib.automata.transducers.MealyMachine;
20
import org.checkerframework.checker.nullness.qual.Nullable;
21

22
/**
23
 * A {@link SUL} that implements steps by stepping through a {@link MealyMachine}.
24
 * <p>
25
 * Note: this SUL is {@link SUL#fork() forkable}.
26
 *
27
 * @param <I>
28
 *         input symbol type
29
 * @param <O>
30
 *         output symbol type
31
 */
32
public class MealySimulatorSUL<I, O> implements SUL<I, O> {
33

34
    private final MealySimulatorSULImpl<?, I, ?, O> impl;
35

36
    /**
37
     * Constructor, using {@code null} as the output for undefined transitions.
38
     * <p>
39
     * This constructor is provided for convenience. It is equivalent to calling {@link #MealySimulatorSUL(MealyMachine,
40
     * Object)} with {@code null} as the second argument.
41
     *
42
     * @param mealy
43
     *         Mealy machine
44
     */
45
    public MealySimulatorSUL(MealyMachine<?, I, ?, O> mealy) {
46
        this(mealy, null);
1✔
47
    }
1✔
48

49
    /**
50
     * Constructor.
51
     * <p>
52
     * If the given Mealy machine has no undefined transitions, the second parameter has no effect. Otherwise, if the
53
     * Mealy machine is partial and sequences of {@link #step(Object)} invocations reach an undefined transition,
54
     * subsequent invocations of {@link #step(Object)} will simply return the specified {@code noTransOut} symbol.
55
     *
56
     * @param mealy
57
     *         the Mealy machine
58
     * @param noTransOut
59
     *         the output symbol to use when encountering undefined transitions
60
     */
61
    public MealySimulatorSUL(MealyMachine<?, I, ?, O> mealy, O noTransOut) {
62
        this(new MealySimulatorSULImpl<>(mealy, noTransOut));
1✔
63
    }
1✔
64

65
    protected MealySimulatorSUL(MealySimulatorSULImpl<?, I, ?, O> impl) {
1✔
66
        this.impl = impl;
1✔
67
    }
1✔
68

69
    @Override
70
    public void pre() {
71
        impl.pre();
1✔
72
    }
1✔
73

74
    @Override
75
    public void post() {
76
        impl.post();
1✔
77
    }
1✔
78

79
    @Override
80
    public O step(I in) {
81
        return impl.step(in);
1✔
82
    }
83

84
    @Override
85
    public boolean canFork() {
86
        return impl.canFork();
1✔
87
    }
88

89
    @Override
90
    public SUL<I, O> fork() {
91
        return new MealySimulatorSUL<>(impl.fork());
1✔
92
    }
93

94
    /**
95
     * Implementation class, used to hide {@code S} and {@code T} type parameters.
96
     *
97
     * @param <S>
98
     *         Mealy machine state type
99
     * @param <I>
100
     *         input symbol type
101
     * @param <T>
102
     *         Mealy machine transition type
103
     * @param <O>
104
     *         output symbol type
105
     */
106
    static class MealySimulatorSULImpl<S, I, T, O> implements SUL<I, O> {
107

108
        private final MealyMachine<S, I, T, O> mealy;
109
        private final O noTransOut;
110
        private @Nullable S curr;
111

112
        MealySimulatorSULImpl(MealyMachine<S, I, T, O> mealy, O noTransOut) {
1✔
113
            this.mealy = mealy;
1✔
114
            this.noTransOut = noTransOut;
1✔
115
        }
1✔
116

117
        @Override
118
        public void pre() {
119
            this.curr = mealy.getInitialState();
1✔
120
        }
1✔
121

122
        @Override
123
        public void post() {
124
            this.curr = null;
1✔
125
        }
1✔
126

127
        @Override
128
        public O step(I in) {
129
            O out = noTransOut;
1✔
130
            if (curr != null) {
1✔
131
                T trans = mealy.getTransition(curr, in);
1✔
132
                if (trans != null) {
1✔
133
                    out = mealy.getTransitionOutput(trans);
1✔
134
                    curr = mealy.getSuccessor(trans);
1✔
135
                } else {
136
                    curr = null;
×
137
                }
138
            }
139
            return out;
1✔
140
        }
141

142
        @Override
143
        public boolean canFork() {
144
            return true;
1✔
145
        }
146

147
        @Override
148
        public MealySimulatorSULImpl<S, I, T, O> fork() {
149
            return new MealySimulatorSULImpl<>(mealy, noTransOut);
1✔
150
        }
151

152
        S getCurr() {
153
            if (curr == null) {
1✔
154
                throw new IllegalStateException("SUL was not properly initialized");
×
155
            }
156
            return curr;
1✔
157
        }
158
    }
159

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