public void CompareTo_ByNode() { var timestamp = Timestamp.Now; var clockSequence = TimeGuidGenerator.GenerateRandomClockSequence(); var timeGuid1 = new TimeGuid(timestamp, clockSequence, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); var timeGuid2 = new TimeGuid(timestamp, clockSequence, new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 }); var timeGuid3 = new TimeGuid(timestamp, clockSequence, new byte[] { 0x12, 0x34, 0x56, 0x78, 0xfe, 0xff }); var timeGuid4 = new TimeGuid(timestamp, clockSequence, new byte[] { 0x12, 0x34, 0x56, 0x78, 0xff, 0x00 }); var timeGuid5 = new TimeGuid(timestamp, clockSequence, new byte[] { 0x12, 0x34, 0x56, 0x78, 0xff, 0xff }); var timeGuid6 = new TimeGuid(timestamp, clockSequence, new byte[] { 0x12, 0x34, 0x56, 0x79, 0x00, 0x00 }); var timeGuid7 = new TimeGuid(timestamp, clockSequence, new byte[] { 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00 }); var timeGuid8 = new TimeGuid(timestamp, clockSequence, new byte[] { 0x7f, 0x01, 0x00, 0x00, 0x00, 0x00 }); var timeGuid9 = new TimeGuid(timestamp, clockSequence, new byte[] { 0xff, 0x00, 0x00, 0x00, 0x00, 0x00 }); var timeGuid10 = new TimeGuid(timestamp, clockSequence, new byte[] { 0xff, 0x00, 0x12, 0x34, 0x00, 0x00 }); var timeGuid11 = new TimeGuid(timestamp, clockSequence, new byte[] { 0xff, 0x00, 0x12, 0x35, 0x00, 0x00 }); var timeGuid12 = new TimeGuid(timestamp, clockSequence, new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0x01 }); var timeGuid13 = new TimeGuid(timestamp, clockSequence, new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }); Assert.That(timeGuid1.CompareTo(timeGuid2), Is.Negative); Assert.That(timeGuid2.CompareTo(timeGuid3), Is.Negative); Assert.That(timeGuid3.CompareTo(timeGuid4), Is.Negative); Assert.That(timeGuid4.CompareTo(timeGuid5), Is.Negative); Assert.That(timeGuid5.CompareTo(timeGuid6), Is.Negative); Assert.That(timeGuid6.CompareTo(timeGuid7), Is.Negative); Assert.That(timeGuid7.CompareTo(timeGuid8), Is.Negative); Assert.That(timeGuid8.CompareTo(timeGuid9), Is.Negative); Assert.That(timeGuid9.CompareTo(timeGuid10), Is.Negative); Assert.That(timeGuid10.CompareTo(timeGuid11), Is.Negative); Assert.That(timeGuid11.CompareTo(timeGuid12), Is.Negative); Assert.That(timeGuid12.CompareTo(timeGuid13), Is.Negative); }
public void CompareTo_FirstLessThanSecond() { DateTime today = DateTime.Now; TimeGuid x = new TimeGuid(today); TimeGuid y = new TimeGuid(today.AddMinutes(2)); Assert.Less(x.CompareTo(y), 0, "A10: First value should have indicated it was less than second value."); }
public void CompareTo_ByClockSequence() { var timestamp = Timestamp.Now; ushort clockSequence1 = 0; ushort clockSequence2 = 1; while (clockSequence2 <= TimeGuidBitsLayout.MaxClockSequence) { var timeGuid1 = new TimeGuid(timestamp, clockSequence1, new byte[6]); var timeGuid2 = new TimeGuid(timestamp, clockSequence2, new byte[6]); Assert.That(timeGuid1.CompareTo(timeGuid1), Is.EqualTo(0)); Assert.That(timeGuid2.CompareTo(timeGuid2), Is.EqualTo(0)); Assert.That(timeGuid1.CompareTo(timeGuid2), Is.Negative); Assert.That(timeGuid2.CompareTo(timeGuid1), Is.Positive); clockSequence1++; clockSequence2++; } }
public void CompareTo_ByTimestamp() { var timestamp1 = Timestamp.Now; var timestamp2 = timestamp1.AddTicks(1); var clockSequence = TimeGuidGenerator.GenerateRandomClockSequence(); var timeGuid1 = new TimeGuid(timestamp1, clockSequence, new byte[6]); var timeGuid2 = new TimeGuid(timestamp2, clockSequence, new byte[6]); Assert.That(timeGuid2.CompareTo(timeGuid1), Is.Positive); Assert.That(timeGuid1.CompareTo(timeGuid2), Is.Negative); }
public void CompareTo_ByClockSequence_AllDistinctValues() { var node = new byte[6]; var timestamp = Timestamp.Now; const int step = 10; for (var clockSequence1 = TimeGuidBitsLayout.MinClockSequence; clockSequence1 <= TimeGuidBitsLayout.MaxClockSequence; clockSequence1++) { for (var clockSequence2Base = TimeGuidBitsLayout.MinClockSequence; clockSequence2Base < TimeGuidBitsLayout.MaxClockSequence - step; clockSequence2Base += step) { var clockSequence2 = (ushort)(clockSequence2Base + rng.Next(step)); var timeGuid1 = new TimeGuid(timestamp, clockSequence1, node); var timeGuid2 = new TimeGuid(timestamp, clockSequence2, node); var expectedResult = clockSequence1.CompareTo(clockSequence2); Assert.That(timeGuid1.CompareTo(timeGuid2), Is.EqualTo(expectedResult), $"clockSequence1 = {clockSequence1}, clockSequence2 = {clockSequence2}"); } } }