public void Insert_ParentSiblingIsRed() { redBlackTree.Insert(4); RedBlackTreeRule.CheckRedBlackTreeRules(redBlackTree); Assert.Equal(9, redBlackTree.Count); Assert.Equal(7, redBlackTree.Root.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.Color); Assert.Equal(3, redBlackTree.Root.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.LeftChild.Color); Assert.Equal(1, redBlackTree.Root.LeftChild.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.LeftChild.LeftChild.Color); Assert.Equal(5, redBlackTree.Root.LeftChild.RightChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.LeftChild.RightChild.Color); Assert.Equal(4, redBlackTree.Root.LeftChild.RightChild.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.LeftChild.RightChild.LeftChild.Color); Assert.Equal(11, redBlackTree.Root.RightChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.RightChild.Color); Assert.Equal(8, redBlackTree.Root.RightChild.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.RightChild.LeftChild.Color); Assert.Equal(13, redBlackTree.Root.RightChild.RightChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.RightChild.RightChild.Color); Assert.Equal(15, redBlackTree.Root.RightChild.RightChild.RightChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.RightChild.RightChild.RightChild.Color); }
public void Remove_NodeWithoutChildren() { redBlackTree.Remove(8); RedBlackTreeRule.CheckRedBlackTreeRules(redBlackTree); Assert.Equal(7, redBlackTree.Count); Assert.Equal(11, redBlackTree.Root.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.Color); Assert.Equal(3, redBlackTree.Root.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.LeftChild.Color); Assert.Equal(1, redBlackTree.Root.LeftChild.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.LeftChild.LeftChild.Color); Assert.Equal(7, redBlackTree.Root.LeftChild.RightChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.LeftChild.RightChild.Color); Assert.Equal(5, redBlackTree.Root.LeftChild.RightChild.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.LeftChild.RightChild.LeftChild.Color); Assert.Null(redBlackTree.Root.LeftChild.RightChild.RightChild); Assert.Equal(13, redBlackTree.Root.RightChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.RightChild.Color); Assert.Equal(15, redBlackTree.Root.RightChild.RightChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.RightChild.RightChild.Color); }
public void Remove_CurrentRoot() { redBlackTree.Remove(11); RedBlackTreeRule.CheckRedBlackTreeRules(redBlackTree); Assert.Equal(7, redBlackTree.Count); Assert.Equal(13, redBlackTree.Root.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.Color); Assert.Equal(3, redBlackTree.Root.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.LeftChild.Color); Assert.Equal(1, redBlackTree.Root.LeftChild.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.LeftChild.LeftChild.Color); Assert.Equal(7, redBlackTree.Root.LeftChild.RightChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.LeftChild.RightChild.Color); Assert.Equal(5, redBlackTree.Root.LeftChild.RightChild.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.LeftChild.RightChild.LeftChild.Color); Assert.Equal(8, redBlackTree.Root.LeftChild.RightChild.RightChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.LeftChild.RightChild.RightChild.Color); Assert.Equal(15, redBlackTree.Root.RightChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.RightChild.Color); }
public void Insert_CheckCorrectConstructionOfInputTree() { RedBlackTreeRule.CheckRedBlackTreeRules(redBlackTree); Assert.Equal(8, redBlackTree.Count); Assert.Equal(11, redBlackTree.Root.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.Color); Assert.Equal(3, redBlackTree.Root.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.LeftChild.Color); Assert.Equal(1, redBlackTree.Root.LeftChild.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.LeftChild.LeftChild.Color); Assert.Equal(7, redBlackTree.Root.LeftChild.RightChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.LeftChild.RightChild.Color); Assert.Equal(5, redBlackTree.Root.LeftChild.RightChild.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.LeftChild.RightChild.LeftChild.Color); Assert.Equal(8, redBlackTree.Root.LeftChild.RightChild.RightChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.LeftChild.RightChild.RightChild.Color); Assert.Equal(13, redBlackTree.Root.RightChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.RightChild.Color); Assert.Equal(15, redBlackTree.Root.RightChild.RightChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.RightChild.RightChild.Color); }
public void Remove_SiblingIsBlackAndRightChildIsRed() { redBlackTree.Remove(7); RedBlackTreeRule.CheckRedBlackTreeRules(redBlackTree); Assert.Equal(7, redBlackTree.Count); Assert.Equal(11, redBlackTree.Root.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.Color); Assert.Equal(3, redBlackTree.Root.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.LeftChild.Color); Assert.Equal(1, redBlackTree.Root.LeftChild.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.LeftChild.LeftChild.Color); Assert.Equal(8, redBlackTree.Root.LeftChild.RightChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.LeftChild.RightChild.Color); Assert.Equal(5, redBlackTree.Root.LeftChild.RightChild.LeftChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.LeftChild.RightChild.LeftChild.Color); Assert.Equal(13, redBlackTree.Root.RightChild.Value); Assert.Equal(RedBlackTreeColors.Black, redBlackTree.Root.RightChild.Color); Assert.Equal(15, redBlackTree.Root.RightChild.RightChild.Value); Assert.Equal(RedBlackTreeColors.Red, redBlackTree.Root.RightChild.RightChild.Color); }