Example #1
0
        public void RemoveVertex_ShouldRemoveVertexWithAllRelatedEdges_WhenTargetVertexExists()
        {
            var graph = DirectedGraphTestData.GenerateTestGraph();
            var expectedAdjacencyLists = new Dictionary <int, IReadOnlyList <int> >()
            {
                [1] = new List <int>()
                {
                    2
                },
                [2] = new List <int>()
                {
                    1
                },
            };

            graph.RemoveVertex(0);

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

            graph.AddDirectedEdge(1, 0);

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