public void BinomialMinHeap_Test() { int nodeCount = 1000 * 10; //insert test var tree = new BinomialMinHeap <int>(); for (int i = 0; i <= nodeCount; i++) { tree.Insert(i); } for (int i = 0; i <= nodeCount; i++) { tree.DecrementKey(i, i - 1); } int min = 0; for (int i = 0; i <= nodeCount; i++) { min = tree.ExtractMin(); Assert.AreEqual(min, i - 1); } //IEnumerable tests. Assert.AreEqual(tree.Count, tree.Count()); var rnd = new Random(); var testSeries = Enumerable.Range(0, nodeCount - 1).OrderBy(x => rnd.Next()).ToList(); foreach (var item in testSeries) { tree.Insert(item); } for (int i = 0; i < testSeries.Count; i++) { var decremented = testSeries[i] - rnd.Next(0, 1000); tree.DecrementKey(testSeries[i], decremented); testSeries[i] = decremented; } testSeries.Sort(); for (int i = 0; i < nodeCount - 2; i++) { min = tree.ExtractMin(); Assert.AreEqual(testSeries[i], min); } //IEnumerable tests. Assert.AreEqual(tree.Count, tree.Count()); }
public static void DoTest() { int i = 37; int numberOfItems = 100000; BinomialMinHeap<int> firstHeap = new BinomialMinHeap<int>(); BinomialMinHeap<int> secondHeap = new BinomialMinHeap<int>(); BinomialMinHeap<int> thirdHeap = new BinomialMinHeap<int>(); Console.WriteLine("Begin Test."); for (i = 37; i != 0; i = (i + 37) % numberOfItems) { if (i % 2 == 0) secondHeap.Add(i); else firstHeap.Add(i); } firstHeap.Merge(secondHeap); thirdHeap = firstHeap; for (i = 1; i <= thirdHeap.Count(); i++) { var min = thirdHeap.ExtractMin(); Debug.Assert(min == i, "WRONG MIN"); } Debug.Assert(secondHeap.IsEmpty(), "SECOND HEAP SHOULD BE EMPTY"); Console.WriteLine("END OF TEST"); Console.ReadLine(); }
public static void DoTest() { int i = 37; int numberOfItems = 100000; BinomialMinHeap <int> firstHeap = new BinomialMinHeap <int>(); BinomialMinHeap <int> secondHeap = new BinomialMinHeap <int>(); BinomialMinHeap <int> thirdHeap = new BinomialMinHeap <int>(); Console.WriteLine("Begin Test."); for (i = 37; i != 0; i = (i + 37) % numberOfItems) { if (i % 2 == 0) { secondHeap.Add(i); } else { firstHeap.Add(i); } } firstHeap.Merge(secondHeap); thirdHeap = firstHeap; for (i = 1; i <= thirdHeap.Count(); i++) { var min = thirdHeap.ExtractMin(); Debug.Assert(min == i, "WRONG MIN"); } Debug.Assert(secondHeap.IsEmpty(), "SECOND HEAP SHOULD BE EMPTY"); Console.WriteLine("END OF TEST"); Console.ReadLine(); }