public void TestBlueCompareAwardProcessUpdateWithExpiredInGreaterThan0() { //Arrange BlueCompareAward award = new BlueCompareAward(15, 10); //Act award.ProcessUpdate(); //Assert Assert.AreEqual(award.ExpiresIn, 14); Assert.AreEqual(award.Quality, 11); Assert.AreEqual(award.ToString(), "Award Name: Blue Compare, Expires In: 14, Quality: 11"); }
public void TestBlueCompareAwardProcessUpdateWithExpiredInlessThan0() { //Arrange BlueCompareAward award = new BlueCompareAward(-5, 10); //Act award.ProcessUpdate(); //Assert Assert.AreEqual(award.ExpiresIn, -6); Assert.AreEqual(award.Quality, 0); Assert.AreEqual(award.ToString(), "Award Name: Blue Compare, Expires In: -6, Quality: 0"); }
public void TestBlueCompareAwardProcessUpdateWithExpiredInBetween0And5Included() { //Arrange BlueCompareAward award = new BlueCompareAward(3, 10); //Act award.ProcessUpdate(); //Assert Assert.AreEqual(award.ExpiresIn, 2); Assert.AreEqual(award.Quality, 13); Assert.AreEqual(award.ToString(), "Award Name: Blue Compare, Expires In: 2, Quality: 13"); }
public void Test_BlueCompare_UpdateQuality_Progression() { Dictionary <int, int> answerKey = new Dictionary <int, int>() { // Key = ExpiresIn, Value = Quality { 12, 25 }, // Start, Increase by 1 if more than 10 days { 11, 26 }, // Increase by 1 if more than 10 days { 10, 27 }, // Increase by 2 if more than 5 days and 10 days or less { 9, 29 }, // Increase by 2 if more than 5 days and 10 days or less { 8, 31 }, // Increase by 2 if more than 5 days and 10 days or less { 7, 33 }, // Increase by 2 if more than 5 days and 10 days or less { 6, 35 }, // Increase by 2 if more than 5 days and 10 days or less { 5, 37 }, // Increase by 3 if not expired and 5 days or less { 4, 40 }, // Increase by 3 if not expired and 5 days or less { 3, 43 }, // Increase by 3 if not expired and 5 days or less { 2, 46 }, // Increase by 3 if not expired and 5 days or less { 1, 49 }, // Increase by 3 if not expired and 5 days or less { 0, 50 }, // Increase by 3 if not expired and 5 days or less, cannot exceed 50 { -1, 0 } // Reduce to 0 if expired }; var bc = new BlueCompareAward() { Name = "Blue Compare", Quality = 25, ExpiresIn = 12, OriginalQuality = 25, OriginalExpiresIn = 12 }; Assert.IsNotNull(bc); Assert.IsTrue(bc.Name == "Blue Compare"); Assert.IsTrue(bc.OriginalExpiresIn == 12); Assert.IsTrue(bc.ExpiresIn == 12); Assert.IsTrue(bc.Quality == 25); for (int idx = 12; idx > -2; idx--) { int expiresIn = idx; Assert.IsTrue(bc.ExpiresIn == expiresIn); Assert.IsTrue(bc.Quality == answerKey[expiresIn]); bc.UpdateQuality(); if (expiresIn > -1)//to prevent the last execution { Assert.IsTrue(bc.ExpiresIn == expiresIn - 1); Assert.IsTrue(bc.Quality == answerKey[expiresIn - 1]); } } }
public void Algorithm_BlueCompare() { var algo = new BlueCompareAlgorithm(); IAward award = new BlueCompareAward(0, TimeSpan.FromDays(15)); var runner = new AwardAlgorithmRunner(algo); runner.Add(award); runner.RunAlgorithmWithDayIncrement(16); var expected = new[] { 0, 1, 2, 3, 4, 6, 8, 10, 12, 14, 17, 20, 23, 26, 29, 32, 0 }; CollectionAssert.AreEqual(expected, runner.AwardInfos[0].history); }
public void Algorithm_BlueCompare_AcrossExpiration() { var algo = new BlueCompareAlgorithm(); IAward award = new BlueCompareAward(50, TimeSpan.FromDays(0)); Assert.IsFalse(award.IsExpired); award = algo.Run(award); Assert.IsTrue(award.Quality > 0); award.IncrementDay(); award = algo.Run(award); Assert.IsTrue(award.IsExpired); Assert.AreEqual(0, award.Quality); }
public void Algorithm_BlueCompare_Expired() { var algo = new BlueCompareAlgorithm(); IAward award = new BlueCompareAward(50, TimeSpan.FromDays(0)); award.IncrementDay(); Assert.IsTrue(award.IsExpired); Assert.AreEqual(50, award.Quality); algo.Run(award); Assert.AreEqual(0, award.Quality); for (var i = 0; i < 25; i++) { award = algo.Run(award); Assert.AreEqual(0, award.Quality, $"Quality is non-zero on iteration '{i}'"); } }
public void Award_BlueCompare() { // we don't explicitly test for expiration here, the behavior of this particular // award is fairly complex and relies on the expiration functionality working properly. // If the algorithm works as expected, the expiration is necessarily working as expected. // IAward award = new BlueCompareAward(0, TimeSpan.FromDays(15)); var algo = award.UpdateAlgorithm; var runner = new AwardAlgorithmRunner(algo); runner.Add(award); runner.RunAlgorithmWithDayIncrement(16); var expected = new[] { 0, 1, 2, 3, 4, 6, 8, 10, 12, 14, 17, 20, 23, 26, 29, 32, 0 }; CollectionAssert.AreEqual(expected, runner.AwardInfos[0].history); }