package draft_test import ( "testing" "git.fromouter.space/mcg/draft" ) // Tests that a pod can be created and seeded correctly func TestCreatePod(t *testing.T) { const PacksPerPlayer = 3 const PlayersPerPod = 5 // Get provider for test set testProvider := draft.PacksFromSet(PacksPerPlayer, testSet) // Create pod pod := draft.MakePod(PlayersPerPod, testProvider) if len(pod.Players) != PlayersPerPod { t.Fatalf("Expected %d players in pod but got %d\n", PlayersPerPod, len(pod.Players)) } for i, player := range pod.Players { t.Logf("Player #%d:", i) for packi, pack := range player.Packs { t.Logf(" - Pack #%d: %s", packi, pack) } if len(player.Packs) != PacksPerPlayer { t.Fatalf("Player #%d has %d packs but should have %d\n", i, PacksPerPlayer, len(player.Packs)) } } } func TestPick(t *testing.T) { const PacksPerPlayer = 3 const PlayersPerPod = 5 // Get provider for test set testProvider := draft.PacksFromSet(PacksPerPlayer, testSet) // Create pod pod := draft.MakePod(PlayersPerPod, testProvider) pod.OpenPacks() for _, player := range pod.Players { // Pick first card for each player err := player.Pick(player.CurrentPack[0]) if err != nil { t.Fatalf("Tried picking first card in pack but couldn't: %s\n", err.Error()) } } } func TestPodErrors(t *testing.T) { const PacksPerPlayer = 3 const PlayersPerPod = 5 // Get provider for test set testProvider := draft.PacksFromSet(PacksPerPlayer, testSet) // Create pod pod := draft.MakePod(PlayersPerPod, testProvider) pod.OpenPacks() // Pick a card that doesn't exist err := pod.Players[0].Pick(draft.Card{ID: "nana"}) if err == nil { t.Fatal("Tried picking inexistant card but it succeeded\n") } else if err != draft.ErrNotInPack { t.Fatalf("Got error for wrong pick but not the right one: %s\n", err.Error()) } // Try opening more packs than each player has for i := 0; i < PacksPerPlayer; i++ { err = pod.OpenPacks() } if err == nil { t.Fatal("Tried opening too many packs but it succeeded\n") } else if err != draft.ErrNoPacksLeft { t.Fatalf("Got error for too many packs but not the right one: %s\n", err.Error()) } }