public void GivenZillowExampleWhenInsertExpectMatchExample() { // arrange var tree = new TrinaryTree(5); // adding nodes to the tree in this order 5,4,9,5,7,2,2 // results in a tree that looks like this: // 5 // / | \ // 4 5 9 // / / // 2 7 // | // 2 // act foreach (int value in this.valuesToAdd) { tree.Insert(value); } // assert Assert.Equal(5, tree.RootNode.Data); Assert.Equal(4, tree.RootNode.Left.Data); Assert.Equal(2, tree.RootNode.Left.Left.Data); Assert.Equal(2, tree.RootNode.Left.Left.Middle.Data); Assert.Equal(5, tree.RootNode.Middle.Data); Assert.Equal(9, tree.RootNode.Right.Data); Assert.Equal(7, tree.RootNode.Right.Left.Data); }
public void GivenIdenticalNumbersWhenInsertExpectAllPutInMiddle() { // arrange var fixture = new Fixture(); var valueToAdd = fixture.Create <int>(); var dups = new[] { valueToAdd, valueToAdd, valueToAdd }; var tree = new TrinaryTree(); // act foreach (int value in dups) { tree.Insert(value); } // assert tree.RootNode.Data.Should().Be(dups[0]); tree.RootNode.AssertLeftIsNull().AssertRightIsNull(); tree.RootNode.Middle.Data.Should().Be(dups[0]); tree.RootNode.Middle.AssertLeftIsNull().AssertRightIsNull(); tree.RootNode.Middle.Middle.Data.Should().Be(dups[0]); AssertNoChildren(tree.RootNode.Middle.Middle); }