Exemplo n.º 1
0
        public void SortingSomeArrayWhenMaxComparerUsing()
        {
            var array     = new[] { -5, 5, -10, -4, 11, 0, 1, -9, 9, 7 };
            var arrayCopy = (int[])array.Clone();
            var comparer  = new MyIntComparer();

            array.HeapSort(comparer);
            Array.Sort(arrayCopy, comparer);

            CollectionAssert.AreEqual(arrayCopy, array);
        }
Exemplo n.º 2
0
        public void HeapFromCollectionConstructorWorksRightWhenMaxComparerUsing()
        {
            var comparer = new MyIntComparer();
            var list     = new List <int>(new[] { 2, 4, -2, 0, 1, 7 });
            var heap     = new Heap <int>(list, comparer);

            list.Sort(comparer);
            var listFromHeap = new List <int>();

            foreach (var element in heap)
            {
                listFromHeap.Add(element);
            }

            CollectionAssert.AreEqual(list, listFromHeap);
        }