Example #1
0
        public void ClearsItems()
        {
            BinaryHeap <TestType> heap = new BinaryHeap <TestType>();

            Assert.Equal(0, heap.Count);

            heap.Push(new TestType(1));
            heap.Push(new TestType(2));
            heap.Push(new TestType(3));

            Assert.Equal(3, heap.Count);

            heap.Clear();

            Assert.Equal(0, heap.Count);
        }
Example #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);
        }
Example #3
0
        public void ReportsCorrectCapacity()
        {
            BinaryHeap <TestType> heap = new BinaryHeap <TestType>(7);

            Assert.Equal(0, heap.Count);
            Assert.Equal(7, heap.Capacity);

            heap.Push(new TestType(1));
            heap.Push(new TestType(2));
            heap.Push(new TestType(3));
            heap.Push(new TestType(4));
            heap.Push(new TestType(5));
            heap.Push(new TestType(6));
            heap.Push(new TestType(7));

            Assert.Equal(7, heap.Capacity);

            heap.Push(new TestType(8));

            Assert.True(heap.Capacity > 7);
        }
Example #4
0
        public void ThrowsOnNullPush()
        {
            BinaryHeap <string> heap = new BinaryHeap <string>();

            Assert.Throws <ArgumentNullException>(() => { heap.Push(default); });