From: JBM Date: Wed, 10 Jun 2020 15:29:00 +0000 (+0200) Subject: This is not the test I was looking for X-Git-Url: https://troll.desast.re/troll.git/commitdiff_plain/465e309013ad6f8dd35035c928ad6eadd154339c?ds=sidebyside This is not the test I was looking for --- diff --git a/src/test/java/TrollTest.java b/src/test/java/TrollTest.java index abbf3c5..e54d413 100644 --- a/src/test/java/TrollTest.java +++ b/src/test/java/TrollTest.java @@ -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 scores = gameResult.scores; assertEquals("Two scores are reported", scores.size(), 2);