예제 #1
0
 public void When_CheckExistingEdges_Expect_Found(NodeGraph nodeGraph)
 {
     for (int i = 1; i < nodeGraph.Nodes.Count; i++)
     {
         Assert.That(nodeGraph.AreLinked(0, i), "Count: " + nodeGraph.Nodes.Count);
         Assert.That(nodeGraph.AreLinked(i, 0), "Count: " + nodeGraph.Nodes.Count);
     }
 }
예제 #2
0
        public void When_AddNodeWithMultipleNeighbors_Expect_AllLinked(NodeGraph nodeGraph)
        {
            Node newNode = new Node(5, 5, 5);

            Node neighbor1 = nodeGraph.Nodes[0];
            Node neighbor2 = nodeGraph.Nodes[1];

            nodeGraph.AddNode(newNode, neighbor1, neighbor2);

            Assert.That(nodeGraph.AreLinked(newNode, neighbor1));
            Assert.That(nodeGraph.AreLinked(newNode, neighbor2));
        }
예제 #3
0
        public void When_RemoveEdgeByIndices_Expect_EdgeRemoved(NodeGraph nodeGraph)
        {
            Node edgeStart = nodeGraph.Nodes[0];
            Node edgeEnd   = nodeGraph.Nodes[1];

            nodeGraph.RemoveEdge(edgeStart.index, edgeEnd.index);

            Assert.That(!nodeGraph.AreLinked(edgeStart, edgeEnd));
        }
예제 #4
0
        public void When_RemoveEdge_Expect_EdgeRemoved(NodeGraph nodeGraph)
        {
            Edge edgeToRemove = nodeGraph.Edges[0];

            nodeGraph.RemoveEdge(edgeToRemove);

            Assert.That(!nodeGraph.Edges.Contains(edgeToRemove));
            Assert.That(!nodeGraph.AreLinked(nodeGraph.Nodes[0], nodeGraph.Nodes[1]));
        }
예제 #5
0
        public void When_AddNodeWithNeighborAndWidthByIndex_Expect_NodeAddedWithWidth()
        {
            NodeGraph nodeGraph = new NodeGraph();
            Node      node1     = new Node(new Vect3(1, 1, 1));
            Node      node2     = new Node(new Vect3(2, 2, 2));
            Node      node3     = new Node(new Vect3(3, 3, 3));

            nodeGraph.AddNode(node1);
            nodeGraph.AddNode(node2, (0, 5.5));
            nodeGraph.AddNode(node3, (0, 5.5), (1, 10));

            Assert.That(nodeGraph.AreLinked(node1, node2));
            Assert.AreEqual(5.5, nodeGraph.GetEdgeWidth(node1, node2));
            Assert.That(nodeGraph.AreLinked(node3, node2));
            Assert.That(nodeGraph.AreLinked(node3, node1));
            Assert.AreEqual(5.5, nodeGraph.GetEdgeWidth(node1, node3));
            Assert.AreEqual(10, nodeGraph.GetEdgeWidth(node2, node3));
        }
예제 #6
0
 public void When_CheckNonExistingEdges_Expect_NotFound(NodeGraph nodeGraph)
 {
     for (int i = 1; i < nodeGraph.Nodes.Count; i++)
     {
         for (int j = 1; j < nodeGraph.Nodes.Count; j++)
         {
             // Assume a node cannot be linked to itself.
             Assert.That(!nodeGraph.AreLinked(i, j));
         }
     }
 }
예제 #7
0
        public void When_CreateNewEdgeByIndex_Expect_EdgeAdded(NodeGraph nodeGraph)
        {
            Node edgeStartNode = nodeGraph.Nodes[1];
            Node edgeEndNode   = nodeGraph.Nodes[2];

            nodeGraph.LinkNodes(edgeStartNode.index, edgeEndNode.index, 5);

            Assert.That(nodeGraph.AreLinked(edgeStartNode, edgeEndNode));
            Assert.AreEqual(5, nodeGraph.Edges[4].width);
            Assert.AreEqual(5, nodeGraph.GetEdgeWidth(edgeStartNode, edgeEndNode));
        }
예제 #8
0
        public void When_MergeNode_Expect_NodeMerged(NodeGraph nodeGraph)
        {
            NodeGraph nodeGraphCopy = nodeGraph.DeepCopy();

            Node node1 = nodeGraph.GetNode(new Vect3(1, 1, 1));
            Node node2 = nodeGraph.GetNode(new Vect3(2, 2, 2));
            Node node3 = nodeGraph.GetNode(new Vect3(3, 3, 3));
            Node node4 = nodeGraph.GetNode(new Vect3(4, 4, 4));
            Node node5 = nodeGraph.GetNode(new Vect3(5, 5, 5));

            nodeGraph.LinkNodes(node2, node3);

            node1 = nodeGraph.MoveNode(node1, node2.coordinate);

            Assert.That(nodeGraph.AreLinked(node1, node3));
            Assert.That(nodeGraph.AreLinked(node1, node4));
            Assert.That(nodeGraph.AreLinked(node1, node5));

            Assert.AreEqual(4, nodeGraph.Nodes.Count);
            Assert.AreEqual(3, nodeGraph.Edges.Count);

            foreach (Node node in nodeGraph.Nodes)
            {
                foreach (NodeEdgePair neighbor in node.neighbors)
                {
                    Assert.AreNotEqual(node2.index, neighbor.nodeIndex);
                }
            }

            foreach (Edge edge in nodeGraph.Edges)
            {
                Assert.AreNotEqual(node2.index, edge.nodeIndex1);
                Assert.AreNotEqual(node2.index, edge.nodeIndex2);
            }

            Assert.AreEqual(nodeGraph.GetNode(new Vect3(1, 1, 1)), null);

            Assert.AreNotEqual(nodeGraph, nodeGraphCopy);
        }
예제 #9
0
        public void When_AddNodeWithNeighborByIndex_Expect_EdgeAdded()
        {
            NodeGraph nodeGraph = new NodeGraph();

            Node node       = new Node(1, 1, 1);
            Node secondNode = new Node(2, 2, 2);

            nodeGraph.AddNode(node);
            nodeGraph.AddNode(secondNode, 0);

            Assert.AreEqual(1, nodeGraph.Edges.Count);
            Assert.AreEqual(0, nodeGraph.Edges[0].index);
            Assert.That(nodeGraph.AreLinked(node, secondNode));
        }
예제 #10
0
        public void When_RemoveEdge_Expect_OrderUnimportant(NodeGraph nodeGraph)
        {
            NodeGraph nodeGraphCopy = nodeGraph.DeepCopy();
            Node      edgeStart     = nodeGraph.Nodes[0];
            Node      edgeEnd       = nodeGraph.Nodes[1];

            nodeGraph.RemoveEdge(edgeStart, edgeEnd);
            nodeGraphCopy.RemoveEdge(edgeEnd, edgeStart);

            Assert.That(!nodeGraph.AreLinked(edgeStart, edgeEnd));
            Assert.That(!nodeGraphCopy.AreLinked(edgeStart, edgeEnd));

            Assert.AreEqual(nodeGraph, nodeGraphCopy);
        }
예제 #11
0
        public void When_MoveNode_Expect_NodeMoved(NodeGraph nodeGraph)
        {
            NodeGraph nodeGraphCopy = nodeGraph.DeepCopy();

            Node node2 = nodeGraph.GetNode(new Vect3(2, 2, 2));
            Node node3 = nodeGraph.GetNode(new Vect3(3, 3, 3));
            Node node4 = nodeGraph.GetNode(new Vect3(4, 4, 4));
            Node node5 = nodeGraph.GetNode(new Vect3(5, 5, 5));

            nodeGraph.MoveNode(new Vect3(1, 1, 1), new Vect3(70, 70, 70));

            Node node1 = nodeGraph.GetNode(new Vect3(70, 70, 70));

            Assert.That(nodeGraph.AreLinked(node1, node2));
            Assert.That(nodeGraph.AreLinked(node1, node3));
            Assert.That(nodeGraph.AreLinked(node1, node4));
            Assert.That(nodeGraph.AreLinked(node1, node5));

            Assert.AreEqual(5, nodeGraph.Nodes.Count);

            Assert.AreEqual(nodeGraph.GetNode(new Vect3(1, 1, 1)), null);

            Assert.AreNotEqual(nodeGraph, nodeGraphCopy);
        }
예제 #12
0
        public void When_MergeNode_Expect_MinDistanceKept(NodeGraph nodeGraph)
        {
            NodeGraph nodeGraphCopy = nodeGraph.DeepCopy();

            Node node1 = nodeGraph.GetNode(new Vect3(1, 1, 1));
            Node node2 = nodeGraph.GetNode(new Vect3(2, 2, 2));
            Node node3 = nodeGraph.GetNode(new Vect3(3, 3, 3));
            Node node4 = nodeGraph.GetNode(new Vect3(4, 4, 4));
            Node node5 = nodeGraph.GetNode(new Vect3(5, 5, 5));

            nodeGraph.LinkNodes(node1, node4);
            nodeGraph.SetEdgeWidth(node1, node2, 5);
            nodeGraph.SetEdgeWidth(node2, node3, 10);

            node1 = nodeGraph.MoveNode(node2, node1.coordinate);

            Assert.That(nodeGraph.AreLinked(new Vect3(1, 1, 1), new Vect3(3, 3, 3)));
            Assert.AreEqual(5d, nodeGraph.GetEdgeWidth(new Vect3(1, 1, 1), new Vect3(3, 3, 3)));

            Assert.AreNotEqual(nodeGraph, nodeGraphCopy);
        }
예제 #13
0
        public void When_RemoveEdgeByCoordinates_Expect_EdgeRemoved(NodeGraph nodeGraph)
        {
            Node edgeStart = nodeGraph.Nodes[0];
            Node edgeEnd   = nodeGraph.Nodes[1];

            Edge edge = nodeGraph.GetEdge(edgeStart.coordinate, edgeEnd.coordinate);

            nodeGraph.RemoveEdge(edgeStart.coordinate, edgeEnd.coordinate);

            Assert.That(!nodeGraph.AreLinked(edgeStart, edgeEnd));
            Assert.That(!nodeGraph.Edges.Exists(x => x.index == edge.index));

            foreach (NodeEdgePair neighbor in edgeStart.neighbors)
            {
                Assert.AreNotEqual(edgeStart.index, neighbor.nodeIndex);
            }

            foreach (NodeEdgePair neighbor in edgeEnd.neighbors)
            {
                Assert.AreNotEqual(edgeEnd.index, neighbor.nodeIndex);
            }
        }