Implemented tests for double or nothing.

This commit is contained in:
neviyn 2017-01-22 15:34:48 +00:00
parent 9b5952b8cd
commit 96fdb1eb1a
3 changed files with 44 additions and 3 deletions

View File

@ -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);
}
}

View File

@ -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();
}
}
}

View File

@ -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;