public void a060_BreadthFirstTraversalTest() { 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 List <GraphPathNode> path = graphPath.BreadthFirstTraversal(graphPath.GetNodeById(0)); Assert.AreEqual(4, path.Count); Assert.AreEqual(0, path[0]._id); Assert.AreEqual(1, path[1]._id); Assert.AreEqual(2, path[2]._id); Assert.AreEqual(3, path[3]._id); List <GraphPathNode> path2 = graphPath.BreadthFirstTraversal(graphPath.GetNodeById(4)); Assert.AreEqual(6, path2.Count); Assert.AreEqual(4, path2[0]._id); Assert.AreEqual(5, path2[1]._id); Assert.AreEqual(6, path2[2]._id); Assert.AreEqual(7, path2[3]._id); Assert.AreEqual(8, path2[4]._id); Assert.AreEqual(9, path2[5]._id); }
public void a030_GetNodeByIdTest() { 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 Assert.AreEqual(0, graphPath.GetNodeById(0)._id); Assert.AreEqual(1, graphPath.GetNodeById(1)._id); Assert.AreEqual(2, graphPath.GetNodeById(2)._id); Assert.AreEqual(3, graphPath.GetNodeById(3)._id); Assert.AreEqual(4, graphPath.GetNodeById(4)._id); Assert.AreEqual(5, graphPath.GetNodeById(5)._id); Assert.AreEqual(6, graphPath.GetNodeById(6)._id); Assert.AreEqual(7, graphPath.GetNodeById(7)._id); Assert.AreEqual(8, graphPath.GetNodeById(8)._id); Assert.AreEqual(9, graphPath.GetNodeById(9)._id); }
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); }); } }
public void a050_IsDirectConnectedTest() { 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 Assert.True(graphPath.IsDirectConnected(graphPath.GetNodeById(0), graphPath.GetNodeById(1))); Assert.True(graphPath.IsDirectConnected(graphPath.GetNodeById(1), graphPath.GetNodeById(2))); Assert.True(graphPath.IsDirectConnected(graphPath.GetNodeById(2), graphPath.GetNodeById(3))); Assert.False(graphPath.IsDirectConnected(graphPath.GetNodeById(3), graphPath.GetNodeById(4))); Assert.True(graphPath.IsDirectConnected(graphPath.GetNodeById(4), graphPath.GetNodeById(5))); Assert.False(graphPath.IsDirectConnected(graphPath.GetNodeById(5), graphPath.GetNodeById(6))); Assert.True(graphPath.IsDirectConnected(graphPath.GetNodeById(6), graphPath.GetNodeById(7))); Assert.True(graphPath.IsDirectConnected(graphPath.GetNodeById(6), graphPath.GetNodeById(8))); Assert.True(graphPath.IsDirectConnected(graphPath.GetNodeById(6), graphPath.GetNodeById(9))); Assert.False(graphPath.IsDirectConnected(graphPath.GetNodeById(6), graphPath.GetNodeById(5))); Assert.False(graphPath.IsDirectConnected(graphPath.GetNodeById(6), graphPath.GetNodeById(1))); Assert.False(graphPath.IsDirectConnected(graphPath.GetNodeById(7), graphPath.GetNodeById(8))); Assert.False(graphPath.IsDirectConnected(graphPath.GetNodeById(8), graphPath.GetNodeById(9))); Assert.False(graphPath.IsDirectConnected(graphPath.GetNodeById(8), graphPath.GetNodeById(8))); }