Пример #1
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);
        }
Пример #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 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));
        }
Пример #4
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);
        }
Пример #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 SortReturnsNodesInTopologicalOrder()
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);
            var nodes = graph.Sort();

            Assert.AreEqual(20, nodes.Count());
            AssertNodesAreInTopologicalOrder(nodes);
        }
Пример #7
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);
        }
Пример #8
0
 public void SortThrowsTopologicalSortExceptionExceptionWhenGraphContainsLoops()
 {
     Assert.Throws <TopologicalSortException>(() =>
     {
         var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);
         graph.AddSequence(new[] { 61, 11 });
         graph.Sort().ToArray();
     });
 }
Пример #9
0
        public void GetLeafNodesReturnsNodesOnLastLevel(int[] expectedNodes)
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);

            GraphTestHelper.AssertCollectionsConsistsOfNodes(expectedNodes, graph.GetLeafNodes());
        }
Пример #10
0
        public void FindReturnsCorrectValue(int node)
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);

            Assert.AreEqual(node, graph.Find(node).Value);
        }
Пример #11
0
        public void CountReturnsCountOfGraph()
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);

            Assert.AreEqual(20, graph.CountNodes);
        }
Пример #12
0
        public void CountLevelsReturnsNumberOfLevelsInGraph1()
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);

            Assert.AreEqual(6, graph.CountLevels);
        }