182 lines
6.9 KiB
Go
182 lines
6.9 KiB
Go
package pokercore
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestAceLowStraight(t *testing.T) {
|
|
hand := Cards{
|
|
AceOfSpades(),
|
|
DeuceOfHearts(),
|
|
ThreeOfDiamonds(),
|
|
FourOfClubs(),
|
|
FiveOfSpades(),
|
|
}
|
|
assert.True(t, hand.containsStraight(), "Expected hand to be a straight")
|
|
}
|
|
|
|
func TestAceHighStraight(t *testing.T) {
|
|
hand := Cards{
|
|
TenOfSpades(),
|
|
JackOfHearts(),
|
|
KingOfClubs(),
|
|
AceOfSpades(),
|
|
QueenOfDiamonds(),
|
|
}
|
|
|
|
assert.True(t, hand.containsStraight(), "Expected hand to be a straight")
|
|
|
|
newDeck := NewDeckFromCards(hand)
|
|
newDeck.ShuffleDeterministically(123456789)
|
|
fmt.Printf("Shuffled deck: %s\n", newDeck.String())
|
|
fmt.Printf("new deck has %d cards\n", newDeck.Count())
|
|
shuffledHand := newDeck.Deal(5)
|
|
assert.True(t, shuffledHand.containsStraight(), "Expected hand to still be a straight after shuffle")
|
|
}
|
|
|
|
func TestOtherStraight(t *testing.T) {
|
|
hand := Cards{
|
|
DeuceOfSpades(),
|
|
ThreeOfHearts(),
|
|
FourOfDiamonds(),
|
|
FiveOfClubs(),
|
|
SixOfSpades(),
|
|
}
|
|
assert.True(t, hand.containsStraight(), "Expected hand to be a straight")
|
|
|
|
newDeck := NewDeckFromCards(hand)
|
|
newDeck.ShuffleDeterministically(123456789)
|
|
fmt.Printf("Shuffled deck: %s\n", newDeck.String())
|
|
fmt.Printf("new deck has %d cards\n", newDeck.Count())
|
|
shuffledHand := newDeck.Deal(5)
|
|
assert.True(t, shuffledHand.containsStraight(), "Expected hand to still be a straight after shuffle")
|
|
assert.False(t, shuffledHand.containsTwoPair(), "Expected hand to not be two pair")
|
|
|
|
}
|
|
|
|
func TestFlush(t *testing.T) {
|
|
hand := Cards{
|
|
AceOfSpades(),
|
|
DeuceOfSpades(),
|
|
ThreeOfSpades(),
|
|
FourOfSpades(),
|
|
SixOfSpades(),
|
|
}
|
|
assert.True(t, hand.containsFlush(), "Expected hand to be a flush")
|
|
newDeck := NewDeckFromCards(hand)
|
|
newDeck.ShuffleDeterministically(123456789)
|
|
fmt.Printf("Shuffled deck: %s\n", newDeck.String())
|
|
fmt.Printf("new deck has %d cards\n", newDeck.Count())
|
|
shuffledHand := newDeck.Deal(5)
|
|
assert.True(t, shuffledHand.containsFlush(), "Expected hand to still be a flush after shuffle")
|
|
|
|
x := ScoreFlush
|
|
var multiplier HandScore = 100
|
|
x += multiplier * DEUCE.HandScore(AcesHigh)
|
|
multiplier *= 100
|
|
x += multiplier * THREE.HandScore(AcesHigh)
|
|
multiplier *= 100
|
|
x += multiplier * FOUR.HandScore(AcesHigh)
|
|
multiplier *= 100
|
|
x += multiplier * SIX.HandScore(AcesHigh)
|
|
fmt.Printf("a-2-3-4-6 flush score should be: %d\n", x)
|
|
}
|
|
|
|
func TestStraightFlush(t *testing.T) {
|
|
hand := Cards{
|
|
SixOfSpades(),
|
|
DeuceOfSpades(),
|
|
ThreeOfSpades(),
|
|
FourOfSpades(),
|
|
FiveOfSpades(),
|
|
}
|
|
assert.True(t, hand.containsStraight(), "Expected hand to be a straight")
|
|
assert.True(t, hand.containsFlush(), "Expected hand to be a flush")
|
|
assert.True(t, hand.containsStraightFlush(), "Expected hand to be a straight flush")
|
|
assert.False(t, hand.containsRoyalFlush(), "Expected hand to not be a royal flush")
|
|
assert.False(t, hand.containsFourOfAKind(), "Expected hand to not be four of a kind")
|
|
assert.False(t, hand.containsFullHouse(), "Expected hand to not be a full house")
|
|
assert.False(t, hand.containsThreeOfAKind(), "Expected hand to not be three of a kind")
|
|
assert.False(t, hand.containsTwoPair(), "Expected hand to not be two pair")
|
|
assert.False(t, hand.containsPair(), "Expected hand to not be a pair")
|
|
|
|
assert.True(t, hand.HighestRank(AcesHigh) == SIX, "Expected highest rank to be a six")
|
|
|
|
nd := NewDeckFromCards(hand)
|
|
nd.ShuffleDeterministically(123456789)
|
|
fmt.Printf("Shuffled deck: %s\n", nd.String())
|
|
fmt.Printf("new deck has %d cards\n", nd.Count())
|
|
shuffledHand := nd.Deal(5)
|
|
assert.True(t, shuffledHand.containsStraightFlush(), "Expected hand to still be a straight flush after shuffle")
|
|
assert.True(t, shuffledHand.HighestRank(AcesHigh) == SIX, "Expected highest rank to still be a six after shuffle")
|
|
assert.True(t, shuffledHand.HighestRank(AcesLow) == SIX, "Expected highest rank to be a six after shuffle even with aces low")
|
|
}
|
|
|
|
func TestRoyalFlush(t *testing.T) {
|
|
hand := Cards{
|
|
TenOfSpades(),
|
|
JackOfSpades(),
|
|
QueenOfSpades(),
|
|
KingOfSpades(),
|
|
AceOfSpades(),
|
|
}
|
|
assert.True(t, hand.containsStraight(), "Expected hand to be a straight")
|
|
assert.True(t, hand.containsFlush(), "Expected hand to be a flush")
|
|
assert.True(t, hand.containsStraightFlush(), "Expected hand to be a straight flush")
|
|
assert.True(t, hand.containsRoyalFlush(), "Expected hand to be a royal flush")
|
|
|
|
assert.False(t, hand.containsFourOfAKind(), "Expected hand to not be four of a kind")
|
|
assert.False(t, hand.containsFullHouse(), "Expected hand to not be a full house")
|
|
assert.False(t, hand.containsThreeOfAKind(), "Expected hand to not be three of a kind")
|
|
assert.False(t, hand.containsTwoPair(), "Expected hand to not be two pair")
|
|
assert.False(t, hand.containsPair(), "Expected hand to not be a pair")
|
|
|
|
assert.True(t, hand.HighestRank(AcesHigh) == ACE, "Expected highest rank to be an ace")
|
|
assert.False(t, hand.HighestRank(AcesHigh) == TEN, "Expected highest rank to not be an ace")
|
|
}
|
|
|
|
func TestUnmadeHand(t *testing.T) {
|
|
hand := Cards{
|
|
TenOfSpades(),
|
|
JackOfDiamonds(),
|
|
QueenOfSpades(),
|
|
KingOfSpades(),
|
|
DeuceOfSpades(),
|
|
}
|
|
assert.False(t, hand.containsStraight(), "Expected hand to not be a straight")
|
|
assert.False(t, hand.containsFlush(), "Expected hand to not be a flush")
|
|
assert.False(t, hand.containsStraightFlush(), "Expected hand to not be a straight flush")
|
|
assert.False(t, hand.containsRoyalFlush(), "Expected hand to not be a royal flush")
|
|
assert.False(t, hand.containsFourOfAKind(), "Expected hand to not be four of a kind")
|
|
assert.False(t, hand.containsFullHouse(), "Expected hand to not be a full house")
|
|
assert.False(t, hand.containsThreeOfAKind(), "Expected hand to not be three of a kind")
|
|
assert.False(t, hand.containsTwoPair(), "Expected hand to not be two pair")
|
|
assert.False(t, hand.containsPair(), "Expected hand to not be a pair")
|
|
assert.True(t, hand.HighestRank(AcesHigh) == KING, "Expected highest rank to be a king")
|
|
assert.True(t, hand.isUnmadeHand(), "Expected hand to be unmade")
|
|
}
|
|
|
|
func TestTwoPair(t *testing.T) {
|
|
hand := Cards{
|
|
KingOfSpades(),
|
|
JackOfDiamonds(),
|
|
JackOfSpades(),
|
|
KingOfDiamonds(),
|
|
TenOfSpades(),
|
|
}
|
|
assert.False(t, hand.containsStraight(), "Expected hand to not be a straight")
|
|
assert.False(t, hand.containsFlush(), "Expected hand to not be a flush")
|
|
assert.False(t, hand.containsStraightFlush(), "Expected hand to not be a straight flush")
|
|
assert.False(t, hand.containsRoyalFlush(), "Expected hand to not be a royal flush")
|
|
assert.False(t, hand.containsFourOfAKind(), "Expected hand to not be four of a kind")
|
|
assert.False(t, hand.containsFullHouse(), "Expected hand to not be a full house")
|
|
assert.False(t, hand.containsThreeOfAKind(), "Expected hand to not be three of a kind")
|
|
assert.True(t, hand.containsTwoPair(), "Expected hand to be two pair")
|
|
assert.True(t, hand.containsPair(), "Expected hand to also be a pair")
|
|
assert.True(t, hand.HighestRank(AcesHigh) == KING, "Expected highest rank to be a king")
|
|
assert.False(t, hand.isUnmadeHand(), "Expected hand to not be unmade")
|
|
}
|