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
Raw Normal View History

2022-11-16 23:51:58 +00:00
package com.github.dtschust.zork;
2022-11-17 20:58:02 +00:00
import com.github.dtschust.zork.utils.CommandReader;
import com.github.dtschust.zork.utils.IOWrapper;
2022-11-16 23:51:58 +00:00
import org.junit.jupiter.api.Test;
2022-11-17 20:58:02 +00:00
import static com.github.stefanbirkner.systemlambda.SystemLambda.catchSystemExit;
2022-11-16 23:51:58 +00:00
import static org.junit.jupiter.api.Assertions.assertEquals;
class ZorkTest {
2022-11-17 20:58:02 +00:00
/** 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
*/
2022-11-16 23:51:58 +00:00
@Test
2022-11-17 20:58:02 +00:00
public void testSampleGame() {
String gameConfig = "sampleGame.xml";
String gameExecution = "RunThroughResults.txt";
CommandReader run = new CommandReader(gameExecution);
IOWrapper io = new IOWrapper(false);
new Thread(() -> {
try {
catchSystemExit(() -> new Zork(gameConfig));
} catch (Exception ignored) {}
}).start();
2022-11-16 23:51:58 +00:00
while(true){
switch(run.getInstructionType()) {
case SEND:
2022-11-17 20:58:02 +00:00
io.write(run.getInstruction());
2022-11-16 23:51:58 +00:00
break;
case RECV:
2022-11-17 20:58:02 +00:00
assertEquals(run.getInstruction(), io.read());
2022-11-16 23:51:58 +00:00
break;
default:
2022-11-17 20:58:02 +00:00
io.restore();
2022-11-16 23:51:58 +00:00
return;
}
}
}
}