public void SingleIsEmptyTest() { var heap = LeftistHeap <int> .Empty; heap = LeftistHeap <int> .Insert(2, heap); Assert.IsFalse(LeftistHeap <int> .IsEmpty(heap)); }
public void SingleElement() { var heap = LeftistHeap <int> .Empty; heap = LeftistHeap <int> .Insert(2, heap); Assert.AreEqual("2, ", DumpHeap(heap)); }
public void InsertZeroTest() { var heap = new[] { 3, 2, 5, 1 }.Aggregate(LeftistHeap <int> .Empty, (h, x) => LeftistHeap <int> .Insert(x, h)); heap = LeftistHeap <int> .Insert(0, heap); Assert.AreEqual("3, 2, 5, 1, 0, ", DumpHeap(heap)); Assert.AreEqual(0, LeftistHeap <int> .FindMin(heap)); }
public void SingleDeleteMinTest() { var heap = LeftistHeap <int> .Empty; heap = LeftistHeap <int> .Insert(2, heap); heap = LeftistHeap <int> .DeleteMin(heap); Assert.IsTrue(LeftistHeap <int> .IsEmpty(heap)); }
public void SingleMinTest() { var heap = LeftistHeap <int> .Empty; heap = LeftistHeap <int> .Insert(2, heap); var x = LeftistHeap <int> .FindMin(heap); Assert.AreEqual(2, x); }
public void DeleteLotsOfMinsTest() { var random = new Random(3456); var heap = LeftistHeap <int> .Empty; for (var i = 0; i < 100; i++) { heap = LeftistHeap <int> .Insert(random.Next(100), heap); } var last = 0; var count = 0; while (!LeftistHeap <int> .IsEmpty(heap)) { var next = LeftistHeap <int> .FindMin(heap); heap = LeftistHeap <int> .DeleteMin(heap); Assert.IsTrue(last <= next); last = next; count++; } Assert.AreEqual(100, count); }
public void MergeTest() { var heap1 = new[] { "How", "now," }.Aggregate(LeftistHeap <string> .Empty, (h, x) => LeftistHeap <string> .Insert(x, h)); var heap2 = new[] { "brown", "cow?" }.Aggregate(LeftistHeap <string> .Empty, (h, x) => LeftistHeap <string> .Insert(x, h)); var heap = LeftistHeap <string> .Merge(heap1, heap2); Assert.AreEqual("cow?, brown, now,, How, ", DumpHeap(heap)); Assert.AreEqual("brown", LeftistHeap <string> .FindMin(heap)); }
public void DelSecondMinTest() { var heap = new[] { 3, 2, 5, 1 }.Aggregate(LeftistHeap <int> .Empty, (h, x) => LeftistHeap <int> .Insert(x, h)); heap = LeftistHeap <int> .DeleteMin(heap); heap = LeftistHeap <int> .DeleteMin(heap); Assert.AreEqual("5, 3, ", DumpHeap(heap)); Assert.AreEqual(3, LeftistHeap <int> .FindMin(heap)); }
public void MinTreeTest() { var heap = new[] { 3, 2, 5, 1 }.Aggregate(LeftistHeap <int> .Empty, (h, x) => LeftistHeap <int> .Insert(x, h)); Assert.AreEqual(1, LeftistHeap <int> .FindMin(heap)); }
public void DumpTreeTest() { var heap = new[] { 3, 2, 5, 1 }.Aggregate(LeftistHeap <int> .Empty, (h, x) => LeftistHeap <int> .Insert(x, h)); Assert.AreEqual("3, 2, 5, 1, ", DumpHeap(heap)); }