Пример #1
0
        public void GetFirstUnsafe_Blindly_Returns_Whatever_At_0Th_Index_Irrespective_Of_Count()
        {
            var instance = new TestAbstractBinaryHeap(5, (x, y) => x < y);

            Assert.IsTrue(instance.GetFirstUnsafe().Equals(0));
            instance.Add(0);
            Assert.IsTrue(instance.GetFirstUnsafe().Equals(0));
            instance.Add(-1);
            Assert.IsTrue(instance.GetFirstUnsafe().Equals(-1));
        }
Пример #2
0
        public void Pop_N_TryPop_Behaves_For_Non_Empty_Heap()
        {
            IHeap <int> instance = new TestAbstractBinaryHeap(5, (x, y) => x < y);

            instance.Add(3);
            instance.Add(2);
            instance.Add(1);
            instance.Add(4);
            instance.Add(1);
            Assert.AreEqual(instance.Pop(), 1);
            Assert.AreEqual(instance.Pop(), 1);
            Assert.AreEqual(instance.Pop(), 2);
            Assert.AreEqual(instance.Pop(), 3);
            Assert.AreEqual(instance.Pop(), 4);
            Assert.True(instance.IsEmpty);
            Assert.IsFalse(instance.TryPop(out _));
        }
Пример #3
0
        public void Peek_N_TryPeek_Behaves_For_Non_Empty_Heap()
        {
            IHeap <int> instance = new TestAbstractBinaryHeap(1, (x, y) => x < y);

            instance.Add(1);
            Assert.AreEqual(instance.Peek(), 1);
            Assert.True(instance.TryPeek(out var val) && val.Equals(1));
        }
Пример #4
0
        public void Add_N_Try_Add_Behaves_For_Non_Empty_Heap()
        {
            IHeap <int> instance = new TestAbstractBinaryHeap(1, (x, y) => x < y);

            Assert.True(instance.IsEmpty);
            Assert.IsTrue(instance.TryAdd(1));
            Assert.IsFalse(instance.TryAdd(1));
            var ex = Assert.Throws <DdnDfException>(() => instance.Add(1));

            Assert.NotNull(ex);
            Assert.IsTrue(ex.ErrorCode.Equals(DdnDfErrorCode.DemandUnfulfilled));
            Assert.IsTrue(ex.Message.Equals("(DemandUnfulfilled) Unable to add element in the heap."));
            instance = new TestAbstractBinaryHeap(3, (x, y) => x < y);
            instance.Add(3);
            Assert.False(instance.IsFull);
            instance.Add(2);
            Assert.False(instance.IsFull);
            Assert.IsTrue(instance.TryAdd(1));
            Assert.True(instance.IsFull);
        }