hands to uint64

This commit is contained in:
Bel LaPointe
2021-03-17 13:35:48 -05:00
parent 0c406e3163
commit cc4a19a47c
4 changed files with 304 additions and 49 deletions

View File

@@ -102,6 +102,123 @@ func TestFlush(t *testing.T) {
}
}
func TestHighCard(t *testing.T) {
cases := map[string]testHandCase{
"no cards": {
want: 0,
},
"seven card": {
public: []entity.Card{
entity.Card{Value: 13},
entity.Card{Value: 11},
entity.Card{Value: 11},
entity.Card{Value: 11},
entity.Card{Value: 11},
entity.Card{Value: 3},
entity.Card{Value: 4},
},
want: 13111111110403,
},
"four card": {
public: []entity.Card{
entity.Card{Value: 13},
entity.Card{Value: 11},
entity.Card{Value: 3},
entity.Card{Value: 4},
},
want: 13110403,
},
"three card": {
public: []entity.Card{
entity.Card{Value: 13},
entity.Card{Value: 3},
entity.Card{Value: 4},
},
want: 130403,
},
"two card": {
public: []entity.Card{
entity.Card{Value: 3},
entity.Card{Value: 4},
},
want: 403,
},
"one card": {
public: []entity.Card{
entity.Card{Value: 3},
},
want: 3,
},
}
for name, d := range cases {
testHand(t, name, highCard, d.public, d.private, d.want)
}
}
func TestTwoPair(t *testing.T) {
cases := map[string]testHandCase{
"no cards": {
want: 0,
},
"no pair": {
public: []entity.Card{
entity.Card{Value: 11},
entity.Card{Value: 10},
},
want: 0,
},
"one pair": {
public: []entity.Card{
entity.Card{Value: 11},
entity.Card{Value: 11},
},
want: 0,
},
"no second pair": {
public: []entity.Card{
entity.Card{Value: 12},
entity.Card{Value: 12},
entity.Card{Value: 11},
entity.Card{Value: 10},
},
want: 0,
},
"two pair diff": {
public: []entity.Card{
entity.Card{Value: 11},
entity.Card{Value: 11},
entity.Card{Value: 10},
entity.Card{Value: 10},
},
want: 111000,
},
"two pair same": {
public: []entity.Card{
entity.Card{Value: 11},
entity.Card{Value: 11},
entity.Card{Value: 11},
entity.Card{Value: 11},
},
want: 111100,
},
"two pair high": {
public: []entity.Card{
entity.Card{Value: 11},
entity.Card{Value: 11},
entity.Card{Value: 10},
entity.Card{Value: 10},
entity.Card{Value: 13},
},
want: 111013,
},
}
for name, d := range cases {
testHand(t, name, twoPair, d.public, d.private, d.want)
}
}
func TestFullHouse(t *testing.T) {
cases := map[string]testHandCase{
"no cards": {
@@ -144,8 +261,8 @@ func TestFullHouse(t *testing.T) {
}
}
func TestFourOfAKind(t *testing.T) {
cases := map[string]testHandCase{
func TestNOfAKind(t *testing.T) {
cases4 := map[string]testHandCase{
"no cards": {
want: 0,
},
@@ -191,9 +308,118 @@ func TestFourOfAKind(t *testing.T) {
},
}
for name, d := range cases {
for name, d := range cases4 {
testHand(t, name, fourOfAKind, d.public, d.private, d.want)
}
cases2 := map[string]testHandCase{
"no cards": {
want: 0,
},
"one card": {
public: []entity.Card{
entity.Card{Value: 5},
},
want: 0,
},
"two cards": {
public: []entity.Card{
entity.Card{Value: 5},
entity.Card{Value: 5},
},
want: 500,
},
"three cards": {
public: []entity.Card{
entity.Card{Value: 5},
entity.Card{Value: 5},
entity.Card{Value: 5},
},
want: 505,
},
"four cards, two diff pairs": {
public: []entity.Card{
entity.Card{Value: 4},
entity.Card{Value: 4},
entity.Card{Value: 5},
entity.Card{Value: 5},
},
want: 504,
},
"four cards": {
public: []entity.Card{
entity.Card{Value: 5},
entity.Card{Value: 5},
entity.Card{Value: 5},
entity.Card{Value: 5},
},
want: 505,
},
"five cards": {
public: []entity.Card{
entity.Card{Value: 5},
entity.Card{Value: 5},
entity.Card{Value: 5},
entity.Card{Value: 5},
entity.Card{Value: 5},
},
want: 505,
},
}
for name, d := range cases2 {
testHand(t, name, pair, d.public, d.private, d.want)
}
cases3 := map[string]testHandCase{
"no cards": {
want: 0,
},
"one card": {
public: []entity.Card{
entity.Card{Value: 5},
},
want: 0,
},
"two cards": {
public: []entity.Card{
entity.Card{Value: 5},
entity.Card{Value: 5},
},
want: 0,
},
"three cards": {
public: []entity.Card{
entity.Card{Value: 5},
entity.Card{Value: 5},
entity.Card{Value: 5},
},
want: 500,
},
"four cards": {
public: []entity.Card{
entity.Card{Value: 5},
entity.Card{Value: 5},
entity.Card{Value: 5},
entity.Card{Value: 5},
},
want: 505,
},
"five cards": {
public: []entity.Card{
entity.Card{Value: 5},
entity.Card{Value: 5},
entity.Card{Value: 5},
entity.Card{Value: 5},
entity.Card{Value: 5},
},
want: 505,
},
}
for name, d := range cases3 {
testHand(t, name, threeOfAKind, d.public, d.private, d.want)
}
}
func TestStraightFlush(t *testing.T) {
@@ -272,7 +498,7 @@ func testHand(t *testing.T, name string, foo Int, public []entity.Card, private
},
}
got := foo(game, nil)
if got != want {
if got != uint64(want) {
t.Fatal(want, got)
}
})