Implemented tests for double or nothing.
This commit is contained in:
parent
9b5952b8cd
commit
96fdb1eb1a
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
Loading…
Reference in New Issue
Block a user