package game import "testing" // TestRandomBattlesTerminate throws thousands of random decks (drawn from // every tier's real cards, plus apples, bees, and perks) at the battle // resolver, checking it always terminates with a sane event log and a // consistent winner. This is the safety net for effect interactions no // hand-written scenario covers. func TestRandomBattlesTerminate(t *testing.T) { names := []string{} for _, tier := range petTiers { for _, tmpl := range tier { names = append(names, tmpl.Name) } } foods := []string{"Honey", "Garlic", "Pineapple", "Chili", "Melon"} for i := range 3000 { g, _, _ := testGame(t) buildDeck := func() []Card { deck := make([]Card, 0, 10) for range 1 + randInt(6) { switch randInt(5) { case 0: deck = append(deck, g.newApple()) case 1: deck = append(deck, g.realFood(t, foods[randInt(len(foods))])) case 2: deck = append(deck, g.newBee()) default: deck = append(deck, g.realPet(t, names[randInt(len(names))])) } } return deck } g.Round = 1 + randInt(MaxRounds) res := forceBattle(t, g, buildDeck(), buildDeck()) if len(res.Events) > 2000 { t.Fatalf("battle %d produced a runaway event log (%d events)", i, len(res.Events)) } if res.WinnerSeat < -1 || res.WinnerSeat > 1 { t.Fatalf("battle %d: bogus winner %d", i, res.WinnerSeat) } if res.WinnerSeat >= 0 && res.Trophies < 1 { t.Fatalf("battle %d: winner without trophies", i) } } }