コード例 #1
0
        public void ShouldCalculateShortestPathLength(string igraph, char isourceNode, char idestinationNode, int expectedShortedPathLength)
        {
            //Arrange
            var sut   = new DijkstrasShortestPathAlgorithm <char>();
            var graph = GraphLoaderHelper.LoadGraphFromString(igraph);

            //Act
            var result = sut.GetShortestPath(graph, isourceNode, idestinationNode).PathWeight;

            //Assert
            Assert.AreEqual(expectedShortedPathLength, result);
        }
コード例 #2
0
        public void ShouldReturnNullWhenNoPathExistsGivenSourceAndDestinationNode(string igraph, char isourceNode, char idestinationNode)
        {
            //Arrange
            var sut   = new DijkstrasShortestPathAlgorithm <char>();
            var graph = GraphLoaderHelper.LoadGraphFromString(igraph);

            //Act
            var result = sut.GetShortestPath(graph, isourceNode, idestinationNode);

            //Assert
            Assert.IsNull(result);
        }
コード例 #3
0
        public void ShouldCountAllCyclesGivenSourceNodeAndMaxPathWeight(string igraph, char isourceNode, int imaxWeight, int expectedCycleCount)
        {
            //Arrange
            var graph = GraphLoaderHelper.LoadGraphFromString(igraph);
            var sut   = new CycleOperations <char>();

            //Act
            var actual = sut.CountAllCycles(graph, isourceNode, imaxWeight);

            //Assert
            Assert.AreEqual(expectedCycleCount, actual);
        }
コード例 #4
0
        public void ShouldCountAllSimpleCyclesWhenGivenSourceNodeAndMaxStops(string igraph, char isourceNode, int imaxStops, int expectedCycleCount)
        {
            //Arrange
            var graph = GraphLoaderHelper.LoadGraphFromString(igraph);
            var sut   = new CycleOperations <char>();

            //Act
            var actual = sut.FindAllSimpleCycles(graph, isourceNode, imaxStops);

            //Assert
            Assert.AreEqual(expectedCycleCount, actual.Count);
        }
コード例 #5
0
        public void ShouldCountAllSimpleCycles(string igraph, int expectedCycleCount)
        {
            //Arrange
            var graph = GraphLoaderHelper.LoadGraphFromString(igraph);
            var sut   = new CycleOperations <char>();

            //Act
            var actual = sut.FindAllSimpleCycles(graph);

            //Assert
            Assert.AreEqual(expectedCycleCount, actual.Count);
        }
コード例 #6
0
        public void ShouldCountSimplePathsGivenSourceAndDestinationNode(string igraph, char isourceNode, char idestinationNode, int expectedNofPaths)
        {
            //Arrange
            var graph = GraphLoaderHelper.LoadGraphFromString(igraph);
            var sut   = new PathOperations <Char>();

            //Assert
            var actual = sut.FindAllSimplePaths(graph, isourceNode, idestinationNode);

            //Act
            Assert.AreEqual(expectedNofPaths, actual.Count);
        }
コード例 #7
0
        public void ShouldCountPathsWhenGivenSourceDestinationAndNumberOfStops(string igraph, char isourceNode, char idestinationNode, int inoOfStops, int expectedNoOfPaths)
        {
            //Arrange
            var graph = GraphLoaderHelper.LoadGraphFromString(igraph);
            var sut   = new PathOperations <Char>();

            //Assert
            var actual = sut.CountAllPaths(graph, isourceNode, idestinationNode, inoOfStops);

            //Atc
            Assert.AreEqual(expectedNoOfPaths, actual);
        }
コード例 #8
0
        public void ShouldTraverseAllEdges(string graph, string expected)
        {
            //Arrange
            var sut = new DepthFirstSearchAlgorithm <char>();

            //Act
            var result = sut.TraverseGraph(GraphLoaderHelper.LoadGraphFromString(graph));
            var actual =
                result.OrderBy(x => x.SourceNode)
                .ThenBy(x => x.DestinationNode)
                .ConvertDfsEdgeToString();

            //Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #9
0
        public void ShouldReturnDfsBackEdges(string graph, string expected)
        {
            var sut = new DepthFirstSearchAlgorithm <char>();

            var result = sut.TraverseGraph(GraphLoaderHelper.LoadGraphFromString(graph));


            var actual =
                result.Where(x => x.EdgeType == DepthFirstSearchEdgeType.BackEdge)
                .OrderBy(x => x.SourceNode)
                .ThenBy(x => x.DestinationNode)
                .ConvertDfsEdgeToString();

            Assert.AreEqual(expected, actual);
        }