public void Division_WinPercentage() { IDivision nfcSouth = this.NFL.GetDivision("NFC", "South"); ITeam saints = this.NFL.GetTeam("NO"); IDivision nfcWest = this.NFL.GetDivision("NFC", "West"); ITeam seahawks = this.NFL.GetTeam("SEA"); switch (this.StatsDataFile.StripPath()) { case "NFLStats_2016.xml": Assert.AreEqual((2.0 / 6.0), nfcSouth.WinPercentage(saints)); Assert.AreEqual(((3.0 + (1.0 * 0.5)) / 6.0), nfcWest.WinPercentage(seahawks)); break; case "NFLStats_2017.xml": Assert.AreEqual((4.0 / 6.0), nfcSouth.WinPercentage(saints)); break; default: break; } }
public int Compare(ITeam x, ITeam y) { IDivision divx = GetDivision(x); IDivision divy = GetDivision(y); if (divx != divy) { throw new Exception("Cannot compare teams from different divisions"); } IConference conf = league.Conferences.Where(c => c.Divisions.Contains(divx)).FirstOrDefault(); int result = 0; // base win percentage result = x.WinPercentage.CompareTo(y.WinPercentage); TiebreakDescription[x.ID] = "Win Percentage"; if (result != 0) { return(result); } // head to head result = x.HeadToHead(y.ID); TiebreakDescription[x.ID] = "Head to Head"; if (result != 0) { return(result); } // win percentage in games played within the division result = divx.WinPercentage(x).CompareTo(divx.WinPercentage(y)); TiebreakDescription[x.ID] = "Division Win Percentage"; if (divx.WinPercentage(x) == -1 || divx.WinPercentage(y) == -1) { result = 0; } if (result != 0) { return(result); } // win percentage in common games result = league.CommonGameWinPercentage(x, y, 0).CompareTo(league.CommonGameWinPercentage(y, x, 0)); TiebreakDescription[x.ID] = "Common Game Win Percentage"; if (result != 0) { return(result); } // win percentage in games played within the conference result = conf.WinPercentage(x).CompareTo(conf.WinPercentage(y)); TiebreakDescription[x.ID] = "Conference Win Percentage"; if (conf.WinPercentage(x) == -1 || conf.WinPercentage(y) == -1) { result = 0; } if (result != 0) { return(result); } // strength of victory result = league.StrengthOfVictory(x).CompareTo(league.StrengthOfVictory(y)); TiebreakDescription[x.ID] = "Strength of Victory"; if (result != 0) { return(result); } // strength of schedule result = league.StrengthOfSchedule(x).CompareTo(league.StrengthOfSchedule(y)); TiebreakDescription[x.ID] = "Strength of Schedule"; if (result != 0) { return(result); } // best combined ranking in the conference of points scored and points allowed int xnetrank = conf.OffensiveRankings[x.ID] + conf.DefensiveRankings[x.ID]; int ynetrank = conf.OffensiveRankings[y.ID] + conf.DefensiveRankings[y.ID]; result = ynetrank.CompareTo(xnetrank); // lower is better TiebreakDescription[x.ID] = "Combined Conference Ranking"; if (result != 0) { return(result); } // best combined ranking across the nfl in points scored and points allowed xnetrank = league.OffensiveRankings[x.ID] + league.DefensiveRankings[x.ID]; ynetrank = league.OffensiveRankings[y.ID] + league.DefensiveRankings[y.ID]; result = ynetrank.CompareTo(xnetrank); // lower is better TiebreakDescription[x.ID] = "Combined League Ranking"; if (result != 0) { return(result); } // best net points in common games result = league.NetPointsInCommonGames(x, y).CompareTo(league.NetPointsInCommonGames(y, x)); TiebreakDescription[x.ID] = "Net Points in Common Games"; if (result != 0) { return(result); } // best net points in all games int xnetpoints = x.PointsScored - x.PointsAllowed; int ynetpoints = y.PointsScored - y.PointsAllowed; result = xnetpoints.CompareTo(ynetpoints); TiebreakDescription[x.ID] = "Net Points in All Games"; if (result != 0) { return(result); } // best net touchdowns in all games int xnettds = x.TouchdownsScored - x.TouchdownsAllowed; int ynettds = y.TouchdownsScored - y.TouchdownsAllowed; TiebreakDescription[x.ID] = "Net Touchdowns"; result = xnettds.CompareTo(ynettds); if (result == 0) { TiebreakDescription[x.ID] = "Coin Flip!"; } return(result); }