From 96fdb1eb1a54d9329ff0c8c5d8a076ec4ee3b8ba Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Sun, 22 Jan 2017 15:34:48 +0000 Subject: [PATCH] Implemented tests for double or nothing. --- .../co/neviyn/pokergame/model/DONResult.java | 5 +++ .../pokergame/game/DoubleOrNothingTest.java | 38 +++++++++++++++++++ .../co/neviyn/pokergame}/game/HandTest.java | 4 +- 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 src/test/java/uk/co/neviyn/pokergame/game/DoubleOrNothingTest.java rename src/test/java/{ => uk/co/neviyn/pokergame}/game/HandTest.java (98%) diff --git a/src/main/java/uk/co/neviyn/pokergame/model/DONResult.java b/src/main/java/uk/co/neviyn/pokergame/model/DONResult.java index 422bc84..a95cc2b 100644 --- a/src/main/java/uk/co/neviyn/pokergame/model/DONResult.java +++ b/src/main/java/uk/co/neviyn/pokergame/model/DONResult.java @@ -21,4 +21,9 @@ public class DONResult { public boolean isWin() { return win; } + + @Override + public String toString() { + return String.format("card: %s, win: %b", card.getShortName(), win); + } } diff --git a/src/test/java/uk/co/neviyn/pokergame/game/DoubleOrNothingTest.java b/src/test/java/uk/co/neviyn/pokergame/game/DoubleOrNothingTest.java new file mode 100644 index 0000000..ca41926 --- /dev/null +++ b/src/test/java/uk/co/neviyn/pokergame/game/DoubleOrNothingTest.java @@ -0,0 +1,38 @@ +package uk.co.neviyn.pokergame.game; + +import org.junit.Before; +import org.junit.Test; +import uk.co.neviyn.pokergame.model.Card; +import uk.co.neviyn.pokergame.model.DONResult; + +import static org.junit.Assert.*; + +public class DoubleOrNothingTest { + + DoubleOrNothing doubleOrNothing; + + @Before + public void setUp(){ + doubleOrNothing = new DoubleOrNothing(); + } + + @Test + public void testPlayTryToWin() throws Exception { + while(doubleOrNothing.isPlayable()) { + assertTrue(doubleOrNothing.play(doubleOrNothing.getCurrentCard().compareTo(doubleOrNothing.cheat()) <= 0).isWin()); + } + } + + @Test + public void testPlayTryToLose() throws Exception { + Card card = doubleOrNothing.getCurrentCard(); + while(doubleOrNothing.isPlayable()) { + DONResult result = doubleOrNothing.play(doubleOrNothing.getCurrentCard().compareTo(doubleOrNothing.cheat()) > 0); + if(card.getValue() == result.getCard().getValue()) // If it's a draw we technically win. + assertTrue(result.isWin()); + else + assertFalse(result.isWin()); + card = result.getCard(); + } + } +} \ No newline at end of file diff --git a/src/test/java/game/HandTest.java b/src/test/java/uk/co/neviyn/pokergame/game/HandTest.java similarity index 98% rename from src/test/java/game/HandTest.java rename to src/test/java/uk/co/neviyn/pokergame/game/HandTest.java index b33ecaa..eab97be 100644 --- a/src/test/java/game/HandTest.java +++ b/src/test/java/uk/co/neviyn/pokergame/game/HandTest.java @@ -1,12 +1,10 @@ -package game; +package uk.co.neviyn.pokergame.game; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import uk.co.neviyn.pokergame.game.Hand; -import uk.co.neviyn.pokergame.game.IDeck; import uk.co.neviyn.pokergame.model.Card; import uk.co.neviyn.pokergame.model.Result; import uk.co.neviyn.pokergame.model.Suit;