parent
e71316d70a
commit
ce5a1d219b
@ -0,0 +1,162 @@ |
|||||||
|
package net.pokeranalytics.android |
||||||
|
|
||||||
|
import net.pokeranalytics.android.model.handhistory.HandSetup |
||||||
|
import net.pokeranalytics.android.model.handhistory.Street |
||||||
|
import net.pokeranalytics.android.model.realm.handhistory.Action |
||||||
|
import net.pokeranalytics.android.model.realm.handhistory.Card |
||||||
|
import net.pokeranalytics.android.model.realm.handhistory.HandHistory |
||||||
|
import net.pokeranalytics.android.model.realm.handhistory.PlayerSetup |
||||||
|
import org.junit.Assert |
||||||
|
import org.junit.Test |
||||||
|
|
||||||
|
fun HandHistory.addAction(street: Street, position: Int, type: Action.Type, effectiveAmount: Double = 0.0) { |
||||||
|
val action = Action() |
||||||
|
action.street = street |
||||||
|
action.position = position |
||||||
|
action.type = type |
||||||
|
// action.amount = amount |
||||||
|
action.effectiveAmount = effectiveAmount |
||||||
|
action.index = this.actions.size |
||||||
|
this.actions.add(action) |
||||||
|
} |
||||||
|
|
||||||
|
class HandHistoryTest { |
||||||
|
|
||||||
|
private fun handHistoryInstance(players: Int): HandHistory { |
||||||
|
val hh = HandHistory() |
||||||
|
val hs = HandSetup() |
||||||
|
hs.smallBlind = 1.0 |
||||||
|
hs.bigBlind = 2.0 |
||||||
|
hs.tableSize = players |
||||||
|
|
||||||
|
hh.configure(hs) |
||||||
|
return hh |
||||||
|
} |
||||||
|
|
||||||
|
private fun playerSetupInstance(position: Int, cards: List<Card>): PlayerSetup { |
||||||
|
val ps = PlayerSetup() |
||||||
|
ps.position = position |
||||||
|
ps.cards.addAll(cards) |
||||||
|
return ps |
||||||
|
} |
||||||
|
|
||||||
|
private fun card(value: Int, suit: Int): Card { |
||||||
|
return Card.newInstance(value, Card.Suit.valueOf(suit)) |
||||||
|
} |
||||||
|
|
||||||
|
private fun board(values: List<Int>, suits: List<Int>): List<Card> { |
||||||
|
val cards = mutableListOf<Card>() |
||||||
|
(0 until 5).forEach { index -> |
||||||
|
cards.add(card(values[index], suits[index])) |
||||||
|
} |
||||||
|
return cards |
||||||
|
} |
||||||
|
|
||||||
|
private val delta = 0.0001 |
||||||
|
|
||||||
|
@Test |
||||||
|
fun potTest1() { // A simple BET / FOLD |
||||||
|
|
||||||
|
val hh = handHistoryInstance(2) |
||||||
|
hh.addAction(Street.PREFLOP, 0, Action.Type.CHECK) |
||||||
|
hh.addAction(Street.PREFLOP, 1, Action.Type.BET, 6.0) |
||||||
|
hh.addAction(Street.PREFLOP, 0, Action.Type.FOLD) |
||||||
|
|
||||||
|
hh.defineWinnerPositions() |
||||||
|
|
||||||
|
val winnerPots = hh.winnerPots |
||||||
|
assert(winnerPots.size == 1) |
||||||
|
|
||||||
|
val wp = winnerPots.first()!! |
||||||
|
Assert.assertEquals(9.0, wp.amount, delta) |
||||||
|
Assert.assertEquals(1, wp.position) |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
fun potTest2() { // A simple BET / CALL |
||||||
|
|
||||||
|
val hh = handHistoryInstance(2) |
||||||
|
hh.addAction(Street.PREFLOP, 0, Action.Type.BET, 6.0) |
||||||
|
hh.addAction(Street.PREFLOP, 1, Action.Type.CALL, 6.0) |
||||||
|
|
||||||
|
val ps1 = playerSetupInstance(0, listOf(card(3, 0), card(3, 1))) |
||||||
|
val ps2 = playerSetupInstance(1, listOf(card(2, 0), card(2, 1))) |
||||||
|
hh.playerSetups.addAll(listOf(ps1, ps2)) |
||||||
|
|
||||||
|
hh.board.addAll(board(listOf(4, 5, 6, 7, 9), listOf(0, 1, 2, 1, 2))) |
||||||
|
|
||||||
|
hh.defineWinnerPositions() |
||||||
|
|
||||||
|
val winnerPots = hh.winnerPots |
||||||
|
Assert.assertEquals(1, winnerPots.size) |
||||||
|
|
||||||
|
val wp = winnerPots.first()!! |
||||||
|
Assert.assertEquals(15.0, wp.amount, delta) |
||||||
|
Assert.assertEquals(0, wp.position) |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
fun potTest3() { // A split pot with a BET / CALL with same hand, a flush |
||||||
|
|
||||||
|
val hh = handHistoryInstance(2) |
||||||
|
hh.addAction(Street.PREFLOP, 0, Action.Type.BET, 6.0) |
||||||
|
hh.addAction(Street.PREFLOP, 1, Action.Type.CALL, 6.0) |
||||||
|
|
||||||
|
val ps1 = playerSetupInstance(0, listOf(card(3, 0), card(3, 1))) |
||||||
|
val ps2 = playerSetupInstance(1, listOf(card(2, 0), card(2, 1))) |
||||||
|
hh.playerSetups.addAll(listOf(ps1, ps2)) |
||||||
|
|
||||||
|
hh.board.addAll(board(listOf(4, 5, 6, 7, 9), listOf(3, 3, 3, 3, 3))) |
||||||
|
|
||||||
|
hh.defineWinnerPositions() |
||||||
|
|
||||||
|
val winnerPots = hh.winnerPots |
||||||
|
Assert.assertEquals(2, winnerPots.size) |
||||||
|
|
||||||
|
winnerPots.forEach { |
||||||
|
Assert.assertEquals(7.5, it.amount, delta) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
fun potTest4() { // A multi allin pot |
||||||
|
|
||||||
|
val hh = handHistoryInstance(3) // 3 |
||||||
|
hh.addAction(Street.PREFLOP, 0, Action.Type.BET, 6.0) |
||||||
|
hh.addAction(Street.PREFLOP, 1, Action.Type.CALL, 6.0) |
||||||
|
hh.addAction(Street.PREFLOP, 2, Action.Type.CALL, 6.0) // 21 |
||||||
|
|
||||||
|
hh.addAction(Street.FLOP, 0, Action.Type.BET, 10.0) |
||||||
|
hh.addAction(Street.FLOP, 1, Action.Type.CALL, 10.0) |
||||||
|
hh.addAction(Street.FLOP, 2, Action.Type.RAISE_ALLIN, 100.0) |
||||||
|
hh.addAction(Street.FLOP, 0, Action.Type.CALL, 90.0) |
||||||
|
hh.addAction(Street.FLOP, 1, Action.Type.CALL, 90.0) // main 321 |
||||||
|
|
||||||
|
hh.addAction(Street.TURN, 0, Action.Type.BET, 100.0) |
||||||
|
hh.addAction(Street.TURN, 1, Action.Type.RAISE_ALLIN, 200.0) |
||||||
|
hh.addAction(Street.TURN, 0, Action.Type.CALL, 100.0) // side 400 |
||||||
|
|
||||||
|
val ps0 = playerSetupInstance(0, listOf(card(10, 3), card(2, 1))) |
||||||
|
val ps1 = playerSetupInstance(1, listOf(card(2, 3), card(3, 1))) |
||||||
|
val ps2 = playerSetupInstance(2, listOf(card(12, 3), card(2, 1))) |
||||||
|
hh.playerSetups.addAll(listOf(ps0, ps1, ps2)) |
||||||
|
|
||||||
|
hh.board.addAll(board(listOf(4, 5, 6, 7, 9), listOf(3, 3, 3, 3, 3))) |
||||||
|
|
||||||
|
hh.defineWinnerPositions() |
||||||
|
|
||||||
|
val winnerPots = hh.winnerPots |
||||||
|
Assert.assertEquals(2, winnerPots.size) |
||||||
|
|
||||||
|
val mainPot = winnerPots.first { it.position == 2 } |
||||||
|
Assert.assertEquals(321.0, mainPot.amount, delta) |
||||||
|
|
||||||
|
val sidePot = winnerPots.first { it.position == 0 } |
||||||
|
Assert.assertEquals(400.0, sidePot.amount, delta) |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue