mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-14 07:02:03 +00:00
feat: form matches from queue projections
This commit is contained in:
@@ -66,3 +66,38 @@ func TestSelectCandidatesRejectsNoCommonRegion(t *testing.T) {
|
||||
t.Fatal("selected players without a common <=100ms region")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormFromQueueUsesServerProjectionAndBalancesTeams(t *testing.T) {
|
||||
now := time.Unix(100000, 0)
|
||||
queue := NewQueue()
|
||||
for _, id := range []string{"c", "a", "b", "d"} {
|
||||
candidate := candidate(id, 1500, time.Second, 40, 45, now)
|
||||
if _, err := queue.Create(candidate.PlayerID, candidate.TicketID, "create-key-"+id+"-123456", candidate, now.Add(-time.Duration(len(id))*time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
formation, err := FormFromQueue(queue, 4, now)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if formation.Selection.Players[0].TicketID != "a" || formation.Selection.Region != "EU" || len(formation.Teams.Team0) != 2 || len(formation.Teams.Team1) != 2 {
|
||||
t.Fatalf("formation = %+v", formation)
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
for _, player := range append(formation.Teams.Team0, formation.Teams.Team1...) {
|
||||
if seen[player.PlayerID] {
|
||||
t.Fatalf("duplicate player in teams: %s", player.PlayerID)
|
||||
}
|
||||
seen[player.PlayerID] = true
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectCandidatesRejectsMalformedCandidateInsteadOfTrustingIt(t *testing.T) {
|
||||
now := time.Unix(100000, 0)
|
||||
anchor := candidate("a", 1500, 0, 40, 40, now)
|
||||
malformed := candidate("b", 1500, 0, 40, 40, now)
|
||||
malformed.PlayerID = anchor.PlayerID
|
||||
if _, err := SelectCandidates(anchor, []Candidate{malformed}, 2, now); err == nil {
|
||||
t.Fatal("duplicate player candidate accepted")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user