public void ShortestPathToBlockedEdge() { Graph graph = new Graph(1); Node a = new Node("a"); Node b = new Node("b"); Node c = new Node("c"); Node d = new Node("d"); Node e = new Node("e"); graph.AddNode(a); graph.AddNode(b); graph.AddNode(c); graph.AddNode(d); graph.AddNode(e); graph.AddUndirectedEdge(new Tuple<Node, int>(a, 1), new Tuple<Node, int>(b, 3), 1); graph.AddUndirectedEdge(new Tuple<Node, int>(b, 2), new Tuple<Node, int>(c, 0), 2); graph.AddUndirectedEdge(new Tuple<Node, int>(c, 3), new Tuple<Node, int>(d, 1), 3); //block this graph.AddUndirectedEdge(new Tuple<Node, int>(d, 0), new Tuple<Node, int>(e, 2), 200); graph.AddUndirectedEdge(new Tuple<Node, int>(e, 1), new Tuple<Node, int>(a, 3), 100); graph.BlockEdge(c, d); Path expectedPath = new Path() { Identifier = 1, Nodes = new List<Node>(){a, b, c} }; Path actualPath = graph.PathToBlockedEdge(a, graph.BlockedEdges.FirstOrDefault()); actualPath.Identifier = 1; Assert.IsTrue(expectedPath.Equals(actualPath)); }
public void ShortestPathThreeNodesTwoPaths() { Graph g = new Graph(1); Node a = new Node("a"); Node b = new Node("b"); Node c = new Node("c"); Edge ab = new Edge(20); Edge ac = new Edge(10); Edge cb = new Edge(5); g.AddNode(a); g.AddNode(b); g.AddNode(c); g.AddUndirectedEdge(new Tuple<Node, int>(a, 0), new Tuple<Node, int>(b, 0), ab); g.AddUndirectedEdge(new Tuple<Node, int>(a, 1), new Tuple<Node, int>(c, 0), ac); g.AddUndirectedEdge(new Tuple<Node, int>(c, 1), new Tuple<Node, int>(b, 1), cb); Path actual = g.ShortestPath(a, b); Path expected = new Path(); expected.Nodes.Add(a); expected.Nodes.Add(c); expected.Nodes.Add(b); Assert.IsTrue(expected.Equals(actual)); }