mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package domain
|
|
|
|
import "testing"
|
|
|
|
func TestPartitionTeamsBalancesMeanRatingBeforeOpposingSpread(t *testing.T) {
|
|
players := []Candidate{
|
|
{PlayerID: "a", Rating: 1000}, {PlayerID: "b", Rating: 1100},
|
|
{PlayerID: "c", Rating: 1900}, {PlayerID: "d", Rating: 2000},
|
|
}
|
|
teams, err := PartitionTeams(players)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if playerIDs(teams.Team0) != "a\x00d\x00" || playerIDs(teams.Team1) != "b\x00c\x00" {
|
|
t.Fatalf("unexpected balanced partition: team0=%q team1=%q", playerIDs(teams.Team0), playerIDs(teams.Team1))
|
|
}
|
|
}
|
|
|
|
func TestPartitionTeamsIsIndependentOfInputOrder(t *testing.T) {
|
|
players := []Candidate{
|
|
{PlayerID: "d", Rating: 1500}, {PlayerID: "b", Rating: 1500},
|
|
{PlayerID: "c", Rating: 1500}, {PlayerID: "a", Rating: 1500},
|
|
}
|
|
first, err := PartitionTeams(players)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
second, err := PartitionTeams([]Candidate{players[2], players[0], players[3], players[1]})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if playerIDs(first.Team0) != playerIDs(second.Team0) || playerIDs(first.Team1) != playerIDs(second.Team1) {
|
|
t.Fatalf("input order changed partition: first=%q/%q second=%q/%q", playerIDs(first.Team0), playerIDs(first.Team1), playerIDs(second.Team0), playerIDs(second.Team1))
|
|
}
|
|
}
|
|
|
|
func TestPartitionTeamsRejectsUnsupportedShapes(t *testing.T) {
|
|
for _, count := range []int{0, 1, 3, 7} {
|
|
players := make([]Candidate, count)
|
|
if _, err := PartitionTeams(players); err == nil {
|
|
t.Fatalf("accepted %d players", count)
|
|
}
|
|
}
|
|
}
|