Ejemplo n.º 1
0
        public void GraphSearchTest()
        {
            UndirectedGraph <string> graph = new UndirectedGraph <string>();

            GraphNode <string> node1 = new GraphNode <string>("node1");
            GraphNode <string> node2 = new GraphNode <string>("node2");
            GraphNode <string> node3 = new GraphNode <string>("node3");
            GraphNode <string> node4 = new GraphNode <string>("node4");
            GraphNode <string> node5 = new GraphNode <string>("node5");

            graph.AddPair(node1, node4);
            graph.AddPair(node4, node5);
            graph.AddPair(node5, node2);

            Assert.AreEqual(node2, DFS.FindGraphNode(node1, "node2"));
            Assert.AreEqual(null, DFS.FindGraphNode(node1, "node3"));
        }
        public void AddEdgeTest()
        {
            UndirectedGraph <string> graph = new UndirectedGraph <string>();

            GraphNode <string> node1 = new GraphNode <string>("node1");
            GraphNode <string> node2 = new GraphNode <string>("node2");
            GraphNode <string> node3 = new GraphNode <string>("node3");
            GraphNode <string> node4 = new GraphNode <string>("node4");
            GraphNode <string> node5 = new GraphNode <string>("node5");

            graph.AddPair(node1, node4);
            graph.AddPair(node4, node5);

            Assert.AreEqual(1, node1.NeighborCount);
            Assert.AreEqual(2, node4.NeighborCount);
            Assert.IsTrue(node4.Neighbors.Contains(node5));
        }
        public void ValidEdgeTest()
        {
            UndirectedGraph <string> graph = new UndirectedGraph <string>();

            GraphNode <string> node1 = new GraphNode <string>("node1");
            GraphNode <string> node2 = new GraphNode <string>("node2");
            GraphNode <string> node3 = new GraphNode <string>("node3");
            GraphNode <string> node4 = new GraphNode <string>("node4");
            GraphNode <string> node5 = new GraphNode <string>("node5");

            graph.AddPair(node1, node4);

            Assert.IsTrue(graph.IsValidEdge(node1, node4));
            Assert.IsTrue(graph.IsValidEdge(node4, node1));
            Assert.IsFalse(graph.IsValidEdge(node1, node5));
        }