public void DeleteLotsOfMinsTest() { const int size = 1000; var random = new Random(3456); var heap = ParingHeap <int> .Empty; for (var i = 0; i < size; i++) { heap = ParingHeap <int> .Insert(random.Next(size), heap); } var last = 0; var count = 0; while (!ParingHeap <int> .IsEmpty(heap)) { var next = ParingHeap <int> .FindMin(heap); heap = ParingHeap <int> .DeleteMin(heap); Assert.IsTrue(last <= next); last = next; count++; } Assert.AreEqual(size, count); }
public void InsertTest3() { var heap1 = Enumerable.Range(0, 3).Aggregate(ParingHeap <int> .Empty, (current, i) => ParingHeap <int> .Insert(i, current)); var heap = ParingHeap <int> .Insert(3, heap1); Assert.AreEqual("[0: [3][2][1]]", DumpHeap(heap)); }
public void InsertTest1() { var empty = ParingHeap <int> .Empty; var heap = ParingHeap <int> .Insert(0, empty); Assert.AreEqual("[0]", DumpHeap(heap)); }
public void EmptyTest() { var empty = ParingHeap <int> .Empty; Assert.IsTrue(ParingHeap <int> .IsEmpty(empty)); var heap = ParingHeap <int> .Insert(3, empty); Assert.IsFalse(ParingHeap <int> .IsEmpty(heap)); }
public void MergeTest3() { var heap1 = Enumerable.Range(0, 4).Aggregate(ParingHeap <int> .Empty, (current, i) => ParingHeap <int> .Insert(i, current)); var heap2 = Enumerable.Range(10, 3).Aggregate(ParingHeap <int> .Empty, (current, i) => ParingHeap <int> .Insert(i, current)); var heap = ParingHeap <int> .Merge(heap1, heap2); Assert.AreEqual("[0: [10: [12][11]][3][2][1]]", DumpHeap(heap)); }
public void MergeTest2() { var empty = ParingHeap <int> .Empty; var heap2 = Enumerable.Range(0, 8).Aggregate(ParingHeap <int> .Empty, (current, i) => ParingHeap <int> .Insert(i, current)); var heap = ParingHeap <int> .Merge(empty, heap2); Assert.AreSame(heap2, heap); }
public void DeleteMinTest() { var heap = Enumerable.Range(0, 8).Aggregate(ParingHeap <int> .Empty, (current, i) => ParingHeap <int> .Insert(i, current)); heap = ParingHeap <int> .DeleteMin(heap); Assert.AreEqual("[1: [6: [7]][4: [5]][2: [3]]]", DumpHeap(heap)); }
public void FindMinTest() { var heap = Enumerable.Range(0, 8).Aggregate(ParingHeap <int> .Empty, (current, i) => ParingHeap <int> .Insert(i, current)); var min = ParingHeap <int> .FindMin(heap); Assert.AreEqual(0, min); }