public void Swap_ChangesPlacesOfTwoPlayersInRound()
        {
            var p1 = new Player { Name = "P1" };
            var p2 = new Player { Name = "P2" };
            var p3 = new Player { Name = "P3" };
            var p4 = new Player { Name = "P4" };
            var tournament = new Tournament(new PairingGenerator(), 1) { Players = new[] { p1, p2, p3, p4 } };
            var pairings = tournament.SwissPairings().ToList();
            var round = tournament.Rounds.ElementAt(0);
            round.Pairings = pairings;

            round.Swap(pairings.ElementAt(0).Player1, pairings.ElementAt(1).Player2);
            Assert.Equal(p4, pairings[0].Player1);
            Assert.Equal(p2, pairings[0].Player2);
            Assert.Equal(p3, pairings[1].Player1);
            Assert.Equal(p1, pairings[1].Player2);

            round.Swap(p2, p1);
            Assert.Equal(p4, pairings[0].Player1);
            Assert.Equal(p1, pairings[0].Player2);
            Assert.Equal(p3, pairings[1].Player1);
            Assert.Equal(p2, pairings[1].Player2);
        }
        public void GetOpponent_ReturnsPlayersOpponentOrThrowsException()
        {
            var players = new[] { P1, P2, P3 };
            var tournament = new Tournament(new PairingGenerator(), 1) { Players = players };
            tournament.Rounds.ElementAt(0).Pairings = tournament.SwissPairings();

            Assert.Equal(players[0], tournament.Rounds.ElementAt(0).Pairings.ElementAt(0).GetOpponent(players[1]));
            Assert.Equal(Player.CreateEmpty(), tournament.Rounds.ElementAt(0).Pairings.ElementAt(1).GetOpponent(players[2]));
            Assert.Throws<ArgumentException>(() => tournament.Rounds.ElementAt(0).Pairings.ElementAt(0).GetOpponent(new Player { Name = "P4" }));
        }
        public void GetPlayerStandings_CalculatesScoresFromAllRounds()
        {
            var tournament = new Tournament(new PairingGenerator(), 3)
            {
                Players = new List<Player> { P1, P2, P3, P4 }
            };

            var pairings = tournament.SwissPairings().ToList();
            pairings[0].SetScore(12, 8);
            pairings[1].SetScore(1, 19);
            tournament.Rounds.ElementAt(0).Pairings = pairings;

            pairings = tournament.SwissPairings().ToList();
            pairings[0].SetScore(13, 7);
            pairings[1].SetScore(10, 10);
            tournament.Rounds.ElementAt(1).Pairings = pairings;

            var standings = tournament.GetPlayerStandings();
            VerifyPlayersStandingWithScore(standings.ElementAt(0), P4, 32);
            VerifyPlayersStandingWithScore(standings.ElementAt(1), P1, 19);
            VerifyPlayersStandingWithScore(standings.ElementAt(2), P2, 18);
            VerifyPlayersStandingWithScore(standings.ElementAt(3), P3, 11);
        }