public void DeleteLotsOfMinsTest() { const int size = 1000; var random = new Random(3456); var heap = ScheduledBinomialHeap <int> .Empty; for (var i = 0; i < size; i++) { heap = ScheduledBinomialHeap <int> .Insert(random.Next(size), heap); } var last = 0; var count = 0; while (!ScheduledBinomialHeap <int> .IsEmpty(heap)) { var next = ScheduledBinomialHeap <int> .FindMin(heap); heap = ScheduledBinomialHeap <int> .DeleteMin(heap); Assert.IsTrue(last <= next); last = next; count++; } Assert.AreEqual(size, count); }
public void DeleteMinTest() { var t = ScheduledBinomialHeap <int> .Empty; var t1 = ScheduledBinomialHeap <int> .Insert(5, t); var t2 = ScheduledBinomialHeap <int> .Insert(3, t1); var t3 = ScheduledBinomialHeap <int> .Insert(6, t2); var t4 = ScheduledBinomialHeap <int> .DeleteMin(t3); Assert.AreEqual("[[5: [6]]]", DumpHeap(t4)); Assert.AreEqual(5, ScheduledBinomialHeap <int> .FindMin(t4)); Assert.AreEqual(3, ScheduledBinomialHeap <int> .FindMin(t3)); }
public void DeleteLotsOfMinsTest2() { const int size = 1000; var random = new Random(6435); var heap = ScheduledBinomialHeap <int> .Empty; var min = size; for (var i = 0; i < size; i++) { var j = random.Next(size); min = Math.Min(j, min); heap = ScheduledBinomialHeap <int> .Insert(j, heap); j = random.Next(size); min = Math.Min(j, min); heap = ScheduledBinomialHeap <int> .Insert(j, heap); var k = ScheduledBinomialHeap <int> .FindMin(heap); heap = ScheduledBinomialHeap <int> .DeleteMin(heap); Assert.IsTrue(min <= k); min = k; } for (var i = 0; i < size; i++) { var j = ScheduledBinomialHeap <int> .FindMin(heap); heap = ScheduledBinomialHeap <int> .DeleteMin(heap); Assert.IsTrue(min <= j); min = j; } Assert.IsTrue(ScheduledBinomialHeap <int> .IsEmpty(heap)); }