示例#1
0
        public void Remove_RemoveAllFromTail_EmptyHeap()
        {
            // arrange
            MaxHeap heap = new MaxHeap(1000);

            // act
            heap.Add(3);
            heap.Add(2);
            heap.Add(1);
            heap.RemoveAt(2);
            heap.RemoveAt(1);
            heap.RemoveAt(0);

            // assert
            Assert.AreEqual(0, heap.Size);
        }
示例#2
0
        public void Remove_HalfRandomElements_HeapSorted()
        {
            // arrange
            const int heapSize = 10;
            MaxHeap heap = new MaxHeap(heapSize);

            // act
            Random r = new Random(heapSize);
            for (int i = 0; i < heapSize; i++)
            {
                heap.Add(r.Next() % 10);
            }

            int j = heapSize / 2;
            while (j >= 0)
            {
                heap.RemoveAt(0);
                j--;
            }

            // assert
            ValidateSorting(heap);
        }
示例#3
0
        public void Remove_RandomElements_EmptyHeap()
        {
            // arrange
            const int heapSize = 1000000;
            MaxHeap heap = new MaxHeap(heapSize);

            // act
            Random r = new Random(heapSize);
            for (int i = 0; i < heapSize; i++)
            {
                heap.Add(r.Next());
            }

            int j = heapSize - 1;
            while (j >= 0)
            {
                heap.RemoveAt(0);
                j--;
            }

            // assert
            Assert.AreEqual(0, heap.Size);
        }