package logic import ( "testing" ) func TestCalculateStandings(t *testing.T) { teams := []string{"MEX", "RSA", "KOR", "CZE"} matches := []Match{ {TeamA: "MEX", TeamB: "RSA", IsCompleted: true, ScoreA: 2, ScoreB: 0}, // MEX: 3 pts, RSA: 0 pts {TeamA: "KOR", TeamB: "CZE", IsCompleted: true, ScoreA: 2, ScoreB: 1}, // KOR: 3 pts, CZE: 0 pts } standings := CalculateStandings(teams, matches) if len(standings) != 4 { t.Fatalf("expected 4 teams, got %d", len(standings)) } // MEX and KOR should be top 2 if standings[0].TeamName != "MEX" && standings[0].TeamName != "KOR" { t.Errorf("expected MEX or KOR as first, got %s", standings[0].TeamName) } } func TestRunMonteCarlo(t *testing.T) { teams := []Team{ {Name: "MEX", Group: "A"}, {Name: "RSA", Group: "A"}, {Name: "KOR", Group: "A"}, {Name: "CZE", Group: "A"}, } matches := []Match{ {TeamA: "MEX", TeamB: "RSA", IsCompleted: true, ScoreA: 2, ScoreB: 0}, {TeamA: "KOR", TeamB: "CZE", IsCompleted: true, ScoreA: 2, ScoreB: 1}, {TeamA: "CZE", TeamB: "RSA", IsCompleted: false}, {TeamA: "MEX", TeamB: "KOR", IsCompleted: false}, {TeamA: "MEX", TeamB: "CZE", IsCompleted: false}, {TeamA: "KOR", TeamB: "RSA", IsCompleted: false}, } // We only simulate Group A here (4 teams, 6 matches total). // Note: 3rd place comparison won't succeed in putting any team to top 8 of third placed // unless there are other groups, but it shouldn't crash. probs := RunMonteCarlo(teams, matches, nil, 100) if len(probs) != 4 { t.Fatalf("expected probabilities for 4 teams, got %d", len(probs)) } for _, p := range probs { if p.TotalQualProb < 0 || p.TotalQualProb > 1.0 { t.Errorf("invalid total qual probability for %s: %f", p.TeamName, p.TotalQualProb) } } }