public void VisitAllNodes()
        {
            // Arrange
            var bfsGraph = new BFSGraph();

            bfsGraph.AddEdge(1, 2);
            bfsGraph.ResetDistances();
            bfsGraph.ResetSourcesDistance(2);

            // Act
            bfsGraph.VisitAllNodes(2);

            // Assert
            Assert.Equal(2, bfsGraph.Distances.Count);

            Assert.Equal(1, bfsGraph.Distances.First().Key);
            Assert.Equal(1, bfsGraph.Distances.First().Value);

            Assert.Equal(2, bfsGraph.Distances.Last().Key);
            Assert.Equal(0, bfsGraph.Distances.Last().Value);

            // Paths
            Assert.Equal(1, bfsGraph.Paths.Count);

            Assert.Equal(1, bfsGraph.Paths.Last().Key);
            Assert.Equal(2, bfsGraph.Paths.Last().Value);
        }
        public void AddingExistingEdgesDoNothing()
        {
            // Arrange
            var bfsGraph = new BFSGraph();

            // Act
            bfsGraph.AddEdge(1, 2);
            bfsGraph.AddEdge(1, 2);

            // Assert
            Assert.Equal(2, bfsGraph.References.Count());
        }
        public void AddEdgeTest()
        {
            // Arrange
            var bfsGraph = new BFSGraph();

            // Act
            bfsGraph.AddEdge(1, 2);

            // Assert
            Assert.Equal(1, bfsGraph.References.First().Key);
            Assert.Equal(2, bfsGraph.References.First().Value.First());

            Assert.Equal(2, bfsGraph.References.Last().Key);
            Assert.Equal(1, bfsGraph.References.Last().Value.First());
        }
        public void AddEdgeTestDetailed()
        {
            // Arrange
            var bfsGraph = new BFSGraph();

            bfsGraph.AddEdge(1, 2);
            bfsGraph.AddEdge(1, 3);
            bfsGraph.AddEdge(1, 4);
            bfsGraph.AddEdge(4, 5);
            bfsGraph.AddEdge(2, 6);
            bfsGraph.AddEdge(4, 7);
            bfsGraph.AddEdge(5, 6);
            bfsGraph.AddEdge(6, 7);

            // Act
            var references = bfsGraph.References.ToList();

            // Assert
            Assert.Equal(1, references[0].Key);
            Assert.Equal(2, references[0].Value[0]);
            Assert.Equal(3, references[0].Value[1]);
            Assert.Equal(4, references[0].Value[2]);

            Assert.Equal(2, references[1].Key);
            Assert.Equal(1, references[1].Value[0]);
            Assert.Equal(6, references[1].Value[1]);

            Assert.Equal(3, references[2].Key);
            Assert.Equal(1, references[2].Value[0]);

            Assert.Equal(4, references[3].Key);
            Assert.Equal(1, references[3].Value[0]);
            Assert.Equal(5, references[3].Value[1]);
            Assert.Equal(7, references[3].Value[2]);

            Assert.Equal(5, references[4].Key);
            Assert.Equal(4, references[4].Value[0]);
            Assert.Equal(6, references[4].Value[1]);

            Assert.Equal(6, references[5].Key);
            Assert.Equal(2, references[5].Value[0]);
            Assert.Equal(5, references[5].Value[1]);
            Assert.Equal(7, references[5].Value[2]);

            Assert.Equal(7, references[6].Key);
            Assert.Equal(4, references[6].Value[0]);
            Assert.Equal(6, references[6].Value[1]);
        }
        public void ShortestPath()
        {
            // Arrange
            var bfsGraph = new BFSGraph();

            bfsGraph.AddEdge(1, 2);

            // Act & Assert
            var paths = bfsGraph.ShortestPath(1, 2);

            // Assert
            Assert.Equal(2, paths.Count);

            Assert.Equal(1, paths.First());
            Assert.Equal(2, paths.Last());
        }
        public void ResetDistances()
        {
            // Arrange
            var bfsGraph = new BFSGraph();

            bfsGraph.AddEdge(1, 2);

            // Act
            bfsGraph.ResetDistances();

            // Assert
            Assert.Equal(1, bfsGraph.Distances.First().Key);
            Assert.Equal(-1, bfsGraph.Distances.First().Value);

            Assert.Equal(2, bfsGraph.Distances.Last().Key);
            Assert.Equal(-1, bfsGraph.Distances.Last().Value);
        }
        public void BuildPath()
        {
            // Arrange
            var bfsGraph = new BFSGraph();

            bfsGraph.AddEdge(1, 2);

            bfsGraph.ResetDistances();
            bfsGraph.ResetSourcesDistance(1);
            bfsGraph.VisitAllNodes(1);

            // Act
            var paths = bfsGraph.BuildPath(1, 2);

            // Assert
            Assert.Equal(2, paths.Count);

            Assert.Equal(1, paths.First());
            Assert.Equal(2, paths.Last());
        }
        public void ShortestPath6()
        {
            // Arrange
            var bfsGraph = new BFSGraph();

            bfsGraph.AddEdge(1, 2);
            bfsGraph.AddEdge(2, 3);
            bfsGraph.AddEdge(3, 4);
            bfsGraph.AddEdge(4, 5);
            bfsGraph.AddEdge(5, 6);

            // Act
            var paths = bfsGraph.ShortestPath(1, 6).ToList();

            // Assert
            Assert.Equal(1, paths[0]);
            Assert.Equal(2, paths[1]);
            Assert.Equal(3, paths[2]);
            Assert.Equal(4, paths[3]);
            Assert.Equal(5, paths[4]);
            Assert.Equal(6, paths[5]);
        }
        public void ShortestPath5()
        {
            // Arrange
            var bfsGraph = new BFSGraph();

            bfsGraph.AddEdge(1, 2);
            bfsGraph.AddEdge(1, 3);
            bfsGraph.AddEdge(1, 4);
            bfsGraph.AddEdge(4, 5);
            bfsGraph.AddEdge(2, 6);
            bfsGraph.AddEdge(4, 7);
            bfsGraph.AddEdge(5, 6);
            bfsGraph.AddEdge(6, 7);

            // Act
            var paths = bfsGraph.ShortestPath(2, 7).ToList();

            // Assert
            Assert.Equal(2, paths[0]);
            Assert.Equal(6, paths[1]);
            Assert.Equal(7, paths[2]);
        }
        public void UpdateDistancesAndPaths()
        {
            // Arrange
            var bfsGraph = new BFSGraph();

            bfsGraph.AddEdge(1, 2);
            bfsGraph.ResetDistances();
            bfsGraph.ResetSourcesDistance(2);

            // Act
            bfsGraph.UpdateDistancesAndPaths(2);

            // Assert
            Assert.Equal(1, bfsGraph.Distances.First().Key);
            Assert.Equal(1, bfsGraph.Distances.First().Value); // Updated distance

            Assert.Equal(2, bfsGraph.Distances.Last().Key);
            Assert.Equal(0, bfsGraph.Distances.Last().Value);

            // Paths
            Assert.Equal(1, bfsGraph.Paths.Last().Key);
            Assert.Equal(2, bfsGraph.Paths.Last().Value);
        }