public void GenerateTeams_GivenFourPlayers_PerfectSolutionsExist_PerfectSolutionFound( int p1, int g1, int p2, int g2, int p3, int g3, int p4, int g4) { IShuffler shuffler = A.Fake <IShuffler>(); TeamGenerator teamGenerator = new TeamGenerator(shuffler); Player player1 = new Player() { Id = 1, Name = "Name1", Points = p1, GamesPlayed = g1 }; Player player2 = new Player() { Id = 2, Name = "Name2", Points = p2, GamesPlayed = g2 }; Player player3 = new Player() { Id = 3, Name = "Name3", Points = p3, GamesPlayed = g3 }; Player player4 = new Player() { Id = 4, Name = "Name4", Points = p4, GamesPlayed = g4 }; List <Player> selectedPlayers = new List <Player> { player1, player2, player3, player4 }; var result = teamGenerator.GenerateTeams(selectedPlayers); result.Item1.Sum(p => p.PointsPerGame).Should().Be(1); result.Item2.Sum(p => p.PointsPerGame).Should().Be(1); }
public void GenerateTeams_GivenThreePlayers_PerfectSolutionsExist_PerfectSolutionFound( int p1, int g1, int p2, int g2, int p3, int g3) { IShuffler shuffler = A.Fake <IShuffler>(); TeamGenerator teamGenerator = new TeamGenerator(shuffler); Player player1 = new Player() { Id = 1, Name = "Name1", Points = p1, GamesPlayed = g1 }; Player player2 = new Player() { Id = 2, Name = "Name2", Points = p2, GamesPlayed = g2 }; Player player3 = new Player() { Id = 3, Name = "Name3", Points = p3, GamesPlayed = g3 }; List <Player> selectedPlayers = new List <Player> { player1, player2, player3 }; var result = teamGenerator.GenerateTeams(selectedPlayers); var r1 = (double)p1 / g1; var r2 = (double)p2 / g2; var r3 = (double)p3 / g3; double expected = (r1 + r2 + r3) / 2; result.Item1.Sum(p => p.PointsPerGame).Should().Be(expected); result.Item2.Sum(p => p.PointsPerGame).Should().Be(expected); }
public void GenerateTeams_GivenOddPlayers_EvenSplitReturned_Team1WithMorePlayers(int numberOfPlayers) { IShuffler shuffler = A.Fake <IShuffler>(); TeamGenerator teamGenerator = new TeamGenerator(shuffler); List <Player> selectedPlayers = new List <Player>(); for (int i = 1; i <= numberOfPlayers; i++) { selectedPlayers.Add(new Player() { Id = i, Name = "Name" + i, Points = 1, GamesPlayed = 1 }); } var result = teamGenerator.GenerateTeams(selectedPlayers); result.Item1.Count().Should().Be((numberOfPlayers + 1) / 2); result.Item2.Count().Should().Be((numberOfPlayers - 1) / 2); }
protected void ASPxButton1_Click(object sender, EventArgs e) { int numPlayers = 20; int nbrOfTeams = 20 / 2; int rounds = 3; List <Player> players = new List <Player>(); for (int i = 1; i <= numPlayers; i++) { Player player = new Player { Name = "Person " + i.ToString() }; players.Add(player); } Tournament tournament = new Tournament(rounds); ExtensionMethods.Shuffle(players); for (int i = 0; i < rounds; i++) { TournamentRound round = new TournamentRound("Round : " + (i + 1).ToString()); List <Team> teams = TeamGenerator.GenerateTeams(players, nbrOfTeams); round.Teams = teams; round.Matches = MatchGenerator.GenerateMatches(teams, teams.Count / 2); tournament.Rounds.Add(round); } ASPxListBox1.DataSource = tournament.Rounds[0].Matches; ASPxListBox1.TextField = "Name"; ASPxListBox1.DataBind(); ASPxListBox2.DataSource = tournament.Rounds[1].Matches; ASPxListBox2.TextField = "Name"; ASPxListBox2.DataBind(); ASPxListBox3.DataSource = tournament.Rounds[2].Matches; ASPxListBox3.TextField = "Name"; ASPxListBox3.DataBind(); }