Exemplo n.º 1
0
        public void GenerateGraph()
        {
            var dotText = new List <string>()
            {
                "digraph D {",
                "Start ->    Middle1",
                "Middle1 ->    Start",
                "Start     -> End [label=\"2\"]",
                "Middle2->End [label=\"Test\"]",
                "Middle1 -> Middle2 [label=\"2\"]",
                "}",
            };

            var graph = GraphGenerator.FromDotText(dotText);

            Assert.AreEqual(4, graph.Nodes.Count());
            Assert.AreEqual(5, graph.Edges.Count());

            var text = graph.ToDotText();

            Assert.IsTrue(text.Contains("Start -> Middle1"));
            Assert.IsTrue(text.Contains("Middle1 -> Start"));
            Assert.IsTrue(text.Contains("Start -> End"));
            Assert.IsTrue(text.Contains("Middle2 -> End"));
            Assert.IsTrue(text.Contains("Middle1 -> Middle2"));

            var image = graph.ToImage(GraphVizPath);

            Assert.IsNotNull(image);
        }
Exemplo n.º 2
0
        public void GenerateGraphWithDoubleEdges()
        {
            var dotText = new List <string>()
            {
                "digraph D {",
                "Start <->    Middle1",
                "Start ->    Middle1",
                "Start     -> End [label=\"2\"]",
                "Middle2->End [label=\"Test\"]",
                "Middle1 -> Middle2 [label=\"2\"]",
                "}",
            };

            var _ = GraphGenerator.FromDotText(dotText);
        }
Exemplo n.º 3
0
        public void Degree8()
        {
            var graphText = File.ReadLines(Path.Combine("TestGraphs", "LargeGraph.txt"));

            var graph = GraphGenerator.FromDotText(graphText);

            var shortestGraph = graph.ToShortestGraph("Actor:Eric Elmosnino(1964)", "Actor:Libuse Safránková(1953)");

            var paths = (new PathAlgorithm(shortestGraph)).GetAllPaths("Actor:Eric Elmosnino(1964)");

            Assert.AreEqual(1032, paths.Count); //only copied

            foreach (var path in paths)
            {
                Assert.IsTrue(path.StartsWith("Actor:Eric Elmosnino(1964)"));
                Assert.IsTrue(path.EndsWith("Actor:Libuse Safránková(1953)"));
            }
        }
Exemplo n.º 4
0
        public void GenerateGraphWithDifferentWeights()
        {
            var dotText = new List <string>()
            {
                "digraph D {",
                "Start ->    Middle1 [weight=1]",
                "Start ->    Middle2 [weight=2]",
                "Middle2     -> End [weight=\"1\", label=\"2\"]",
                "Middle1     -> End [label=\"2\", weight=1]",
                "}",
            };

            var graph = GraphGenerator.FromDotText(dotText);

            Assert.AreEqual(1d, graph.GetEdge("Start", "Middle1").Weight);
            Assert.AreEqual(2d, graph.GetEdge("Start", "Middle2").Weight);
            Assert.AreEqual(1d, graph.GetEdge("Middle1", "End").Weight);
            Assert.AreEqual(1d, graph.GetEdge("Middle2", "End").Weight);

            var shortestGraph = graph.ToShortestGraph("Start", "End");

            Assert.AreEqual(3, shortestGraph.Nodes.Count());
            Assert.AreEqual(2, shortestGraph.Edges.Count());
        }
Exemplo n.º 5
0
        public void GenerateGraphWithBidirectionalEdge()
        {
            var dotText = new List <string>()
            {
                "digraph D {",
                "Start <->    Middle1",
                "Start     -> End [label=\"2\"]",
                "Middle2->End [label=\"Test\"]",
                "Middle1 -> Middle2 [label=\"2\"]",
                "}",
            };

            var graph = GraphGenerator.FromDotText(dotText);

            Assert.AreEqual(4, graph.Nodes.Count());
            Assert.AreEqual(4, graph.Edges.Count());

            var text = graph.ToDotText();

            Assert.IsTrue(text.Contains("Start -> Middle1 [color=black,arrowhead=normal,fontcolor=black,style=solid,label=\"\",decorate=false,dir=\"both\"]"));
            Assert.IsTrue(text.Contains("Start -> End"));
            Assert.IsTrue(text.Contains("Middle2 -> End"));
            Assert.IsTrue(text.Contains("Middle1 -> Middle2"));
        }
        public static void Initialize(TestContext _)
        {
            var graphText = File.ReadLines(Path.Combine("TestGraphs", "LargeGraph.txt"));

            _graph = GraphGenerator.FromDotText(graphText);
        }