go_games_collection/thousand_bot_test.go
2026-07-04 13:51:04 +03:00

59 lines
1.9 KiB
Go

package main
import "testing"
// TestThousandBotFullMatches прогоняет много полных матчей (до
// 1000 очков) силами ThousandBot, проверяя отсутствие паник,
// зависаний и потери/дублирования карт.
func TestThousandBotFullMatches(t *testing.T) {
bot := ThousandBot{}
for match := 0; match < 20; match++ {
names := newThousandBotNames(3)
g := NewThousandGame(names, -1)
const maxHands = 500
hand := 0
for ; hand < maxHands; hand++ {
const maxSteps = 2000
steps := 0
for ; steps < maxSteps && g.Phase != ThousandPhaseHandOver; steps++ {
if err := bot.PlayFullTurn(g); err != nil {
t.Fatalf("матч %d, раздача %d, шаг %d: ошибка бота (фаза %v): %v",
match, hand, steps, g.Phase, err)
}
}
if steps >= maxSteps {
t.Fatalf("матч %d, раздача %d: раздача не завершилась за %d шагов (фаза %v)",
match, hand, maxSteps, g.Phase)
}
if g.Result == nil {
t.Fatalf("матч %d, раздача %d: раздача завершилась без результата", match, hand)
}
seen := map[Card]bool{}
total := 0
for _, p := range g.Players {
for _, c := range p.Hand {
if seen[c] {
t.Fatalf("матч %d, раздача %d: карта %v встретилась дважды", match, hand, c)
}
seen[c] = true
total++
}
}
if total != 0 {
t.Fatalf("матч %d, раздача %d: после завершения раздачи на руках не должно остаться карт, получено %d",
match, hand, total)
}
if g.Result.MatchOver {
break
}
g.NextHand()
}
if hand >= maxHands {
t.Fatalf("матч %d: не завершился за %d раздач (возможное зависание)", match, maxHands)
}
}
}