예제 #1
0
        public void YouTubeExampleConnectivityTest()
        {
            Graph graph = new UnidirectionalGraph();

            GraphTestHelpers.CommonInitialize(graph);

            Connectivity connectivity = new Connectivity(graph);

            bool isConnected = connectivity.IsConnected("a", "z");

            Assert.IsTrue(isConnected, "A should be connected to Z");
            isConnected = connectivity.IsConnected(graph.GetVertex("z"), graph.GetVertex("a"));
            Assert.IsFalse(isConnected, "Z should not be connected to A");
        }
예제 #2
0
        public void GetVertexTest()
        {
            Graph graph = new UnidirectionalGraph();

            Assert.IsTrue(graph.Directionality == Directionality.Unidirectional);

            GraphTestHelpers.CommonInitialize(graph);
            Assert.IsTrue(graph.NumVertices == 6);

            Vertex v = graph.GetVertex("a");

            Assert.IsNotNull(v);
        }
예제 #3
0
        public void GetVertexIndexTest2()
        {
            Graph graph = new UnidirectionalGraph();

            Assert.IsTrue(graph.Directionality == Directionality.Unidirectional);

            GraphTestHelpers.CommonInitialize(graph);
            Vertex v = graph.GetVertex("b");

            Assert.IsNotNull(v);

            int index = graph.GetVertexIndex(v);

            Assert.IsTrue(index >= 0);
        }
예제 #4
0
        public void GetAdjacentVerticesNoConnectionsTest()
        {
            Graph graph = new UnidirectionalGraph();

            Assert.IsTrue(graph.Directionality == Directionality.Unidirectional);

            GraphTestHelpers.CommonInitialize(graph);
            Vertex v = graph.GetVertex("z");

            Assert.IsNotNull(v);

            List <Vertex> adjacentVertices = graph.GetAdjacentVertices(v);

            Assert.IsNotNull(adjacentVertices);
            Assert.IsFalse(adjacentVertices.Any());
        }
예제 #5
0
        public void GetEdgesTest()
        {
            Graph graph = new UnidirectionalGraph();

            Assert.IsTrue(graph.Directionality == Directionality.Unidirectional);

            GraphTestHelpers.CommonInitialize(graph);
            Vertex v = graph.GetVertex("a");

            Assert.IsNotNull(v);

            IEnumerable <WeightedEdge <int> > edges = graph.GetEdges(v);

            Assert.IsNotNull(edges);
            Assert.IsTrue(edges.Any());
        }
예제 #6
0
        public void GetAdjacentVerticesTest()
        {
            Graph graph = new UnidirectionalGraph();

            Assert.IsTrue(graph.Directionality == Directionality.Unidirectional);

            GraphTestHelpers.CommonInitialize(graph);
            Vertex v = graph.GetVertex("a");

            Assert.IsNotNull(v);

            List <Vertex> adjacentVertices = graph.GetAdjacentVertices(v);

            Assert.IsNotNull(adjacentVertices);
            Assert.IsTrue(adjacentVertices.Any());

            // Vertex B and C should be the only vertices that are adjacent to A
            Assert.IsTrue(adjacentVertices.Count == 2);
            Assert.IsTrue(adjacentVertices[0].Name == "b");
            Assert.IsTrue(adjacentVertices[1].Name == "c");
        }