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", 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", 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) // Simulate a round of drafting // Each player will always pick their first card // Repeat until all packs are gone // Channels are tested when they should trigger for packnum := 0; packnum < PacksPerPlayer; packnum++ { // Open new packs! err := pod.OpenPacks() if err != nil { t.Fatalf("Got an error while opening packs #%d: %s", packnum, err.Error()) } for picknum := 0; picknum < PACKSIZE; picknum++ { 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", err.Error()) } } // Make sure either ReadyNextPick or ReadyNextPack triggers select { case <-pod.ReadyNextPick: // Pass packs around err := pod.NextPacks() if err != nil { t.Fatalf("Got an error while passing packs: %s", err.Error()) } case <-pod.ReadyNextPack: break default: t.Fatal("Either ReadyNextPick/ReadyNextPack should trigger but neither has") } } } } 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") } else if err != draft.ErrNotInPack { t.Fatalf("Got error for wrong pick but not the right one: %s", err.Error()) } // Try getting packs from nearby players when no one is passing them err = pod.NextPacks() if err == nil { t.Fatal("Tried getting inexistant packs from nearby players but it succeeded") } else if err != draft.ErrNoPendingPack { t.Fatalf("Got error for non existant pack but not the right one: %s", 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") } else if err != draft.ErrNoPacksLeft { t.Fatalf("Got error for too many packs but not the right one: %s", err.Error()) } }