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);
        }
Beispiel #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));
        }
        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));
        }
        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);
        }
Beispiel #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));
        }
Beispiel #6
0
        public void SortReturnsNodesInTopologicalOrder()
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);
            var nodes = graph.Sort();

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

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

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

            Assert.AreEqual(20, graph.CountNodes);
        }
Beispiel #12
0
        public void CountLevelsReturnsNumberOfLevelsInGraph1()
        {
            var graph = GraphTestHelper.CreateExampleGraph(TargetGraph);

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