Skip to content

Commit

Permalink
Fix to enquote the output of mealy machines in the TFAWriter. (#38)
Browse files Browse the repository at this point in the history
* Fix to enquote the output of mealy machines in the TFAWriter.

Closes #37.

* small refactorings

* add changelog notice

Co-authored-by: mtf90
  • Loading branch information
aschieweck committed Feb 24, 2020
1 parent 96dc14f commit d8d7d96
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
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
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
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

0 comments on commit d8d7d96

Please sign in to comment.