public void TransformNull() { var transformer = new NodeTransformer(); var describer = NodeDescriberFactory.GetDescriber(); var node1 = transformer.Transform(null); Assert.AreEqual("", describer.Describe(node1)); }
public void TransformNoChildrenTest() { var transformer = new NodeTransformer(); var describer = NodeDescriberFactory.GetDescriber(); var node1 = transformer.Transform( new ManyChildrenNode("node1") ); Assert.AreEqual("new NoChildrenNode(\"node1\")", describer.Describe(node1)); }
public void Transform_Given_ManyChildrenNode_And_NoChildren_Returns_NoChildrenNode() { //arrange var expected = new NoChildrenNode("root"); var testInput = new ManyChildrenNode("root"); //act var transformer = new NodeTransformer(); var actual = transformer.Transform(testInput); //assert Assert.AreEqual(expected, actual); }
public void TransformSingleChildTest() { var transformer = new NodeTransformer(); var describer = NodeDescriberFactory.GetDescriber(); var node1 = transformer.Transform( new ManyChildrenNode("node1", new Node[] { new ManyChildrenNode("node2") }) ); Assert.AreEqual("new SingleChildNode(\"node1\",\n new NoChildrenNode(\"node2\"))", describer.Describe(node1)); }
public void Transform_Given_SingleChildNode_Returns_SameNode() { //arrange var expected = new SingleChildNode("root", new NoChildrenNode("leaf")); var testInput = new SingleChildNode("root", new NoChildrenNode("leaf")); //act var transformer = new NodeTransformer(); var actual = transformer.Transform(testInput); //assert Assert.AreEqual(expected, actual); }
public void Transform_Given_ManyChildrenNode_And_ManyChildren_Returns_DerivedNodes() { //arrange var expected = new SingleChildNode("root", new TwoChildrenNode("child1", new NoChildrenNode("leaf1"), new SingleChildNode("child2", new NoChildrenNode("leaf2")))); var testInput = new ManyChildrenNode("root", new ManyChildrenNode("child1", new ManyChildrenNode("leaf1"), new ManyChildrenNode("child2", new ManyChildrenNode("leaf2")))); //act var transformer = new NodeTransformer(); var actual = transformer.Transform(testInput); //assert Assert.AreEqual(expected, actual); }
public void TransformTreeTest() { var transformer = new NodeTransformer(); var describer = NodeDescriberFactory.GetDescriber(); var node1 = transformer.Transform( new ManyChildrenNode("root", new ManyChildrenNode("child1", new ManyChildrenNode("leaf1"), new ManyChildrenNode("child2", new ManyChildrenNode("leaf2")))) ); Assert.AreEqual( "new SingleChildNode(\"root\",\n" + " new TwoChildrenNode(\"child1\",\n" + " new NoChildrenNode(\"leaf1\"),\n" + " new SingleChildNode(\"child2\",\n" + " new NoChildrenNode(\"leaf2\"))))", describer.Describe(node1) ); }
public void NodeTransformerTest() { // Traverse tree, of many ManyChildrenNode INodeTransformer implementation = new NodeTransformer(new NodesHelper()); var testData = new ManyChildrenNode("root", new ManyChildrenNode("child1", new ManyChildrenNode("leaf1"), new ManyChildrenNode("child2", new ManyChildrenNode("leaf2")))); var result = implementation.Transform(testData); var root = result; Assert.IsInstanceOfType(root, typeof(SingleChildNode)); Assert.AreEqual("root", root.Name); var child1 = ((SingleChildNode)root).Child; Assert.IsInstanceOfType(child1, typeof(TwoChildrenNode)); Assert.AreEqual("child1", child1.Name); var leaf1 = ((TwoChildrenNode)child1).FirstChild; Assert.IsInstanceOfType(leaf1, typeof(NoChildrenNode)); Assert.AreEqual("leaf1", leaf1.Name); var child2 = ((TwoChildrenNode)child1).SecondChild; Assert.IsInstanceOfType(child2, typeof(SingleChildNode)); Assert.AreEqual("child2", child2.Name); var leaf2 = ((SingleChildNode)child2).Child; Assert.IsInstanceOfType(leaf2, typeof(NoChildrenNode)); Assert.AreEqual("leaf2", leaf2.Name); // Traverse tree, of various types of nodes implementation = new NodeTransformer(new NodesHelper()); testData = new ManyChildrenNode("root", new TwoChildrenNode("child1", new ManyChildrenNode("leaf1"), new SingleChildNode("child2", new NoChildrenNode("leaf2")))); result = implementation.Transform(testData); root = result; Assert.IsInstanceOfType(root, typeof(SingleChildNode)); Assert.AreEqual("root", root.Name); child1 = ((SingleChildNode)root).Child; Assert.IsInstanceOfType(child1, typeof(TwoChildrenNode)); Assert.AreEqual("child1", child1.Name); leaf1 = ((TwoChildrenNode)child1).FirstChild; Assert.IsInstanceOfType(leaf1, typeof(NoChildrenNode)); Assert.AreEqual("leaf1", leaf1.Name); child2 = ((TwoChildrenNode)child1).SecondChild; Assert.IsInstanceOfType(child2, typeof(SingleChildNode)); Assert.AreEqual("child2", child2.Name); leaf2 = ((SingleChildNode)child2).Child; Assert.IsInstanceOfType(leaf2, typeof(NoChildrenNode)); Assert.AreEqual("leaf2", leaf2.Name); // Traverse tree, of various types of nodes, removing null nodes implementation = new NodeTransformer(new NodesHelper()); testData = new ManyChildrenNode("root", new TwoChildrenNode("child1", null, new SingleChildNode("leaf1", null))); result = implementation.Transform(testData); root = result; Assert.IsInstanceOfType(root, typeof(SingleChildNode)); Assert.AreEqual("root", root.Name); child1 = ((SingleChildNode)root).Child; Assert.IsInstanceOfType(child1, typeof(SingleChildNode)); Assert.AreEqual("child1", child1.Name); leaf1 = ((SingleChildNode)child1).Child; Assert.IsInstanceOfType(leaf1, typeof(NoChildrenNode)); Assert.AreEqual("leaf1", leaf1.Name); }