public void Test0() { var t = SkewBinomialHeap <string> .Empty; var x1 = SkewBinomialHeap <string> .Insert("C", t); Assert.AreEqual("[[C]]", DumpHeap(x1)); }
public void Test1() { var t = SkewBinomialHeap <string> .Empty; var x1 = SkewBinomialHeap <string> .Insert("C", t); var x2 = SkewBinomialHeap <string> .Insert("B", x1); Assert.AreEqual("[[B][C]]", DumpHeap(x2)); }
public void EmptyTest() { var t = SkewBinomialHeap <string> .Empty; Assert.IsTrue(SkewBinomialHeap <string> .IsEmpty(t)); var t1 = SkewBinomialHeap <string> .Insert("C", t); Assert.IsFalse(SkewBinomialHeap <string> .IsEmpty(t1)); }
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); }
public void MergeTest() { const string data1 = "What's in a name?"; var ts1 = data1.Split().Aggregate(SkewBinomialHeap <string> .Empty, (current, word) => SkewBinomialHeap <string> .Insert(word, current)); const string data2 = "That which we call a rose by any other name would smell as sweet"; var ts2 = data2.Split().Aggregate(SkewBinomialHeap <string> .Empty, (current, word) => SkewBinomialHeap <string> .Insert(word, current)); var t = SkewBinomialHeap <string> .Merge(ts1, ts2); Assert.AreEqual("[[name?][a, in[[What's]]][a, by, rose[[any, sweet, name[[as, smell[[would]]][other]]][That, we[[which]]][call]]]]", DumpHeap(t)); }
public void Test2() { const string words = "What's in a name? That which we call a rose by any other name would smell as sweet."; var t = words.Split().Aggregate(SkewBinomialHeap <string> .Empty, (current, word) => SkewBinomialHeap <string> .Insert(word, current)); Assert.AreEqual("[[as, sweet.[[smell]]][a, would, name, rose[[a, we, in[[name?, which[[That]]][What's]]][any, other[[by]]][call]]]]", DumpHeap(t)); }