Ejemplo n.º 1
0
        /// <summary>
        /// Does a generic heap test.
        /// </summary>
        /// <param name="heap">Heap to be checked.</param>
        /// <param name="input">Input values.</param>
        private static void HeapTest <Value>(IHeap <Value, Value> heap, List <Value> input) where Value : IComparable
        {
            List <Value> sortedInput = new List <Value>(input);

            sortedInput.Sort();

            input.ForEach(number => heap.Add(number, number));
            Assert.AreEqual(input.Count, heap.GetSize());

            Assert.AreEqual(sortedInput[0], heap.GetMinKey());

            heap.Clear();
            Assert.AreEqual(0, heap.GetSize());

            input.ForEach(number => heap.Add(number, number));
            List <Value> result = new List <Value>();

            while (heap.GetSize() != 0)
            {
                result.Add(heap.RemoveMin());
            }

            Assert.IsTrue(CollectionsEquality.Equals(sortedInput, result));
        }