Ejemplo n.º 1
0
        public void Minimum_SingleElement_ReturnsElement()
        {
            var heap = new BinaryHeap <int>();

            heap.Insert(42);
            Assert.That(heap.Minimum, Is.EqualTo(42));
        }
Ejemplo n.º 2
0
        public void Insert_Empty_CountIsOne()
        {
            var heap = new BinaryHeap <int>();

            heap.Insert(0);
            Assert.That(heap.Count, Is.EqualTo(1));
        }
Ejemplo n.º 3
0
        public void ExtractMinimum_SingleElement_RemovesElement()
        {
            var heap = new BinaryHeap <int>();

            heap.Insert(0);
            heap.ExtractMinimum();
            Assert.That(heap.Count, Is.Zero);
            Assert.That(() => heap.Minimum, Throws.InvalidOperationException);
        }
Ejemplo n.º 4
0
        public void Minimum_ManyElements_IsCorrect(params int[] values)
        {
            var heap = new BinaryHeap <int>();

            foreach (var value in values)
            {
                heap.Insert(value);
            }

            Assert.That(heap.Minimum, Is.EqualTo(values.Min()));
        }
Ejemplo n.º 5
0
        public void Insert_MultipleTimesIntoEmpty_CountIsCorrect(int size)
        {
            var heap = new BinaryHeap <int>();

            for (var i = 0; i < size; i++)
            {
                heap.Insert(0);
            }

            Assert.That(heap.Count, Is.EqualTo(size));
        }
Ejemplo n.º 6
0
        public void ExtractMinimum_ManyElements_CanSortSequence(params int[] values)
        {
            var heap = new BinaryHeap <int>();

            foreach (var value in values)
            {
                heap.Insert(value);
            }

            var sorted = new List <int>();

            while (heap.Count > 0)
            {
                sorted.Add(heap.ExtractMinimum());
            }

            Assert.That(sorted, Is.EqualTo(values.OrderBy(x => x).ToList()));
        }