2019-03-23 09:43:25 +00:00
|
|
|
package pokercore
|
|
|
|
|
2019-03-24 04:13:06 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
2019-03-23 09:43:25 +00:00
|
|
|
|
2019-03-23 11:21:03 +00:00
|
|
|
type ShuffleTestResults []struct {
|
|
|
|
SeedVal int64
|
|
|
|
Expected string
|
|
|
|
}
|
|
|
|
|
2019-03-24 04:12:40 +00:00
|
|
|
func TestPokerDeck(t *testing.T) {
|
2019-03-23 11:21:03 +00:00
|
|
|
d := NewDeck()
|
2024-05-19 03:26:08 +00:00
|
|
|
//fmt.Printf("newdeck: %+v\n", d)
|
2019-03-23 11:21:03 +00:00
|
|
|
d.ShuffleDeterministically(437)
|
2024-05-19 03:26:08 +00:00
|
|
|
//fmt.Printf("deterministically shuffled deck: %+v\n", d)
|
2019-03-23 11:21:03 +00:00
|
|
|
cards := d.Deal(7)
|
2019-03-24 04:13:06 +00:00
|
|
|
expected := "6♥,A♦,7♥,9♣,6♠,9♥,8♣"
|
2024-05-19 03:26:08 +00:00
|
|
|
//fmt.Printf("deterministically shuffled deck after dealing: %+v\n", d)
|
|
|
|
//fmt.Printf("cards: %+v\n", cards)
|
2019-03-24 04:13:06 +00:00
|
|
|
assert.Equal(t, expected, cards.String())
|
2019-03-23 11:21:03 +00:00
|
|
|
|
2019-03-24 04:13:06 +00:00
|
|
|
x := d.Count()
|
2019-03-24 03:59:45 +00:00
|
|
|
assert.Equal(t, 45, x)
|
|
|
|
|
|
|
|
d.ShuffleDeterministically(123456789)
|
|
|
|
cards = d.Deal(10)
|
2019-03-24 04:13:06 +00:00
|
|
|
expected = "A♣,7♠,8♠,4♠,7♦,K♠,2♣,J♦,A♠,2♦"
|
2019-03-24 03:59:45 +00:00
|
|
|
assert.Equal(t, expected, cards.String())
|
2019-03-24 04:13:06 +00:00
|
|
|
x = d.Count()
|
|
|
|
assert.Equal(t, 35, x)
|
2019-03-24 03:59:45 +00:00
|
|
|
|
2019-03-23 09:43:25 +00:00
|
|
|
}
|
2019-03-24 04:13:06 +00:00
|
|
|
|
|
|
|
func TestDealing(t *testing.T) {
|
|
|
|
d := NewDeckFromCards(Cards{
|
|
|
|
Card{Rank: ACE, Suit: HEART},
|
|
|
|
Card{Rank: DEUCE, Suit: HEART},
|
|
|
|
Card{Rank: THREE, Suit: HEART},
|
|
|
|
Card{Rank: FOUR, Suit: HEART},
|
|
|
|
Card{Rank: FIVE, Suit: HEART},
|
|
|
|
})
|
|
|
|
cards := d.Deal(5)
|
|
|
|
expected := "A♥,2♥,3♥,4♥,5♥"
|
|
|
|
assert.Equal(t, expected, cards.String())
|
|
|
|
x := d.Count()
|
|
|
|
assert.Equal(t, 0, x)
|
|
|
|
}
|
2024-05-19 00:33:15 +00:00
|
|
|
|
|
|
|
func TestSpecialCaseOfFiveHighStraightFlush(t *testing.T) {
|
|
|
|
// actual bug from first implementation
|
|
|
|
d := NewDeckFromCards(Cards{
|
|
|
|
Card{Rank: ACE, Suit: HEART},
|
|
|
|
Card{Rank: DEUCE, Suit: HEART},
|
|
|
|
Card{Rank: THREE, Suit: HEART},
|
|
|
|
Card{Rank: FOUR, Suit: HEART},
|
|
|
|
Card{Rank: FIVE, Suit: HEART},
|
|
|
|
})
|
|
|
|
cards := d.Deal(5)
|
|
|
|
expected := "A♥,2♥,3♥,4♥,5♥"
|
|
|
|
assert.Equal(t, expected, cards.String())
|
|
|
|
ph, err := cards.PokerHand()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
description := ph.Description()
|
|
|
|
assert.Equal(t, "a five high straight flush in ♥", description)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSpecialCaseOfFiveHighStraight(t *testing.T) {
|
|
|
|
// actual bug from first implementation
|
|
|
|
d := NewDeckFromCards(Cards{
|
|
|
|
Card{Rank: ACE, Suit: HEART},
|
|
|
|
Card{Rank: DEUCE, Suit: HEART},
|
|
|
|
Card{Rank: THREE, Suit: SPADE},
|
|
|
|
Card{Rank: FOUR, Suit: HEART},
|
|
|
|
Card{Rank: FIVE, Suit: CLUB},
|
|
|
|
})
|
|
|
|
d.ShuffleDeterministically(123456789)
|
|
|
|
cards := d.Deal(5)
|
|
|
|
|
|
|
|
cards = cards.SortByRankAscending()
|
|
|
|
expected := "2♥,3♠,4♥,5♣,A♥"
|
|
|
|
assert.Equal(t, expected, cards.String())
|
|
|
|
ph, err := cards.PokerHand()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
description := ph.Description()
|
|
|
|
assert.Equal(t, "a five high straight", description)
|
|
|
|
}
|