public void TestRemoveInRightSubtree() { var tree = new AvlTree <TestNode> (); int[] keys = { 8, 4, 13, 6, 15, 7, 10, 5, 14, 2, 11, 3, 9, 1 }; foreach (var key in keys) { tree.Add(new TestNode(key)); } tree.Remove(tree.First(t => t.val == 13)); Assert.AreEqual(11, ((TestNode)tree.First(t => t.val == 8).Right).val); }
public void TestDetachNodesAtLeftChildAfterDeletingRoot() { var tree = new AvlTree <TestNode> (); int[] keys = { 110, 122, 2, 134, 86, 14, 26, 182 }; foreach (var key in keys) { tree.Add(new TestNode(key)); } tree.Remove(tree.First(t => t.val == 110)); Assert.AreEqual(26, ((TestNode)tree.First(t => t.val == 14).Right).val); }
public void TestRemoveInLeftSubtree() { var tree = new AvlTree <TestNode> (); int[] keys = { 8, 4, 12, 6, 7, 16, 10, 5, 11, 9, 17, 5, 14, 2, 13, 1, 3 }; foreach (var key in keys) { tree.Add(new TestNode(key)); } tree.Remove(tree.First(t => t.val == 16)); Assert.AreEqual(8, tree.Root.val); Assert.AreEqual(12, ((TestNode)tree.Root.Right).val); Assert.AreEqual(14, ((TestNode)tree.Root.Right.Right).val); Assert.AreEqual(13, ((TestNode)tree.First(t => t.val == 14).Left).val); }
public void TestTreeRoationAtLeftChildAfterDeletingRoot() { var tree = new AvlTree <TestNode> (); int[] keys = { 86, 110, 122, 2, 134, 26, 14, 182 }; int[] expectedKeys = { 2, 14, 26, 86, 122, 134, 182 }; foreach (var key in keys) { tree.Add(new TestNode(key)); } tree.Remove(tree.First(t => t.val == 110)); var node = tree.Root.AvlGetOuterLeft(); foreach (var expected in expectedKeys) { Assert.AreEqual(expected, node.val); node = node.AvlGetNextNode(); } }
public void TestTreeRoationAtLeftChildAfterDeletingRoot() { var tree = new AvlTree<TestNode> (); int[] keys = { 86, 110, 122, 2, 134, 26, 14, 182 }; int[] expectedKeys = { 2, 14, 26, 86, 122, 134, 182 }; foreach (var key in keys) { tree.Add (new TestNode (key)); } tree.Remove (tree.First (t => t.val == 110)); var node = tree.Root.AvlGetOuterLeft (); foreach (var expected in expectedKeys) { Assert.AreEqual (expected, node.val); node = node.AvlGetNextNode (); } }
public void TestRemoveInRightSubtree() { var tree = new AvlTree<TestNode> (); int[] keys = { 8, 4, 13, 6, 15, 7, 10, 5, 14, 2, 11, 3, 9, 1 }; foreach (var key in keys) { tree.Add (new TestNode (key)); } tree.Remove (tree.First (t => t.val == 13)); Assert.AreEqual (11, ((TestNode)tree.First (t => t.val == 8).Right).val); }
public void TestRemoveInLeftSubtree() { var tree = new AvlTree<TestNode> (); int[] keys = { 8, 4, 12, 6, 7, 16, 10, 5, 11, 9, 17, 5, 14, 2, 13, 1, 3 }; foreach (var key in keys) { tree.Add (new TestNode (key)); } tree.Remove (tree.First (t => t.val == 16)); Assert.AreEqual( 8, tree.Root.val ); Assert.AreEqual( 12, ((TestNode)tree.Root.Right).val ); Assert.AreEqual( 14, ((TestNode)tree.Root.Right.Right).val ); Assert.AreEqual (13, ((TestNode)tree.First (t => t.val == 14).Left).val); }
public void TestDetachNodesAtLeftChildAfterDeletingRoot() { var tree = new AvlTree<TestNode> (); int[] keys = { 110, 122, 2, 134, 86, 14, 26, 182 }; foreach (var key in keys) { tree.Add (new TestNode (key)); } tree.Remove (tree.First (t => t.val == 110)); Assert.AreEqual (26, ((TestNode)tree.First (t => t.val == 14).Right).val); }