Beispiel #1
0
        public void AddDirectedEdge_ShouldAddConnectedVertexToAdjacencyLists_WhenExistingKeysSpecified()
        {
            var graph = MixedGraphTestData.GenerateTestGraph();
            var expectedAdjacencyLists = new Dictionary <int, IReadOnlyList <int> >()
            {
                [0] = new List <int>()
                {
                    1, 2
                },
                [1] = new List <int>()
                {
                    2
                },
                [2] = new List <int>()
                {
                    1, 0
                },
                [3] = new List <int>()
                {
                    1
                },
            };

            graph.AddDirectedEdge(3, 1);

            Assert.Equal(expectedAdjacencyLists, graph.AdjacencyLists);
        }
Beispiel #2
0
        public void RemoveVertex_ShouldRemoveVertexWithAllRelatedEdges_WhenTargetVertexExists()
        {
            var graph = MixedGraphTestData.GenerateTestGraph();
            var expectedAdjacencyLists = new Dictionary <int, IReadOnlyList <int> >()
            {
                [1] = new List <int>()
                {
                    2
                },
                [2] = new List <int>()
                {
                    1
                },
                [3] = new List <int>(),
            };

            graph.RemoveVertex(0);

            Assert.Equal(expectedAdjacencyLists, graph.AdjacencyLists);
        }