public void BinaryTreeMergeTime_1000_Test() { var list = new List <int>(); var firstTree = new AVLBinaryTree <int>(); for (var i = 0; i < 500; i++) { firstTree.Add(i); list.Add(i); } var secondTree = new AVLBinaryTree <int>(); for (var i = 500; i < 1000; i++) { firstTree.Add(i); list.Add(i); } firstTree.MergeWith(secondTree); CollectionAssert.AreEqual(list, firstTree.Inorder() .ToArray()); }
public void BinaryTreeMerge_random_Test() { var list = new List <int>(); var rnd = new Random(); var firstTree = new AVLBinaryTree <int>(); for (var i = 0; i < 500; i++) { var num = rnd.Next(-50, 50); firstTree.Add(num); list.Add(num); } var secondTree = new AVLBinaryTree <int>(); for (var i = 500; i < 1000; i++) { var num = rnd.Next(-50, 50); firstTree.Add(num); list.Add(num); } firstTree.MergeWith(secondTree); list = list.Distinct() .ToList(); list.Sort(); CollectionAssert.AreEqual(list, firstTree.Inorder() .ToArray()); }
public void BinaryTree_RemoveTest() { var tree = new AVLBinaryTree <int>(); for (var i = 0; i < 10; i++) { tree.Add(i); } tree.Remove(5); CollectionAssert.AreEqual(tree.Inorder() .ToArray(), new[] { 0, 1, 2, 3, 4, 6, 7, 8, 9 }); }
public void BinaryTree_AddTest() { var tree = new AVLBinaryTree <int>(); for (var i = 0; i < 10; i++) { tree.Add(i); } Assert.IsTrue(tree.Count == 10); var array = new int[10]; tree.CopyTo(array, 0); CollectionAssert.AreEqual(array, new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); }
public void BinaryTreeMergeTest() { var firstTree = new AVLBinaryTree <int>(); for (var i = 0; i < 10; i++) { firstTree.Add(i); } var secondTree = new AVLBinaryTree <int>(); for (var i = 10; i < 20; i++) { firstTree.Add(i); } firstTree.MergeWith(secondTree); var checkArray = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; CollectionAssert.AreEqual(checkArray, firstTree.Inorder() .ToArray()); }