use distinct types for player and session ids

This commit is contained in:
2024-01-31 22:40:12 -06:00
parent d61c70da86
commit 73b5ac7960
8 changed files with 42 additions and 32 deletions

View File

@@ -3,14 +3,16 @@ package game
import (
"testing"
"github.com/google/uuid"
"git.sunturtle.xyz/studio/shotgun/player"
"git.sunturtle.xyz/studio/shotgun/serve"
)
func TestNewGame(t *testing.T) {
t.Parallel()
dealer := player.ID{1}
chall := player.ID{2}
dealer := player.ID{UUID: uuid.UUID{1}}
chall := player.ID{UUID: uuid.UUID{2}}
for i := 0; i < 10000; i++ {
g := New(dealer, chall)
checks := []struct {
@@ -41,7 +43,7 @@ func TestNewGame(t *testing.T) {
func TestGameStartRound(t *testing.T) {
t.Parallel()
g := New(player.ID{1}, player.ID{2})
g := New(player.ID{UUID: uuid.UUID{1}}, player.ID{UUID: uuid.UUID{2}})
for i := int8(1); i < 100; i++ {
checks := []struct {
failed bool
@@ -77,7 +79,7 @@ func TestGameStartRound(t *testing.T) {
func TestGameStartGroup(t *testing.T) {
t.Parallel()
g := New(player.ID{1}, player.ID{2})
g := New(player.ID{UUID: uuid.UUID{1}}, player.ID{UUID: uuid.UUID{2}})
for i := uint(1); i < 10000; i++ {
checks := []struct {
failed bool
@@ -114,7 +116,7 @@ func TestGameStartGroup(t *testing.T) {
func TestGameNextTurn(t *testing.T) {
t.Parallel()
g := New(player.ID{1}, player.ID{2})
g := New(player.ID{UUID: uuid.UUID{1}}, player.ID{UUID: uuid.UUID{2}})
for i := int8(1); i < 100; i++ {
checks := []struct {
failed bool
@@ -143,8 +145,8 @@ func TestGameNextTurn(t *testing.T) {
func TestGamePlayers(t *testing.T) {
t.Parallel()
dealer := player.ID{1}
chall := player.ID{2}
dealer := player.ID{UUID: uuid.UUID{1}}
chall := player.ID{UUID: uuid.UUID{2}}
g := New(dealer, chall)
if g.CurrentPlayer().id != chall {
t.Errorf("challenger isn't current player at start")
@@ -183,7 +185,7 @@ func TestGamePlayers(t *testing.T) {
func TestGamePopShell(t *testing.T) {
t.Parallel()
g := New(player.ID{1}, player.ID{2})
g := New(player.ID{UUID: uuid.UUID{1}}, player.ID{UUID: uuid.UUID{2}})
if live := g.popShell(); live != g.shellArray[0] {
t.Errorf("first pop %t, wanted %t", live, g.shellArray[0])
}
@@ -208,8 +210,8 @@ func TestGamePopShell(t *testing.T) {
}
func TestGamePeek(t *testing.T) {
dealer := player.ID{1}
chall := player.ID{2}
dealer := player.ID{UUID: uuid.UUID{1}}
chall := player.ID{UUID: uuid.UUID{2}}
t.Run("empty", func(t *testing.T) {
t.Parallel()
g := New(dealer, chall)
@@ -270,8 +272,8 @@ func TestGameEmpty(t *testing.T) {
func TestGameWinner(t *testing.T) {
t.Parallel()
dealer := player.ID{1}
chall := player.ID{2}
dealer := player.ID{UUID: uuid.UUID{1}}
chall := player.ID{UUID: uuid.UUID{2}}
cases := []struct {
name string
p0, p1 int8
@@ -311,8 +313,8 @@ func TestGameWinner(t *testing.T) {
}
func TestGameShoot(t *testing.T) {
dealer := player.ID{1}
chall := player.ID{2}
dealer := player.ID{UUID: uuid.UUID{1}}
chall := player.ID{UUID: uuid.UUID{2}}
cases := []struct {
name string
live bool
@@ -399,7 +401,7 @@ func TestGameShoot(t *testing.T) {
}
func TestConcede(t *testing.T) {
dealer, chall := player.ID{1}, player.ID{2}
dealer, chall := player.ID{UUID: uuid.UUID{1}}, player.ID{UUID: uuid.UUID{2}}
cases := []struct {
name string
p player.ID
@@ -417,7 +419,7 @@ func TestConcede(t *testing.T) {
},
{
name: "neither",
p: player.ID{3},
p: player.ID{UUID: uuid.UUID{3}},
winner: player.ID{},
},
}
@@ -436,7 +438,7 @@ func TestConcede(t *testing.T) {
func TestGameDTO(t *testing.T) {
t.Parallel()
dealer, chall := player.ID{1}, player.ID{2}
dealer, chall := player.ID{UUID: uuid.UUID{1}}, player.ID{UUID: uuid.UUID{2}}
g := New(dealer, chall)
{
want := serve.Game{