Exemple #1
0
        public static IEnumerable <object[]> PlayoffDataForGetTeamByRuleTests()
        {
            var config  = new PlayoffCompetitionConfig("My Playoff", null, 1, 12, null, 1, null, null, null, null, null);
            var playoff = new Playoff(null, null, 1, 1, new List <PlayoffSeries>(), new List <CompetitionTeam>(), null, new List <TeamRanking>(), true, false, 1, null);

            playoff.CompetitionConfig = config;

            for (int i = 0; i < 10; i++)
            {
                var name = "Team " + i;
                playoff.Teams.Add(CreateTeam(name, i, i));
                playoff.Rankings.Add(new TeamRanking(i + 1, "R1", playoff.Teams.Where(t => t.Name.Equals(name)).First(), 1));
            }

            var gameRules = new GameRules("Rule 1", false, 0, 3, 10, true);

            var seriesA = new BestOfSeries(playoff, "Series A", 2, 15, (PlayoffTeam)playoff.Teams.Where(t => t.Name.Equals("Team 1")).First(), (PlayoffTeam)playoff.Teams.Where(t => t.Name.Equals("Team 2")).First(), 4, 3, 4, null, null);

            playoff.Series.Add(seriesA);

            //need to add series to get teams from
            yield return(new object[] { 1, playoff, new PlayoffSeriesRule(config, "Series 1", 1, PlayoffSeriesRule.Type.BestOf, 4, gameRules, "R1", 1, "R1", 10, 1, null, new int[] { 0, 0, 0, 1, 1, 1 }, null, null, null, null), "Team 0", "Team 9" });

            yield return(new object[] { 1, playoff, new PlayoffSeriesRule(config, "Series 1", 1, PlayoffSeriesRule.Type.BestOf, 4, gameRules, "R1", 4, "R1", 2, 1, null, new int[] { 0, 0, 0, 1, 1, 1 }, null, null, null, null), "Team 3", "Team 1" });
            //todo add get from ranking rule
        }
        public void ShouldMapBestOfSeriesSummary()
        {
            var mapper = new BestOfSeriesToBestofSeriesSummaryMapper();
            var series = new BestOfSeries(new Playoff()
            {
                Name = "P Name", Year = 5
            },
                                          "Series 1", 1, 5, new PlayoffTeam()
            {
                Name = "Team 1"
            }, new PlayoffTeam()
            {
                Name = "Team 2"
            },
                                          3, 2, 4, new List <PlayoffGame>()
            {
                new PlayoffGame(), new PlayoffGame(), new PlayoffGame(), new PlayoffGame()
            }, new int[] { });

            series.Id = 15;

            var mappedSeries = mapper.MapDomainToModel(series);

            StrictEqual(15, mappedSeries.Id);
            Equals("P Name", mappedSeries.PlayoffName);
            Equals("Series 1", mappedSeries.Name);
            StrictEqual(5, mappedSeries.Year);
            Equals("Team 1", mappedSeries.HomeTeamName);
            Equals("Team 2", mappedSeries.AwayTeamName);
            StrictEqual(3, mappedSeries.HomeWins);
            StrictEqual(2, mappedSeries.AwayWins);
            StrictEqual(4, mappedSeries.Games);
            StrictEqual(1, mappedSeries.Round);
        }
Exemple #3
0
        public void ShouldProcessSeriesGameBestOf()
        {
            var homeTeam = CreateTeam("A Team", 1, 1);
            var awayTeam = CreateTeam("B Team", 2, 2);

            var series = new BestOfSeries(null, "Test", 1, 1, homeTeam, awayTeam, 0, 0, 2, null, null);

            var game1 = CreateGame(5, 4, true, homeTeam, awayTeam);
            var game2 = CreateGame(8, 3, true, awayTeam, homeTeam);
            var game3 = CreateGame(2, 3, true, awayTeam, homeTeam);

            False(series.IsComplete());
            series.ProcessGame(game1);

            StrictEqual(1, series.HomeWins);
            StrictEqual(0, series.AwayWins);

            False(series.IsComplete());
            series.ProcessGame(game2);

            StrictEqual(1, series.HomeWins);
            StrictEqual(1, series.AwayWins);

            False(series.IsComplete());
            series.ProcessGame(game3);

            StrictEqual(2, series.HomeWins);
            StrictEqual(1, series.AwayWins);

            True(series.IsComplete());
        }
Exemple #4
0
        public void ShouldCreateGameProperly(int testNo, int gameToTest, int[] homeTeamProgression, int expectedResult)
        {
            var number = testNo;

            var gameRules     = new GameRules("Test", false, 1, 3, 10, true);
            var playoffConfig = new PlayoffCompetitionConfig("My Playoff", null, 1, 55, gameRules, 1, null, null, null, null, null); //todo eventually can't use this constructor
            var playoff       = new Playoff(playoffConfig, "My Playoff", 1, 1, null, null, null, null, true, false, 1, null);

            playoff.CompetitionConfig = playoffConfig;
            playoffConfig.GameRules   = gameRules;

            var homeTeam = CreateTeam("A Team", 1, 1);
            var awayTeam = CreateTeam("B Team", 1, 1);

            var series = new BestOfSeries(playoff, "Test", 1, 1, homeTeam, awayTeam, 0, 0, 0, null, homeTeamProgression);

            var game = series.CreateGameForSeries(gameToTest);

            if (expectedResult == 0)
            {
                Equal("A Team", game.Home.Name);
                Equal("B Team", game.Away.Name);
            }
            else
            {
                Equal("B Team", game.Home.Name);
                Equal("A Team", game.Away.Name);
            }
        }
Exemple #5
0
        public void ShouldGetProperTeamForGameNumber(int testNo, int gameToTest, int[] homeTeamProgression, int expectedResult)
        {
            var number = testNo;

            var series = new BestOfSeries(null, null, 1, 1, null, null, 0, 0, 0, null, homeTeamProgression);

            StrictEqual(expectedResult, series.GetHomeValueForGame(gameToTest));
        }
Exemple #6
0
        public void ShouldGetWinnerAndLoserForBestOf()
        {
            var homeTeam = CreateTeam("A Team", 1, 1);
            var awayTeam = CreateTeam("B Team", 2, 2);

            var series1 = new BestOfSeries(null, "Test", 1, 2, homeTeam, awayTeam, 2, 1, 2, null, null);
            var series2 = new BestOfSeries(null, "Test", 1, 1, homeTeam, awayTeam, 0, 2, 2, null, null);
            var series3 = new BestOfSeries(null, "Test", 1, 1, homeTeam, awayTeam, 0, 0, 2, null, null);

            Equal("A Team", series1.GetWinner().Name);
            Equal("B Team", series1.GetLoser().Name);

            Equal("B Team", series2.GetWinner().Name);
            Equal("A Team", series2.GetLoser().Name);

            Null(series3.GetWinner());
            Null(series3.GetLoser());
        }
Exemple #7
0
        public void ProcessGamesForBestofSeries()
        {
            var teamA = CreateTeam("Team A", 1, 1);
            var teamB = CreateTeam("Team B", 2, 2);

            var series = new BestOfSeries(null, "Test", 1, 1, teamA, teamB, 0, 0, 4, new List <PlayoffGame>(), new int[] { 0, 0, 1, 1, 0, 1, 0 });

            var game1 = CreateGame(1, 0, true, teamA, teamB);
            var game2 = CreateGame(0, 0, false, teamA, teamB);
            var game3 = CreateGame(0, 0, false, teamA, teamB);
            var game4 = CreateGame(0, 0, false, teamA, teamB);
            var game5 = CreateGame(0, 0, false, teamA, teamB);
            var game6 = CreateGame(0, 0, false, teamA, teamB);
            var game7 = CreateGame(0, 0, false, teamA, teamB);

            series.ProcessGame(game1);

            StrictEqual(1, series.HomeWins);
            StrictEqual(0, series.AwayWins);

            series.Games.Add(game1);
            series.Games.Add(game2);

            StrictEqual(2, series.NumberOfGamesNeeded());
            series.Games.Add(game3);

            StrictEqual(1, series.NumberOfGamesNeeded());
            series.Games.Add(game4);

            StrictEqual(0, series.NumberOfGamesNeeded());
            game2.AwayScore = 3;
            game2.Complete  = true;
            series.ProcessGame(game2);
            //should be home 1 away 1
            StrictEqual(1, series.NumberOfGamesNeeded());
            game3.HomeScore = 5;
            game3.Complete  = true;
            game4.AwayScore = 3;
            game4.Complete  = true;
            series.ProcessGame(game3);
            series.ProcessGame(game4);

            StrictEqual(2, series.NumberOfGamesNeeded());
        }