parent
0765e6243c
commit
b58c50cc54
19
pom.xml
19
pom.xml
|
@ -17,8 +17,27 @@
|
||||||
<target>8</target>
|
<target>8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.0</version>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>RELEASE</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>RELEASE</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -0,0 +1,29 @@
|
||||||
|
package xyz.joethei.studium.algodat.vorlesung;
|
||||||
|
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
|
class KeyboardReader {
|
||||||
|
|
||||||
|
private Stack<Character> stack = new Stack<>();
|
||||||
|
|
||||||
|
private void input(char c) {
|
||||||
|
if(c == '#') stack.pop();
|
||||||
|
else if(c == '~') stack.clear();
|
||||||
|
else stack.push(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
String getString() {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
for (char c : stack) {
|
||||||
|
stringBuilder.append(c);
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void read(String input) {
|
||||||
|
for (char c: input.toCharArray()) {
|
||||||
|
input(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package xyz.joethei.studium.algodat.vorlesung;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class KeyboardReaderTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void druckeTest() {
|
||||||
|
KeyboardReader reader = new KeyboardReader();
|
||||||
|
reader.read("D#dr-+~druk#ckeh#");
|
||||||
|
assertEquals("drucke", reader.getString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void blaTest() {
|
||||||
|
KeyboardReader reader = new KeyboardReader();
|
||||||
|
reader.read("grwgafmrag~grsegsthbrshfb~b#blq#a");
|
||||||
|
assertEquals("bla", reader.getString());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue