public void Describe_Given_NoChildrenNode_Returns_NoChildrenNodeDescription() { //arrange var expected = "new NoChildrenNode(\"root\")"; var testInput = new NoChildrenNode("root"); //act var actual = _nodeDescriber.Describe(testInput); //assert Assert.AreEqual(expected, actual); }
public void NodeDescriberTest() { // Traverse down and across tree INodeDescriber implementation = new NodeDescriber(new NodesHelper()); var testData = new SingleChildNode("root", new TwoChildrenNode("child1", new NoChildrenNode("leaf1"), new SingleChildNode("child2", new NoChildrenNode("leaf2")))); var result = implementation.Describe(testData); StringBuilder sb = new StringBuilder(); sb.Append("new SingleChildNode(\"root\","); sb.Append(Environment.NewLine); sb.Append(tab); sb.Append("new TwoChildrenNode(\"child1\","); sb.Append(Environment.NewLine); sb.Append(tab); sb.Append(tab); sb.Append("new NoChildrenNode(\"leaf1\"),"); sb.Append(Environment.NewLine); sb.Append(tab); sb.Append(tab); sb.Append("new SingleChildNode(\"child2\","); sb.Append(Environment.NewLine); sb.Append(tab); sb.Append(tab); sb.Append(tab); sb.Append("new NoChildrenNode(\"leaf2\"))));"); string expectedResult = sb.ToString(); Assert.AreEqual(expectedResult, result); // Traverse down tree, back up, then back down implementation = new NodeDescriber(new NodesHelper()); testData = new SingleChildNode("root", new ManyChildrenNode("child1", new SingleChildNode("child2", new NoChildrenNode("leaf1")), new NoChildrenNode("leaf2"))); result = implementation.Describe(testData); sb = new StringBuilder(); sb.Append("new SingleChildNode(\"root\","); sb.Append(Environment.NewLine); sb.Append(tab); sb.Append("new ManyChildrenNode(\"child1\","); sb.Append(Environment.NewLine); sb.Append(tab); sb.Append(tab); sb.Append("new SingleChildNode(\"child2\","); sb.Append(Environment.NewLine); sb.Append(tab); sb.Append(tab); sb.Append(tab); sb.Append("new NoChildrenNode(\"leaf1\")),"); sb.Append(Environment.NewLine); sb.Append(tab); sb.Append(tab); sb.Append("new NoChildrenNode(\"leaf2\")));"); expectedResult = sb.ToString(); Assert.AreEqual(expectedResult, result); // Traverse tree, removing null nodes implementation = new NodeDescriber(new NodesHelper()); var testDataWithNulls = new ManyChildrenNode("root", new TwoChildrenNode("child1", null, new SingleChildNode("leaf1", null))); result = implementation.Describe(testDataWithNulls); sb = new StringBuilder(); sb.Append("new ManyChildrenNode(\"root\","); sb.Append(Environment.NewLine); sb.Append(tab); sb.Append("new TwoChildrenNode(\"child1\","); sb.Append(Environment.NewLine); sb.Append(tab); sb.Append(tab); sb.Append("new SingleChildNode(\"leaf1\")));"); expectedResult = sb.ToString(); Assert.AreEqual(expectedResult, result); }