Beispiel #1
0
        private static void SimpleEndPointHeapTest()
        {
            var heap = new EndPointHeap();

            Assert.IsTrue(heap.IsEmpty);
            Assert.AreEqual(0, heap.Count);
            Assert.IsFalse(heap.TryPeekNext(out long time, out int value));
            Assert.IsFalse(heap.TryGetNext(out time, out value));
            Assert.IsFalse(heap.TryGetNextExclusive(100, out time, out value));
            Assert.IsFalse(heap.TryGetNextInclusive(100, out time, out value));

            heap.Insert(5, 1000);

            Assert.IsFalse(heap.IsEmpty);
            Assert.AreEqual(1, heap.Count);
            Assert.IsFalse(heap.TryGetNextExclusive(1, out time, out value));
            Assert.IsFalse(heap.TryGetNextInclusive(1, out time, out value));
            Assert.IsTrue(heap.TryPeekNext(out time, out value));
            Assert.AreEqual(5, time);
            Assert.AreEqual(1000, value);

            Assert.IsTrue(heap.TryGetNext(out time, out value));
            Assert.AreEqual(5, time);
            Assert.AreEqual(1000, value);

            Assert.IsTrue(heap.IsEmpty);

            heap.Insert(3, 1001);
            heap.Insert(5, 1002);
            heap.Insert(4, 1003);

            Assert.IsFalse(heap.TryGetNextInclusive(2, out time, out value));
            Assert.IsTrue(heap.TryGetNextInclusive(3, out time, out value));
            Assert.AreEqual(3, time);
            Assert.AreEqual(1001, value);

            Assert.IsFalse(heap.TryGetNextExclusive(4, out time, out value));
            Assert.IsTrue(heap.TryGetNextExclusive(5, out time, out value));
            Assert.AreEqual(4, time);
            Assert.AreEqual(1003, value);

            Assert.IsTrue(heap.TryGetNextInclusive(100, out time, out value));
            Assert.AreEqual(5, time);
            Assert.AreEqual(1002, value);

            Assert.IsTrue(heap.IsEmpty);
        }