Esempio n. 1
0
        public void AdjacencyList_AddVertexAndEdgesToDirectedGraph_DataConsistent()
        {
            var graph = new AlgorithmsAndDataStructures.DataStructures.Graphs.AdjacencyList.AdjacencyList(true);

            graph.AddVertex("a")
            .AddEdge("b")
            .AddEdge("c");
            graph.AddVertex("d");

            var vertex = graph.GetVertex("a");

            vertex.Name.Should().Be("a");
            var edges = vertex.GetEdges().ToArray();

            edges.Length.Should().Be(2);
            edges[0].Vertex1.Name.Should().Be("a");
            edges[0].Vertex2.Name.Should().Be("b");
            edges[0].Weight.Should().Be(0);
            edges[1].Vertex1.Name.Should().Be("a");
            edges[1].Vertex2.Name.Should().Be("c");
            edges[1].Weight.Should().Be(0);

            graph.Vertexes.Count.Should().Be(4);
            graph.Vertexes["a"].GetEdges().Count.Should().Be(2);
            graph.Vertexes["d"].GetEdges().Count.Should().Be(0);
            graph.GetVertexes().Count.Should().Be(4);
        }
Esempio n. 2
0
        public void AdjacencyList_AddVertexToDirected_VertexAvailable()
        {
            var graph = new AlgorithmsAndDataStructures.DataStructures.Graphs.AdjacencyList.AdjacencyList(true);

            graph.AddVertex("a");

            graph.Vertexes.Count.Should().Be(1);
            graph.Vertexes["a"].GetEdges().Count.Should().Be(0);
            graph.GetVertexes().Count.Should().Be(1);
        }