Beispiel #1
0
        public void GraphWithoutCyclesRemainsUntouched()
        {
            var graph   = GraphFactory.BuildGraph("0-1", "1-2", "2-3", "2-4");
            var acyclic = CycleReducer.RemoveCycles(graph);

            acyclic.Cycles.Should().HaveCount(0);
            acyclic.GraphWithoutCycles.Nodes.Should().HaveCount(5);
        }
Beispiel #2
0
        public void GraphWithOnlyACycleIsSubstituted()
        {
            var graph   = GraphFactory.BuildGraph("0-1", "1-2", "2-0");
            var acyclic = CycleReducer.RemoveCycles(graph);

            acyclic.Cycles.Should().HaveCount(1);
            acyclic.GraphWithoutCycles.Nodes.Should().HaveCount(1);
        }
Beispiel #3
0
 public void DoesNotVisitDisconnectedNodes()
 {
     DepthFirst.VisitAll(
         GraphFactory.BuildGraph("A-B", "C-D"), NodeIdentity.Of("A"))
     .Should()
     .ContainInOrder(
         NodeIdentity.Of("A"),
         NodeIdentity.Of("B")
         ).And.HaveCount(2);
 }
Beispiel #4
0
 public void CanFindStraightPath()
 {
     BreadthFirst.FindPath(GraphFactory.BuildGraph("A-B", "B-C", "C-D"), NodeIdentity.Of("A"), node => node == NodeIdentity.Of("D"))
     .Should().ContainInOrder(
         NodeIdentity.Of("A"),
         NodeIdentity.Of("B"),
         NodeIdentity.Of("C"),
         NodeIdentity.Of("D")
         ).And.HaveCount(4);
 }
Beispiel #5
0
 public void FindsShortestPath()
 {
     BreadthFirst.FindPath(
         GraphFactory.BuildGraph("A-B", "B-C", "C-D", "A-D"),
         NodeIdentity.Of("A"),
         node => node == NodeIdentity.Of("D"))
     .Should().ContainInOrder(
         NodeIdentity.Of("A"),
         NodeIdentity.Of("D")
         ).And.HaveCount(2);
 }
        public void Extend(string from, string to, string expected)
        {
            var graph        = GraphFactory.BuildGraph("A-B", "B-C", "C-D", "A-D");
            var fromPath     = CreatePath(from);
            var toPath       = CreatePath(to);
            var expectedPath = CreatePath(expected);

            object extension = fromPath.Extend(toPath, graph);

            extension.Should().Be(expectedPath);
        }
Beispiel #7
0
        public void ReducedGraphsHaveCorrectNodeAndCycleCount()
        {
            var graph = GraphFactory.BuildGraph(
                "0-1", "0-4",
                "1-2", "1-5",
                "2-3",
                "3-1",
                "4-6", "4-4",
                "5-6");
            var acyclic = CycleReducer.RemoveCycles(graph);

            acyclic.GraphWithoutCycles.Nodes.Should().HaveCount(5);
            acyclic.Cycles.Should().HaveCount(2); // 1-2-3-1 and 4-4
        }
        public void IncorrectResultsReturned()
        {
            GraphFactory  factory = new GraphFactory();
            List <string> input   = new List <string>()
            {
                "supernatant",
                "s",
                "super"
            };
            ConcurrentDictionary <string, List <string> > result = factory.BuildGraph(input);

            Assert.AreEqual(3, result.Count());
            List <string> edges;

            Assert.IsTrue(result.TryGetValue("supernatant", out edges));
            Assert.IsFalse(edges.Any());
        }
        public void BuildGraph()
        {
            List <string> testData = new List <string>()
            {
                "agne",
                "agnes",
                "agnew",
                "abnes"
            };

            GraphFactory factory = new GraphFactory();

            ConcurrentDictionary <string, List <string> > result = factory.BuildGraph(testData);

            Assert.IsTrue(result["agne"].Any(a => a == "agnes"));
            Assert.IsTrue(result["agne"].Any(a => a == "agnew"));
        }
        public void ExampleFromIntroToSoftwareTesting()
        {
            var graph = GraphFactory.BuildGraph(
                "0-1", "0-4",
                "1-2", "1-5",
                "2-3",
                "3-1",
                "4-4", "4-6",
                "5-6");
            var sut        = new PrimePathFinder();
            var primePaths = sut.FindPrimePaths(graph);

            primePaths.Should()
            .BeEquivalentTo(
                GraphFactory.CreatePath("4", "4"),
                GraphFactory.CreatePath("0", "4", "6"),
                GraphFactory.CreatePath("0", "1", "2", "3"),
                GraphFactory.CreatePath("0", "1", "5", "6"),
                GraphFactory.CreatePath("1", "2", "3", "1"),
                GraphFactory.CreatePath("2", "3", "1", "2"),
                GraphFactory.CreatePath("3", "1", "2", "3"),
                GraphFactory.CreatePath("2", "3", "1", "5", "6")
                );
        }
Beispiel #11
0
 private static DirectedGraph CreateSimpleGraph()
 {
     return(GraphFactory.BuildGraph("A-B1", "A-B2", "B1-C1", "B2-C1", "B2-C2"));
 }
 private DirectedGraph CreateGraph()
 {
     return(GraphFactory.BuildGraph("S-1", "1-2", "2-T",
                                    "1-3", "3-4", "4-1", "4-5", "5-4"));
 }