示例#1
0
        public void SortThrowsTopologicalSortExceptionExceptionWhenGraphContainsLoops()
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);

            graph.AddSequence(new[] { 61, 11 });
            graph.Sort().ToArray();
        }
示例#2
0
        public void GetNodesWithBetweenReturnsNodesOnTheLevelsInTheRange(int levelFrom, int levelTo, int[] expectedNodes)
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);

            GraphTestHelper.AssertCollectionsConsistsOfNodes(expectedNodes,
                                                             graph.GetNodesBetween(levelFrom, levelTo));
            GraphTestHelper.AssertNodesAreOrderedByLevel(graph.GetNodesBetween(levelFrom, levelTo));
        }
示例#3
0
        public void SortReturnsNodesInTopologicalOrder()
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);
            var nodes = graph.Sort();

            Assert.AreEqual(20, nodes.Count());
            AssertNodesAreInTopologicalOrder(nodes);
        }
示例#4
0
        public void DescendantsReturnsDescendantsOfTheNode(int node, int[] expectedDescendants)
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);

            GraphTestHelper.AssertCollectionsConsistsOfNodes(expectedDescendants,
                                                             graph.Find(node).Descendants);
            GraphTestHelper.AssertNodesAreOrderedByLevel(graph.Find(node).Descendants);
        }
示例#5
0
        public void GetNodesReturnsNodesOnTheLevel(int level, int[] expectedNodes)
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);

            GraphTestHelper.AssertCollectionsConsistsOfNodes(expectedNodes,
                                                             graph.GetNodes(level));
            GraphTestHelper.AssertNodesAreOrderedByLevel(graph.GetNodes(level));
        }
示例#6
0
        public void GetNeighboursReturnsNeighboursOfTheNodeInTheRangeOfLevels(int node, int[] expectedNeighbours)
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);

            GraphTestHelper.AssertCollectionsConsistsOfNodes(expectedNeighbours,
                                                             graph.Find(node).GetNeighbours(-1, 2));
            GraphTestHelper.AssertNodesAreOrderedByLevel(graph.Find(node).GetNeighbours(-1, 2));
        }
示例#7
0
        public void TerminatingPrecedentsReturnsPrecedentsOfTheNodeOnTheZeroLevel(int node, int[] expectedTerminatingPrecedents)
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);

            GraphTestHelper.AssertCollectionsConsistsOfNodes(expectedTerminatingPrecedents,
                                                             graph.Find(node).TerminatingPrecedents);
            GraphTestHelper.AssertNodesAreOrderedByLevel(graph.Find(node).TerminatingPrecedents);
        }
示例#8
0
        public void LevelCalculatesCorrectly(int node, int expectedLevel)
        {
            var graph       = GraphTestHelper.CreateExampleGraph(TargetGraph);
            var countLevels = graph.CountLevels; // force graph to rebuild. fix this later
            var target      = graph.Find(node);

            Assert.AreEqual(expectedLevel, target.Level,
                            "Level of node {0} expected to be {1}, but is {2}", target.Value, expectedLevel, target.Level);
        }
示例#9
0
        public void FindReturnsCorrectValue(int node)
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);

            Assert.AreEqual(node, graph.Find(node).Value);
        }
示例#10
0
        public void CountLevelsReturnsNumberOfLevelsInGraph1()
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);

            Assert.AreEqual(6, graph.CountLevels);
        }
示例#11
0
        public void CountReturnsCountOfGraph()
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);

            Assert.AreEqual(20, graph.CountNodes);
        }