2023-12-07 19:21:10 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
_ "embed"
|
|
|
|
|
|
|
|
"github.com/matryer/is"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AKQJT98765432
|
|
|
|
// dcba987654321
|
|
|
|
|
|
|
|
//go:embed example.txt
|
|
|
|
var example []byte
|
|
|
|
|
|
|
|
//go:embed input.txt
|
|
|
|
var input []byte
|
|
|
|
|
|
|
|
func TestHands(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
|
|
|
|
var game Game
|
2023-12-07 20:09:58 -07:00
|
|
|
game.cardOrder = getOrder(cardTypes1)
|
2023-12-07 19:21:10 -07:00
|
|
|
|
2023-12-08 12:11:44 -07:00
|
|
|
h := Play{hand: []rune("AAA23"), game: &game}
|
|
|
|
// h.generateCounts()
|
2023-12-07 19:21:10 -07:00
|
|
|
is.Equal(h.HandType(), "3K-A")
|
|
|
|
|
2023-12-08 12:11:44 -07:00
|
|
|
h = Play{hand: []rune("JJJJJ"), game:&game}
|
|
|
|
h.generateCounts()
|
|
|
|
|
2023-12-07 19:21:10 -07:00
|
|
|
is.Equal(h.HandType(), "5K-J")
|
|
|
|
is.Equal(fmt.Sprintf("%x", h.HandStrength()), "7aaaaa")
|
|
|
|
|
2023-12-08 12:11:44 -07:00
|
|
|
h = Play{hand: []rune("KKKKJ"), game: &game}
|
2023-12-07 19:21:10 -07:00
|
|
|
is.Equal(h.HandType(), "4K-K")
|
|
|
|
is.Equal(fmt.Sprintf("%x", h.HandStrength()), "6cccca")
|
|
|
|
|
2023-12-08 12:11:44 -07:00
|
|
|
h = Play{hand: []rune("QQQJA"), game: &game}
|
2023-12-07 19:21:10 -07:00
|
|
|
is.Equal(h.HandType(), "3K-Q")
|
|
|
|
is.Equal(fmt.Sprintf("%x", h.HandStrength()), "4bbbad")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPower(t *testing.T) {
|
|
|
|
for i := 1; i <= 13; i++ {
|
|
|
|
for j := 100; j < 800; j += 100 {
|
|
|
|
t.Log(i, j, i+j)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestExample(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
scan := bufio.NewScanner(bytes.NewReader(example))
|
|
|
|
|
2023-12-13 08:32:37 -07:00
|
|
|
r, err := run(scan)
|
|
|
|
is.NoErr(err)
|
|
|
|
is.Equal(r.valuePT1, uint64(6440))
|
|
|
|
is.Equal(r.valuePT2, uint64(5905))
|
2023-12-07 19:21:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSolution(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
scan := bufio.NewScanner(bytes.NewReader(input))
|
|
|
|
|
2023-12-13 08:32:37 -07:00
|
|
|
r, err := run(scan)
|
|
|
|
is.NoErr(err)
|
|
|
|
t.Log("score1", r.valuePT1)
|
|
|
|
is.Equal(r.valuePT1, uint64(248559379))
|
2023-12-07 19:21:10 -07:00
|
|
|
|
2023-12-13 08:32:37 -07:00
|
|
|
t.Log("score2", r.valuePT2)
|
|
|
|
is.Equal(r.valuePT2, uint64(249631254))
|
2023-12-07 19:21:10 -07:00
|
|
|
}
|