Beispiel #1
0
        public void create_empty_heap_min()
        {
            Heap heap = new Heap(HeapType.Min);

            Assert.Equal(heap.Size(), 0);
            Assert.Throws <InvalidOperationException>(() => heap.Peek());
        }
Beispiel #2
0
        public void create_heap_with_two_elements_get_maximum_value()
        {
            Heap heap = new Heap(HeapType.Max);

            heap.Append(2);
            heap.Append(1);

            Assert.Equal(heap.Peek(), 2);
        }
Beispiel #3
0
        public void create_heap_with_two_elements_get_minimal_value()
        {
            Heap heap = new Heap(HeapType.Min);

            heap.Append(2);
            heap.Append(1);

            Assert.Equal(heap.Peek(), 1);
        }
Beispiel #4
0
        public void create_min_heap_with_single_element_and_no_children()
        {
            Heap heap = new Heap(HeapType.Min);

            heap.Append(1);

            Assert.Equal(heap.Size(), 1);
            Assert.Equal(heap.Peek(), 1);
        }
Beispiel #5
0
        public void should_set_maximum_element_first_negative()
        {
            Heap heap = new Heap(HeapType.Max);

            heap.Append(-20);
            heap.Append(-1);
            heap.Append(-21);
            heap.Append(-2);

            Assert.Equal(heap.Peek(), -1);
        }
Beispiel #6
0
        public void should_set_maximum_element_first_when_previous_popped()
        {
            Heap heap = new Heap(HeapType.Max);

            heap.Append(20);
            heap.Append(1);
            heap.Append(21);
            heap.Append(2);

            heap.Pop();

            Assert.Equal(heap.Peek(), 20);
        }