mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 22:53:43 +00:00
44 lines
1.9 KiB
Go
44 lines
1.9 KiB
Go
package domain
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func sixConnectParticipants(connected ...int) []ConnectParticipant {
|
|
set := make(map[int]bool)
|
|
for _, index := range connected {
|
|
set[index] = true
|
|
}
|
|
result := make([]ConnectParticipant, 6)
|
|
for i := range result {
|
|
result[i] = ConnectParticipant{PlayerID: string(rune('a' + i)), Team: i % 2, Connected: set[i]}
|
|
}
|
|
return result
|
|
}
|
|
|
|
func TestRankedInitialNoShowCancelsWithoutRatingPenalty(t *testing.T) {
|
|
readyAt := time.Unix(1000, 0)
|
|
decision, err := EvaluateInitialConnect(Ranked, readyAt, readyAt.Add(InitialConnectWindow), sixConnectParticipants(0, 1, 2, 3, 4), map[string][]time.Time{"f": {readyAt.Add(-time.Hour)}})
|
|
if err != nil || decision.Action != InitialConnectCancel || len(decision.NoShows) != 1 || decision.NoShows[0].PlayerID != "f" || decision.NoShows[0].Cooldown != 15*time.Minute || len(decision.Innocent) != 5 {
|
|
t.Fatalf("ranked no-show decision = %+v err=%v", decision, err)
|
|
}
|
|
}
|
|
|
|
func TestCasualWaitsThenStartsWithBotsOnlyWithHumanOnEachTeam(t *testing.T) {
|
|
readyAt := time.Unix(1000, 0)
|
|
participants := sixConnectParticipants(0, 1)
|
|
if decision, err := EvaluateInitialConnect(Casual, readyAt, readyAt.Add(45*time.Second), participants, nil); err != nil || decision.Action != InitialConnectWait {
|
|
t.Fatalf("casual early decision = %+v err=%v", decision, err)
|
|
}
|
|
decision, err := EvaluateInitialConnect(Casual, readyAt, readyAt.Add(CasualBotStartAfter), participants, nil)
|
|
if err != nil || decision.Action != InitialConnectStartWithBot || len(decision.NoShows) != 4 || decision.NoShows[0].Cooldown != CasualNoShowCooldown {
|
|
t.Fatalf("casual bot decision = %+v err=%v", decision, err)
|
|
}
|
|
noTeam := sixConnectParticipants(0)
|
|
decision, err = EvaluateInitialConnect(Casual, readyAt, readyAt.Add(CasualBotStartAfter), noTeam, nil)
|
|
if err != nil || decision.Action != InitialConnectCancel || len(decision.Innocent) != 1 {
|
|
t.Fatalf("empty-team decision = %+v err=%v", decision, err)
|
|
}
|
|
}
|