public void UnbalancedTreeShouldHaveFiveNeighbors() { // arrange var a = new Node { Label = "A" }; var b = new Node { Label = "B" }; var c = new Node { Label = "C" }; var d = new Node { Label = "D" }; var e = new Node { Label = "E" }; var f = new Node { Label = "F" }; var g = new Node { Label = "G" }; var h = new Node { Label = "H" }; var i = new Node { Label = "I" }; var btree = new BinaryTree(); /* a * b c * d e f * g h i */ a.Left = b; b.Left = d; d.Left = g; b.Right = e; a.Right = c; c.Right = f; f.Left = h; f.Right = i; // act btree.AddNeighborsToTree(a); var nodesWithNeighbors = btree.GetNodesWithNeighbors(a); // assert nodesWithNeighbors.ShouldNotBeEmpty(); nodesWithNeighbors.Count.ShouldBe(5); nodesWithNeighbors.ShouldContain(n => n.Label == "B"); nodesWithNeighbors.ShouldContain(n => n.Label == "D"); nodesWithNeighbors.ShouldContain(n => n.Label == "E"); nodesWithNeighbors.ShouldContain(n => n.Label == "G"); nodesWithNeighbors.ShouldContain(n => n.Label == "H"); b.Neighbor.Label.ShouldBe("C"); c.Neighbor.ShouldBe(null); d.Neighbor.Label.ShouldBe("E"); e.Neighbor.Label.ShouldBe("F"); g.Neighbor.Label.ShouldBe("H"); h.Neighbor.Label.ShouldBe("I"); }
public void Setup() { bt = new BinaryTree <int>(); }
public void EmptyTree() { var tree = new BinaryTree(null); Assert.IsTrue(tree.IsSearchTree()); }
public void EmptyTree() { var tree = new BinaryTree(null); Assert.IsEmpty(tree.Traverse()); }