This is not the test I was looking for
authorJBM <jbm@codingame.com>
Wed, 10 Jun 2020 15:29:00 +0000 (17:29 +0200)
committerJBM <jbm@codingame.com>
Wed, 10 Jun 2020 15:29:00 +0000 (17:29 +0200)
src/test/java/TrollTest.java

index abbf3c5..e54d413 100644 (file)
@@ -12,7 +12,7 @@ import com.codingame.gameengine.runner.dto.*;
 
 public class TrollTest {
     @Test
-    public void test() {
+    public void drawGame() {
         MultiplayerGameRunner gameRunner = new MultiplayerGameRunner();
         Properties gameParameters = new Properties();
         gameParameters.setProperty("roadLength", "6");
@@ -27,10 +27,27 @@ public class TrollTest {
         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);
@@ -83,10 +100,18 @@ public class TrollTest {
 
         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);