public void Calculate_Set_Points_TieBreak(int s1HomeBall, int s1GuestBall, int s2HomeBall, int s2GuestBall, int s3HomeBall, int s3GuestBall, int expectedHomeSetPts, int expectedGuestSetPts, bool expectedTieBreak) { var sets = new List <SetEntity> { new SetEntity { HomeBallPoints = s1HomeBall, GuestBallPoints = s1GuestBall }, new SetEntity { HomeBallPoints = s2HomeBall, GuestBallPoints = s2GuestBall }, new SetEntity { HomeBallPoints = s3HomeBall, GuestBallPoints = s3GuestBall } }; var setRule = new SetRuleEntity { PointsSetWon = 3, PointsSetLost = 1, PointsSetTie = 0 }; var matchRule = new MatchRuleEntity { BestOf = true, NumOfSets = 2 }; sets.CalculateSetPoints(setRule, matchRule); Assert.Multiple(() => { Assert.AreEqual(expectedHomeSetPts, sets.GetSetPoints().Home); Assert.AreEqual(expectedGuestSetPts, sets.GetSetPoints().Guest); Assert.AreEqual(expectedTieBreak, sets.Last().IsTieBreak); }); }
public void Calculate_Set_Points(int homeBallPts, int guestBallPts, int expectedHomeSetPts, int expectedGuestSetPts) { var set = new SetEntity { HomeBallPoints = homeBallPts, GuestBallPoints = guestBallPts }; var setRule = new SetRuleEntity { PointsSetWon = 3, PointsSetLost = 1, PointsSetTie = 2 }; set.CalculateSetPoints(setRule); Assert.Multiple(() => { Assert.AreEqual(expectedHomeSetPts, set.HomeSetPoints); Assert.AreEqual(expectedGuestSetPts, set.GuestSetPoints); }); }
public async Task BestOf_No_Match_After_BestOf_Reached() { var sets = new List <SetEntity> { new SetEntity { Id = 10, SequenceNo = 1, HomeBallPoints = 25, GuestBallPoints = 23, IsTieBreak = false }, new SetEntity { Id = 11, SequenceNo = 2, HomeBallPoints = 23, GuestBallPoints = 25, IsTieBreak = false }, new SetEntity { Id = 12, SequenceNo = 3, HomeBallPoints = 15, GuestBallPoints = 10, IsTieBreak = true }, new SetEntity { Id = 13, SequenceNo = 4, HomeBallPoints = 23, GuestBallPoints = 25, IsTieBreak = false }, new SetEntity { Id = 15, SequenceNo = 5, HomeBallPoints = 15, GuestBallPoints = 10, IsTieBreak = true }, }; var setRule = new SetRuleEntity { PointsSetWon = 1, PointsSetLost = 0, PointsSetTie = 0 }; var matchRule = new MatchRuleEntity { BestOf = true, NumOfSets = 2 }; var sv = new SetsValidator(sets, (new TenantContext(), (matchRule, new SetRuleEntity()))); await sv.CheckAsync(SetsValidator.FactId.BestOfNoMatchAfterBestOfReached, CancellationToken.None); var factResult = sv.GetFailedFacts().First(f => f.Id == SetsValidator.FactId.BestOfNoMatchAfterBestOfReached); Assert.Multiple(() => { Assert.IsFalse(factResult.Success); Assert.IsNull(factResult.Exception); }); // Remove sets which exceed "Best-of-2 out of 3" sets.RemoveAt(3); sets.RemoveAt(3); await sv.CheckAsync(SetsValidator.FactId.BestOfNoMatchAfterBestOfReached, CancellationToken.None); Assert.AreEqual(0, sv.GetFailedFacts().Count); }
public async Task Invalid_Sets() { var sets = new List <SetEntity> { new SetEntity { Id = 10, SequenceNo = 1, HomeBallPoints = 25, GuestBallPoints = 23, IsTieBreak = false }, new SetEntity { Id = 11, SequenceNo = 2, HomeBallPoints = 23, GuestBallPoints = 25, IsTieBreak = false }, new SetEntity { Id = 12, SequenceNo = 3, HomeBallPoints = 16, GuestBallPoints = 15, IsTieBreak = true } // false }; var setRule = new SetRuleEntity { NumOfPointsToWinRegular = 25, PointsDiffToWinRegular = 2, NumOfPointsToWinTiebreak = 15, PointsDiffToWinTiebreak = 2 }; var matchRule = new MatchRuleEntity() { BestOf = true, NumOfSets = 2 }; var sv = new SetsValidator(sets, (new TenantContext(), (matchRule, setRule))); await sv.CheckAsync(CancellationToken.None); var errorFacts = sv.GetFailedFacts(); Assert.Multiple(() => { Assert.AreEqual(1, errorFacts.Count); Assert.AreEqual(1, sv.SingleSetErrors.Count); Assert.AreEqual(3, sv.SingleSetErrors.First().SequenceNo); Assert.AreEqual(SingleSetValidator.FactId.TieBreakWinReachedWithTwoPlusPointsAhead, sv.SingleSetErrors.First().FactId); }); }
/// <summary> /// Assigns "set points" to each of the <see cref="SetEntity"/>s in the list. /// For "Best-of" matches, <see cref="SetEntity.IsTieBreak"/> is flagged, too. /// </summary> /// <param name="setList">An <see cref="IList{SetEntity}"/>.</param> /// <param name="setRule">The <see cref="SetRuleEntity"/> with the set rules to apply.</param> /// <param name="matchRule">The <see cref="MatchRuleEntity"/> with the set rules to apply.</param> /// <returns>Returns the <see cref="IList{SetEntity}"/> after "set points" were set.</returns> public static IList <SetEntity> CalculateSetPoints(this IList <SetEntity> setList, SetRuleEntity setRule, MatchRuleEntity matchRule) { var wonSets = new PointResult(0, 0); foreach (var set in setList) { set.CalculateSetPoints(setRule); set.IsTieBreak = false || matchRule.BestOf && wonSets.Home == wonSets.Guest && wonSets.Home + wonSets.Guest == matchRule.MaxNumOfSets() - 1; wonSets.Home += set.HomeBallPoints > set.GuestBallPoints ? 1 : 0; wonSets.Guest += set.HomeBallPoints < set.GuestBallPoints ? 0 : 1; } return(setList); }