public void b000_TreePathGetSizeTest() { { TreePath treePath = new TreePath(); Assert.AreEqual(0, treePath.GetSize()); } { TreePathNode node = new TreePathNode(Vector3.zero); TreePath treePath = new TreePath(node); Assert.AreEqual(1, treePath.GetSize()); } { TreePathNode node = new TreePathNode(Vector3.zero); node.AddChild(new TreePathNode(Vector3.one)); node.AddChild(new TreePathNode(Vector3.right)); TreePath treePath = new TreePath(node); Assert.AreEqual(3, treePath.GetSize()); } { TreePathNode node = new TreePathNode(Vector3.zero); node.AddChild(new TreePathNode(Vector3.one)); node.AddChild(new TreePathNode(Vector3.right)); node.AddChild(new TreePathNode(Vector3.left)); node.AddChild(new TreePathNode(Vector3.up)); TreePath treePath = new TreePath(node); Assert.AreEqual(5, treePath.GetSize()); } { TreePathNode node = new TreePathNode(Vector3.zero); node.AddChild(new TreePathNode(Vector3.one)); node.AddChild(new TreePathNode(Vector3.right)); node.AddChild(new TreePathNode(Vector3.left)); TreePathNode l1 = new TreePathNode(Vector3.down); l1.AddChild(new TreePathNode(Vector3.up)); l1.AddChild(new TreePathNode(Vector3.forward)); TreePathNode l2 = new TreePathNode(Vector3.back); l2.AddChild(new TreePathNode(Vector3.left)); l1.AddChild(l2); node.AddChild(l1); TreePath treePath = new TreePath(node); Assert.AreEqual(9, treePath.GetSize()); treePath.ResetRoot(node); Assert.AreEqual(9, treePath.GetSize()); treePath.Clear(); Assert.AreEqual(0, treePath.GetSize()); } }
public void b000_BuildTreeTest() { Wire[] wires = PrepareWireArray(8); wires[0].transform.position = new Vector3(0.5f, 0, 1); wires[0]._direction = Wire.Direction.XZ_X; wires[1].transform.position = new Vector3(1.5f, 0, 1); wires[1]._direction = Wire.Direction.XZ_X; wires[2].transform.position = new Vector3(2.5f, 0, 1); wires[2]._direction = Wire.Direction.XZ_X; wires[3].transform.position = new Vector3(5.5f, 0, 5); wires[3]._direction = Wire.Direction.XZ_X; wires[4].transform.position = new Vector3(5, 0, 5.5f); wires[4]._direction = Wire.Direction.XZ_Z; wires[5].transform.position = new Vector3(5, 0, 6.5f); wires[5]._direction = Wire.Direction.XZ_Z; wires[6].transform.position = new Vector3(4.5f, 0, 6); wires[6]._direction = Wire.Direction.XZ_X; wires[7].transform.position = new Vector3(5.5f, 0, 6); wires[7]._direction = Wire.Direction.XZ_X; GraphPath graphPath = GraphPath.Build(wires); // 7 // | // 8-6-9 // | // 0-1-2-3, 4-5 { int[] correctResult = new int[] { 2, 1, 0, 3 }; TreePath tree = graphPath.BuildTree(graphPath.GetNodeById(2)); Assert.AreEqual(4, tree.GetSize()); int cursor = 0; tree.DepthFirstTraversal((TreePathNode node) => { Assert.AreEqual(correctResult[cursor++], node._id); }); } { int[] correctResult = new int[] { 4, 5, 6, 7, 8, 9 }; TreePath tree = graphPath.BuildTree(graphPath.GetNodeById(4)); int cursor = 0; tree.DepthFirstTraversal((TreePathNode node) => { Assert.AreEqual(correctResult[cursor++], node._id); }); } { int[] correctResult = new int[] { 4, 5, 6, 7, 8, 9 }; TreePath tree = graphPath.BuildTree(graphPath.GetNodeById(4)); int cursor = 0; tree.BreadthFirstTraversal((TreePathNode node) => { Assert.AreEqual(correctResult[cursor++], node._id); }); } { int[] correctResult = new int[] { 5, 4, 6, 7, 8, 9 }; TreePath tree = graphPath.BuildTree(graphPath.GetNodeById(5)); int cursor = 0; tree.DepthFirstTraversal((TreePathNode node) => { Assert.AreEqual(correctResult[cursor++], node._id); }); } { int[] correctResult = new int[] { 5, 4, 6, 7, 8, 9 }; TreePath tree = graphPath.BuildTree(graphPath.GetNodeById(5)); int cursor = 0; tree.BreadthFirstTraversal((TreePathNode node) => { Assert.AreEqual(correctResult[cursor++], node._id); }); } { int[] correctResult = new int[] { 6, 4, 5, 7, 8, 9 }; TreePath tree = graphPath.BuildTree(graphPath.GetNodeById(6)); int cursor = 0; tree.DepthFirstTraversal((TreePathNode node) => { Assert.AreEqual(correctResult[cursor++], node._id); }); } { int[] correctResult = new int[] { 6, 4, 7, 8, 9, 5 }; TreePath tree = graphPath.BuildTree(graphPath.GetNodeById(6)); int cursor = 0; tree.BreadthFirstTraversal((TreePathNode node) => { Assert.AreEqual(correctResult[cursor++], node._id); }); } { int[] correctResult = new int[] { 7, 6, 4, 5, 8, 9 }; TreePath tree = graphPath.BuildTree(graphPath.GetNodeById(7)); int cursor = 0; tree.DepthFirstTraversal((TreePathNode node) => { Assert.AreEqual(correctResult[cursor++], node._id); }); } { int[] correctResult = new int[] { 7, 6, 4, 8, 9, 5 }; TreePath tree = graphPath.BuildTree(graphPath.GetNodeById(7)); int cursor = 0; tree.BreadthFirstTraversal((TreePathNode node) => { Assert.AreEqual(correctResult[cursor++], node._id); }); } { int[] correctResult = new int[] { 8, 6, 4, 5, 7, 9 }; TreePath tree = graphPath.BuildTree(graphPath.GetNodeById(8)); int cursor = 0; tree.DepthFirstTraversal((TreePathNode node) => { Assert.AreEqual(correctResult[cursor++], node._id); }); } { int[] correctResult = new int[] { 8, 6, 4, 7, 9, 5 }; TreePath tree = graphPath.BuildTree(graphPath.GetNodeById(8)); int cursor = 0; tree.BreadthFirstTraversal((TreePathNode node) => { Assert.AreEqual(correctResult[cursor++], node._id); }); } { int[] correctResult = new int[] { 9, 6, 4, 5, 7, 8 }; TreePath tree = graphPath.BuildTree(graphPath.GetNodeById(9)); int cursor = 0; tree.DepthFirstTraversal((TreePathNode node) => { Assert.AreEqual(correctResult[cursor++], node._id); }); } { int[] correctResult = new int[] { 9, 6, 4, 7, 8, 5 }; TreePath tree = graphPath.BuildTree(graphPath.GetNodeById(9)); Assert.AreEqual(6, tree.GetSize()); int cursor = 0; tree.BreadthFirstTraversal((TreePathNode node) => { Assert.AreEqual(correctResult[cursor++], node._id); }); } }