This repository has been archived on 2022-12-21. You can view files and clone it, but cannot push or open issues or pull requests.
sdm03/src/test/java/com/github/dtschust/zork/ZorkTest.java

42 lines
1.3 KiB
Java

package com.github.dtschust.zork;
import com.github.dtschust.zork.utils.CommandReader;
import com.github.dtschust.zork.utils.IOWrapper;
import org.junit.jupiter.api.Test;
import static com.github.stefanbirkner.systemlambda.SystemLambda.catchSystemExit;
import static org.junit.jupiter.api.Assertions.assertEquals;
class ZorkTest {
/** Test the game interacting as a real player
* WARNING: when looking at inventory (i) we are relying on the HashMap order, so the test may be unsafe
*/
@Test
void testSampleGame() {
String gameConfig = "sampleGame.xml";
String gameExecution = "RunThroughResults.txt";
CommandReader run = new CommandReader(gameExecution);
IOWrapper io = new IOWrapper(true);
new Thread(() -> {
try {
catchSystemExit(() -> Zork.runZork(gameConfig));
} catch (Exception ignored) {}
}).start();
while(true){
switch(run.getInstructionType()) {
case SEND:
io.write(run.getInstruction());
break;
case RECV:
assertEquals(run.getInstruction(), io.read());
break;
default:
io.restore();
return;
}
}
}
}