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