Skip to content

Fix to enquote the output of mealy machines in the TFAWriter. #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* Removed `IOUtil#copy`, `IOUtil.skip`, `NullOutputStream`. Use the Guava equivalents from `ByteStreams` and `CharStreams`.


### Fixed

* Correctly enquote outputs containing whitespaces in `TAFWriter` ([#37](https://github.com/LearnLib/automatalib/issues/37), thanks to [Alexander Schieweck](https://github.com/aschieweck)).


## [0.9.0](https://github.com/LearnLib/automatalib/releases/tag/automatalib-0.9.0) - 2020-02-05

[Full changelog](https://github.com/LearnLib/automatalib/compare/automatalib-0.8.0...automatalib-0.9.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private void writeTransition(Collection<?> symbols, String target, @Nullable Obj
writeIndent();
writeStringCollection(symbols);
if (output != null) {
out.append(" / ").append(output.toString());
out.append(" / ").append(StringUtil.enquoteIfNecessary(output.toString()));
}
out.append(" -> ").append(target).append(System.lineSeparator());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,39 @@
*/
public class TAFSerializationTest {

private static final Alphabet<String> ALPHABET = Alphabets.closedCharStringRange('0', '3');
private static final Alphabet<String> INPUT_ALPHABET = Alphabets.closedCharStringRange('0', '3');

private static final Alphabet<String> OUTPUT_ALPHABET = Alphabets.fromArray("Hello", "World", "Hello World");

private static final int AUTOMATON_SIZE = 20;

@Test
public void testDFASerialization() throws Exception {

final CompactDFA<String> automaton = RandomAutomata.randomDFA(new Random(0), AUTOMATON_SIZE, ALPHABET);
final CompactDFA<String> automaton = RandomAutomata.randomDFA(new Random(0), AUTOMATON_SIZE, INPUT_ALPHABET);

weedOutTransitions(automaton);

final TAFSerializationDFA serializer = TAFSerializationDFA.getInstance();
final DFA<Integer, String> deserializedModel = writeAndReadModel(automaton, ALPHABET, serializer, serializer);
final DFA<Integer, String> deserializedModel =
writeAndReadModel(automaton, INPUT_ALPHABET, serializer, serializer);

Assert.assertTrue(Automata.testEquivalence(automaton, deserializedModel, ALPHABET));
Assert.assertTrue(Automata.testEquivalence(automaton, deserializedModel, INPUT_ALPHABET));
}

@Test
public void testMealySerialization() throws Exception {
final CompactMealy<String, String> automaton =
RandomAutomata.randomMealy(new Random(0), AUTOMATON_SIZE, ALPHABET, ALPHABET);
RandomAutomata.randomMealy(new Random(0), AUTOMATON_SIZE, INPUT_ALPHABET, OUTPUT_ALPHABET);

weedOutTransitions(automaton);

final TAFSerializationMealy serializer = TAFSerializationMealy.getInstance();

final MealyMachine<?, String, ?, String> deserializedModel =
writeAndReadModel(automaton, ALPHABET, serializer, serializer);
writeAndReadModel(automaton, INPUT_ALPHABET, serializer, serializer);

Assert.assertTrue(Automata.testEquivalence(automaton, deserializedModel, ALPHABET));
Assert.assertTrue(Automata.testEquivalence(automaton, deserializedModel, INPUT_ALPHABET));
}

private <T, A extends MutableDeterministic<Integer, String, T, ?, ?>> void weedOutTransitions(A automaton) {
Expand All @@ -80,7 +83,7 @@ public void testMealySerialization() throws Exception {
// remove some transitions for partiality
for (int i = 0; i < AUTOMATON_SIZE; i++) {
final int rState = random.nextInt(AUTOMATON_SIZE);
final String rInput = ALPHABET.getSymbol(random.nextInt(ALPHABET.size()));
final String rInput = INPUT_ALPHABET.getSymbol(random.nextInt(INPUT_ALPHABET.size()));

automaton.removeTransition(rState, rInput, automaton.getTransition(rState, rInput));
}
Expand Down