public void MaxBinaryHeapSizeTest() { MaxBinaryHeap <int, int> heap = new MaxBinaryHeap <int, int>(); Assert.AreEqual(0, heap.Size); heap.Insert(1, 11); heap.Insert(2, 22); Assert.AreEqual(2, heap.Size); }
public void MaxValueElementIsOnTheTop() { var sut = new MaxBinaryHeap <int>(); sut.Insert(10); sut.Insert(20); Assert.Equal(20, sut.GetTop()); Assert.Equal(10, sut.GetTop()); }
public void Insert_SeveralValues_ExpectCorrectMaxBinaryHeapAfterEachInsert() { var heap = new MaxBinaryHeap <int, string>(new List <KeyValuePair <int, string> > { }); heap.Insert(_nodeA, heap.HeapArray.Count); Assert.IsTrue(HasMaxOrderPropertyForHeap(1, heap)); heap.Insert(_nodeB, heap.HeapArray.Count); Assert.IsTrue(HasMaxOrderPropertyForHeap(2, heap)); heap.Insert(_nodeC, heap.HeapArray.Count); Assert.IsTrue(HasMaxOrderPropertyForHeap(3, heap)); heap.Insert(_nodeD, heap.HeapArray.Count); Assert.IsTrue(HasMaxOrderPropertyForHeap(4, heap)); heap.Insert(_nodeE, heap.HeapArray.Count); Assert.IsTrue(HasMaxOrderPropertyForHeap(5, heap)); heap.Insert(_nodeF, heap.HeapArray.Count); Assert.IsTrue(HasMaxOrderPropertyForHeap(6, heap)); heap.Insert(_nodeG, heap.HeapArray.Count); Assert.IsTrue(HasMaxOrderPropertyForHeap(7, heap)); heap.Insert(_nodeH, heap.HeapArray.Count); Assert.IsTrue(HasMaxOrderPropertyForHeap(8, heap)); heap.Insert(_nodeI, heap.HeapArray.Count); Assert.IsTrue(HasMaxOrderPropertyForHeap(9, heap)); }
public void MaxBinaryHeapIsEmptyTest() { MaxBinaryHeap <int, int> heap = new MaxBinaryHeap <int, int>(); Assert.IsTrue(heap.IsEmpty); heap.Insert(1, 1); heap.Insert(2, 2); Assert.IsFalse(heap.IsEmpty); heap.Clear(); Assert.IsTrue(heap.IsEmpty); }
public void MaxBinaryHeapGetMaximumValueTest() { MaxBinaryHeap <int, int> heap = new MaxBinaryHeap <int, int>(); heap.Insert(2, 22); heap.Insert(3, 33); heap.Insert(1, 11); Assert.AreEqual(3, heap.Size); Assert.AreEqual(33, heap.GetMaximumValue()); Assert.AreEqual(3, heap.Size); }
public void TopElementIsInsertedWhenHeapIsEmpty() { var sut = new MaxBinaryHeap <int>(); sut.Insert(10); Assert.Equal(10, sut.GetTop()); }
static MaxBinaryHeap <int, int> CreateMaxBinaryHeap() { MaxBinaryHeap <int, int> heap = new MaxBinaryHeap <int, int>(); var heapData = GetMaxHeapTestData(); heapData.ForEach(x => heap.Insert(x.Key, x.Value)); return(heap); }
public void Insert_Should_ReturnArray() { //arrange var heap = new MaxBinaryHeap(); //act heap.Insert(55); //assert Assert.That(heap.values[0], Is.EqualTo(55)); }
private static MaxBinaryHeap <int> ReadBinaryHeap() { int[] nodes = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); MaxBinaryHeap <int> result = new MaxBinaryHeap <int>(); foreach (int t in nodes) { result.Insert(t); } return(result); }
public void Insert_Should_BubbleLargestNumberToTop() { //arrange var heap = new MaxBinaryHeap() { values = { 41, 39, 33, 18, 27, 12 } }; //act heap.Insert(55); //assert Assert.That(heap.values[0], Is.EqualTo(55)); }
public void MaxValueElementIsAlwaysOnTheTop() { var sut = new MaxBinaryHeap <int>(1001); var randomValues = new int[1000]; var random = new Random(); for (var i = 0; i < 1000; i++) { randomValues[i] = random.Next(10000); sut.Insert(randomValues[i]); } var orderedArray = randomValues.OrderByDescending(arg => arg).ToArray(); for (var i = 0; i < 1000; i++) { Assert.Equal(orderedArray[i], sut.GetTop()); } }
public void MaxBinaryHeapInsertTest() { MaxBinaryHeap <int, int> heap = new MaxBinaryHeap <int, int>(); heap.Insert(1, 10); heap.Insert(4, 40); heap.Insert(2, 20); heap.Insert(5, 50); heap.Insert(13, 130); heap.Insert(6, 60); heap.Insert(17, 170); List <int> valueList = new List <int>(); while (heap.Size != 0) { valueList.Add(heap.DeleteMaximumValue()); } CollectionAssert.AreEqual(new int[] { 170, 130, 60, 50, 40, 20, 10 }, valueList); }
public void MaxBinaryHeapInsertGuardTest() { MaxBinaryHeap <string, int> heap = new MaxBinaryHeap <string, int>(); heap.Insert(null, 1); }