public void MinuteConversion_Works([Range(0, 59)] int minute) { string val = CalculateTimeGuidPositionalValue(minute, "m"); DateTime d = new DateTime(2000, 01, 01, 0, minute, 0); string guidValue = TimeGuid.ConvertDateTimeToTimeGuid(d); string guidChar = guidValue.Substring(1, 1); Assert.AreEqual(val, guidChar, "A1: The minute did not convert to the expected ascii character. Exp: " + val + " Actual: " + guidValue); }
public void SecondConversion_Works([Range(0, 59)] int second) { string val = CalculateTimeGuidPositionalValue(second, "s"); DateTime d = new DateTime(2000, 01, 01, 0, 0, second); string guidValue = TimeGuid.ConvertDateTimeToTimeGuid(d); string guidChar = guidValue.Substring(2, 1); Assert.AreEqual(val, guidChar, "A1: The second did not convert to the expected ascii character. Exp: " + val + " Actual: " + guidValue); }
public void HourConversion_Works([Range(0, 23)] int hr) { string val = CalculateTimeGuidPositionalValue(hr, "h"); DateTime d = new DateTime(2000, 01, 01, hr, 0, 0); string guidValue = TimeGuid.ConvertDateTimeToTimeGuid(d); string guidChar = guidValue.Substring(0, 1); Assert.AreEqual(val, guidChar, "A1: The hour did not convert to the expected ascii character. Exp: " + val + " Actual: " + guidValue); }
public void TimeGUIDConversion_Works([Random(0, 23, 5)] int hr, [Random(0, 59, 5)] int minute, [Random(0, 59, 5)] int second) { string valSec = CalculateTimeGuidPositionalValue(second, "s"); string valMin = CalculateTimeGuidPositionalValue(minute, "m"); string valHr = CalculateTimeGuidPositionalValue(hr, "h"); string valCombo = valHr + valMin + valSec; DateTime d = new DateTime(2000, 01, 01, hr, minute, second); string guidValue = TimeGuid.ConvertDateTimeToTimeGuid(d); Assert.AreEqual(valCombo, guidValue, "A1: The TimeGuid was not converted correctly. Exp: " + valCombo + " Actual: " + guidValue); TestContext.WriteLine("TimeGuid Value produced was: " + guidValue); // Now perform the random equality comparison. Random rnd = new Random(); int hr1 = rnd.Next(hr, 23); int min1; int sec1; if (hr1 == hr) { min1 = rnd.Next(minute, 59); if (minute == min1) { sec1 = rnd.Next(second, 59); } else { sec1 = rnd.Next(0, 59); } } else { min1 = rnd.Next(0, 59); if (minute == min1) { sec1 = rnd.Next(second, 59); } else { sec1 = rnd.Next(0, 59); } } // This just exits in the rare case that the random values chosen happen to be the exact same as the initial ones. This // prevents a test failure. if (hr1 == hr && min1 == minute && sec1 == second) { return; } DateTime d2 = new DateTime(2000, 01, 01, hr1, min1, sec1); TimeGuid y = new TimeGuid(d2); TimeGuid x = new TimeGuid(d); Assert.True(x < y, "Expected the comparison of y[" + y.ToString + "] > x[" + x.ToString + "] to be true. It was not. Something Wrong! "); TestContext.WriteLine("Comparing x[" + x.ToString + "] < y[" + y.ToString + "] was successful"); }