public void TestBalancedness() { var perfect = new RedBlackSetTester<int>(); perfect.Add(4); perfect.Add(2); perfect.Add(1); perfect.Add(3); perfect.Add(6); perfect.Add(5); perfect.Add(7); Assert.That(perfect.MaxDepth(), Is.EqualTo(3)); }
public void TestDepthOfLinearInsertion() { const int up2 = 9999; var rbt = new RedBlackSetTester<int>(Enumerable.Range(1, 7)); double max = 0.0; for (int i = 8; i <= up2; ++i) { rbt.Add(i); double actual = rbt.MaxDepth(); double perfect = Math.Log(i, 2.0); double ratio = actual / perfect; max = Math.Max(max, ratio); } Assert.That(rbt.Count, Is.EqualTo(up2)); Assert.That(max, Is.LessThanOrEqualTo(2.0)); }
public void TestDepthWithRandomNumbers() { WithRandomNumbers(list => { if (list.Count <= 1) { return; } var rbt = new RedBlackSetTester<int>(list); var depth = rbt.MaxDepth(); var theory = Math.Log(list.Count, 2.0) * 2.0; Assert.That(depth, Is.LessThanOrEqualTo(theory), "The tree is not well balanced."); }, new int[] { 255, 256, 257, 9999, 99999 }); }