public class TrollTest {
@Test
- public void test() {
+ public void drawGame() {
MultiplayerGameRunner gameRunner = new MultiplayerGameRunner();
Properties gameParameters = new Properties();
gameParameters.setProperty("roadLength", "6");
assertIsDraw(gameRunner.simulate());
}
+ @Test
+ public void crashGame() {
+ MultiplayerGameRunner gameRunner = new MultiplayerGameRunner();
+ Properties gameParameters = new Properties();
+ gameParameters.setProperty("roadLength", "6");
+ gameParameters.setProperty("initialStones", "15");
+ gameRunner.setGameParameters(gameParameters);
+ gameRunner.setSeed(0l);
+ gameRunner.setLeagueLevel(1);
+
+ gameRunner.addAgent(agentCrash);
+ gameRunner.addAgent(agentCrash);
+
+ assertIsDefeat(gameRunner.simulate());
+ }
+
// great thanks to @dbdr for the intense moral support leading to
// the following:
static String agentOne = "yes 1";
static String agentTwo = "yes 2";
+ static String agentCrash = "false";
static void dumpGameResult(PrintStream p, GameResult gameResult) {
for (AgentDto agent : gameResult.agents) dumpAgent(p, agent);
int s1 = scores[0], s2 = scores[1];
assertEquals("Player scores are equal", s1, s2);
- dumpGameResult(System.err, gameResult);
assertTrue("Player scores are non-negative", s1 >= 0);
}
+ static void assertIsDefeat(GameResult gameResult) {
+ int[] scores = assertTwoScores(gameResult);
+ if (scores == null) return;
+
+ int s1 = scores[0], s2 = scores[1];
+ assertTrue("First player score is negative", s1 < 0);
+ assertTrue("Second player score is negative", s2 < 0);
+ }
+
static int[] assertTwoScores(GameResult gameResult) {
Map<Integer,Integer> scores = gameResult.scores;
assertEquals("Two scores are reported", scores.size(), 2);