Exemplo n.º 1
0
        public void Add_SecondAddedItemIsGreater_ExpectGreaterItemIsMovedToArrayBeginning()
        {
            var heap = new MaxBinaryHeap<int>();

            heap.Add(10);
            heap.Add(15);

            CollectionAssert.AreEqual(new[] { 15, 10 }, heap.ToArray());
        }
Exemplo n.º 2
0
        public void Add_ExpectHeapContainsItem()
        {
            var heap = new MaxBinaryHeap<int>();
            var item = 10;

            heap.Add(item);

            CollectionAssert.AreEquivalent(new[] { item }, heap.ToArray());
        }
Exemplo n.º 3
0
        public void Add_MoreThanOneSwap_ExpectMaxItemIsMovedToArrayBeginning()
        {
            var heap = new MaxBinaryHeap<int>();

            heap.Add(1);
            heap.Add(3);
            heap.Add(5);
            heap.Add(8);

            CollectionAssert.AreEqual(new[] { 8, 5, 3, 1 }, heap.ToArray());
        }
Exemplo n.º 4
0
        public void DeleteMax_MoreThanOneSwap_ExpectHeapIsValid()
        {
            var heap = new MaxBinaryHeap<int>();

            //three complete layers in tree + one element on the forth layer
            var items = new[] { 1, 3, 5, 8, 13, 21, 34, 55 };
            foreach (var item in items)
            {
                heap.Add(item);
            }

            heap.DeleteMax();

            var expectedArray = new[] { 34, 8, 21, 1, 5, 3, 13 };
            CollectionAssert.AreEqual(expectedArray, heap.ToArray());
        }