Пример #1
0
        public void ReportsCorrectItemCount()
        {
            BinaryHeap <TestType> heap = new BinaryHeap <TestType>();

            Assert.Equal(0, heap.Count);

            heap.Push(new TestType(123));
            heap.Push(new TestType(124));

            Assert.Equal(2, heap.Count);

            Assert.Equal(123, heap.Pop().Priority);

            Assert.Equal(1, heap.Count);

            Assert.Equal(124, heap.Pop().Priority);

            Assert.Equal(0, heap.Count);

            heap.Push(new TestType(-1));

            Assert.Equal(1, heap.Count);

            Assert.Equal(-1, heap.Pop().Priority);

            Assert.Equal(0, heap.Count);
        }
Пример #2
0
        public void ReturnsItemsInCorrectOrder()
        {
            BinaryHeap <TestType> heap = new BinaryHeap <TestType>();

            heap.Push(new TestType(123));
            heap.Push(new TestType(124));
            heap.Push(new TestType(120));
            heap.Push(new TestType(95));

            Assert.Equal(95, heap.Pop().Priority);

            heap.Push(new TestType(-1));

            Assert.Equal(-1, heap.Pop().Priority);

            Assert.Equal(120, heap.Pop().Priority);
            Assert.Equal(123, heap.Pop().Priority);
            Assert.Equal(124, heap.Pop().Priority);
        }