diff --git a/Test/Aufgabe1_KellerautomatTest.java b/Test/Aufgabe1_KellerautomatTest.java index ae511ad..e8f69bb 100644 --- a/Test/Aufgabe1_KellerautomatTest.java +++ b/Test/Aufgabe1_KellerautomatTest.java @@ -6,12 +6,12 @@ class Aufgabe1_KellerautomatTest { @Test void calculate() { - String[] acceptableWords = {"ZZO", "ZZOZZOO", "ZZZOO"}; + String[] acceptableWords = {"ZZ+", "ZZ*ZZ+*", "ZZZ*+"}; for (String word : acceptableWords) { assertTrue(Aufgabe1_Kellerautomat.calculate(word)); } - String[] notAcceptableWords = {"ZZOO", "ZZOZZO", "ZOZ"}; + String[] notAcceptableWords = {"ZZ*+", "ZZ+ZZ*", "Z*Z"}; for (String word : notAcceptableWords) { assertFalse(Aufgabe1_Kellerautomat.calculate(word)); } diff --git a/src/Aufgabe1_Kellerautomat.java b/src/Aufgabe1_Kellerautomat.java index 41ff12c..e799a0a 100644 --- a/src/Aufgabe1_Kellerautomat.java +++ b/src/Aufgabe1_Kellerautomat.java @@ -48,7 +48,7 @@ public class Aufgabe1_Kellerautomat { break; case 2: symbol = wordChars.remove(0); - if (symbol == 'O' && stackSymbol == 'Z') { + if (isOperator(symbol) && stackSymbol == 'Z') { state = 3; } else if (symbol == 'Z' && stackSymbol == 'Z') { stack.add('Z'); @@ -79,7 +79,7 @@ public class Aufgabe1_Kellerautomat { stack.add('Z'); stack.add('Z'); state = 2; - } else if (symbol == 'O' && stackSymbol == 'Z') { + } else if (isOperator(symbol) && stackSymbol == 'Z') { state = 3; } else { dontAccept(word); @@ -121,4 +121,8 @@ public class Aufgabe1_Kellerautomat { System.out.println("Word: " + word + "\naccepted "); } + private static boolean isOperator(char symbol){ + return symbol == '+' || symbol == '*'; + } + }