Exemple #1
0
        private void Add2(SimpleHeapFactory heapFactory)
        {
            ISimpleHeap <int> heap = heapFactory();

            heap.Add(43);
            Assert.AreEqual(43, heap.Top);

            heap.Add(-11);
            Assert.AreEqual(-11, heap.Top);

            heap.Add(0);
            Assert.AreEqual(-11, heap.Top);

            heap.Add(-13);
            Assert.AreEqual(-13, heap.Top);

            heap.Add(5);
            Assert.AreEqual(-13, heap.Top);

            heap.Add(-50);
            Assert.AreEqual(-50, heap.Top);

            heap.Add(-50);
            Assert.AreEqual(-50, heap.Top);

            heap.Add(0);
            Assert.AreEqual(-50, heap.Top);
            Assert.AreEqual(8, heap.Size);
        }
Exemple #2
0
        private void DefaultConstruction(SimpleHeapFactory heapFactory)
        {
            ISimpleHeap <int> heap = heapFactory();

            heap.Add(1);
            Assert.AreEqual(1, heap.Top);
        }
Exemple #3
0
        private void Add1(SimpleHeapFactory heapFactory)
        {
            ISimpleHeap <int> heap = heapFactory(_sourceArray, _descendingComparer);

            heap.Add(13);
            Assert.AreEqual(42, heap.Top);

            heap.Add(43);
            Assert.AreEqual(43, heap.Top);

            heap.Add(-100);
            Assert.AreEqual(43, heap.Top);

            heap.Add(50);
            Assert.AreEqual(50, heap.Top);
            Assert.AreEqual(_sourceArray.Count + 4, heap.Size);
        }
Exemple #4
0
        private void Extract(SimpleHeapFactory heapFactory)
        {
            ISimpleHeap <int> heap = heapFactory(comparer: _descendingComparer);

            heap.Add(13);
            heap.Add(43);
            heap.Add(-100);
            heap.Add(50);
            Assert.AreEqual(50, heap.Extract());
            Assert.AreEqual(3, heap.Size);
            Assert.AreEqual(43, heap.Extract());
            Assert.AreEqual(2, heap.Size);
            Assert.AreEqual(13, heap.Extract());
            Assert.AreEqual(1, heap.Size);
            Assert.AreEqual(-100, heap.Extract());
            Assert.AreEqual(0, heap.Size);

            heap.Add(10);
            Assert.AreEqual(10, heap.Extract());
            Assert.AreEqual(0, heap.Size);
        }