draftbot/bot/bot_test.go
2019-08-26 11:20:00 +02:00

66 lines
1.5 KiB
Go

package bot_test
import (
"testing"
"git.fromouter.space/mcg/mlp-server-tools/draftbot/bot"
"git.fromouter.space/mcg/draft"
)
const PACKSIZE = 5
// Test set that can be used by tests that don't need special features (like alternates)
var testSet = &draft.GenericSet{
Cards: []draft.Card{{ID: "a"}, {ID: "b"}, {ID: "c"}},
PackSize: PACKSIZE,
}
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)
// Create a bot for each player in the pod
var bots []*bot.Bot
for _, player := range pod.Players {
bots = append(bots, bot.MakeBot(player))
}
// Simulate a round of drafting
// 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 _, bot := range bots {
bot.PickNext()
}
// 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")
}
}
}
}