public void GenerateSchedule_WhenTeamsOrLeagueNull_ThrowsInvalidOperationException() { //ARRANGE RoundRobinScheduler rrs = new RoundRobinScheduler(); //ACT rrs.GenerateSchedule(); //ASSERT handled by ExpectedException }
public void GenerateSchedule_ScheduleMustCoverAllPairs() { //ARRANGE int teamsNumber = 16; //prepare checklist //false - not played //already played matches will be marked as true bool[][] checkList = new bool[teamsNumber][]; for (int i = 0; i < teamsNumber; i++) { checkList[i] = new bool[teamsNumber]; } //create teams List <ITeam> teams = this.CreateBlankTeams(teamsNumber); //invoke scheduler RoundRobinScheduler rrs = this.InvokeScheduler(teams); //ACT rrs.GenerateSchedule(); List <IMatch> matches = rrs.GetSchedule(); //ASSERT //loop through each match and mark him as played (true) matches.ForEach(x => checkList[(int)x.HomeTeam.Id - 1][(int)x.AwayTeam.Id - 1] = true); //check if all of the matches has been played //however any team can not play itself for (int i = 0; i < teamsNumber; i++) { for (int j = 0; j < teamsNumber; j++) { bool diagonal = (i == j); bool matchPlayed = checkList[i][j]; //team cannot play itself if (diagonal && matchPlayed) { Assert.Fail(); } //all of the matches must be played, if not, then fail if (!diagonal && !matchPlayed) { Assert.Fail(); } } } //if not failed, then ok }
public bool GenerateSchedule() { Leagues newLeagueEntity = new Leagues { Name = this.NewLeagueName }; DateTime yearOfStart = new DateTime(this.NewLeagueYearOfStart, 1, 1); LeagueEntityToLibraryAdapter newLeagueAdapter = new LeagueEntityToLibraryAdapter(); newLeagueAdapter.Adapt(newLeagueEntity); RoundRobinScheduler scheduler = new RoundRobinScheduler(); scheduler.LoadLeague(newLeagueAdapter); List <ITeam> listOfTeamsAdapter = new List <ITeam>(); foreach (Teams team in this.TeamsForNewLeague) { TeamEntityToLibraryAdapter teamAdapter = new TeamEntityToLibraryAdapter(); teamAdapter.Adapt(team); listOfTeamsAdapter.Add(teamAdapter); } scheduler.LoadTeams(listOfTeamsAdapter); scheduler.YearOfStart = yearOfStart; scheduler.GenerateSchedule(); List <IMatch> listOfMatchesFromAlgorithm = scheduler.GetSchedule(); List <Matches> listOfMatchesEntities = new List <Matches>(); foreach (IMatch match in listOfMatchesFromAlgorithm) { Matches m = new Matches() { TimeOfPlay = match.TimeOfPlay, HomeTeamId = match.HomeTeam.Id, AwayTeamId = match.AwayTeam.Id, }; Context.Matches.Add(m); } Context.Leagues.Add(newLeagueEntity); Context.SaveChanges(); return(true); }