Exemple #1
0
        public void RouteBetweenNodes(string nodes, string edges, int startNode, int endNode, bool exptectedResult)
        {
            Graph g = new Graph();

            GraphNode <int> n1 = null;
            GraphNode <int> n2 = null;

            nodes.Split(',').Select(int.Parse).ToList().ForEach(x =>
            {
                var node = g.AddNode(x);

                if (x == startNode)
                {
                    n1 = node;
                }
                if (x == endNode)
                {
                    n2 = node;
                }
            });

            edges.Split('|').ToList().ForEach(x =>
            {
                if (x != "")
                {
                    var y = x.Split(',');
                    g.AddEdge(int.Parse(y[0]), int.Parse(y[1]));
                }
            });

            var actualResult = TreesAndGraphs.RouteBetweenNodes(n1, n2);

            Assert.AreEqual(exptectedResult, actualResult);
        }