public static List <Node> DepthFirst(Graphs graph) { List <Node> allNodes = graph.GetNodes(); Node root = new Node("root"); foreach (var item in allNodes) { root = item; break; } List <Node> preOrder = new List <Node>(); Stack <Node> depth = new Stack <Node>(); depth.Push(root); while (depth.TryPeek(out root)) { Node top = depth.Pop(); List <Node> child = new List <Node>(); while (!top.Visited) { } } return(preOrder); }
public void TestEmptyGraph() { ///return null if graph is empty Graphs graph = new Graphs(); Assert.Null(graph.GetNodes()); }
public void AddNodeToGraph() { ///Test that vertex can be added to graph Graphs graph = new Graphs(); Node testVertex = new Node("Test"); graph.AddNode(testVertex); List <Node> expected = new List <Node>(); expected.Add(testVertex); Assert.Equal(expected, graph.GetNodes()); }
public void RetreiveVertices() { ///test that method will return all vertices/Vertex Graphs graph = new Graphs(); Node testV1 = new Node("Test1"); Node testV2 = new Node("Test2"); graph.AddNode(testV1); graph.AddNode(testV2); graph.AddEdge(testV1, testV2, 4); List <Node> expected = new List <Node>(); expected.Add(testV1); expected.Add(testV2); Assert.Equal(expected, graph.GetNodes()); }
public void CanAddEdgeWithZeroWeight() { Node nodeOne = new Node("nodeOne"); Node nodeTwo = new Node("nodeTwo"); Node nodeThree = new Node("nodeThree"); Node nodeFour = new Node("nodeFour"); Node nodeFive = new Node("nodeFive"); Graphs myGraph = new Graphs(nodeOne); myGraph.AddEdge(nodeOne, new Tuple <Node, int>(nodeTwo, 0)); myGraph.AddEdge(nodeTwo, new Tuple <Node, int>(nodeThree, 0)); myGraph.AddEdge(nodeThree, new Tuple <Node, int>(nodeFour, 0)); myGraph.AddEdge(nodeFour, new Tuple <Node, int>(nodeFive, 0)); myGraph.AddEdge(nodeFive, new Tuple <Node, int>(nodeOne, 0)); Assert.NotEmpty(myGraph.GetNodes()); }
public void CanReturnListOfNodes() { Node nodeOne = new Node("nodeOne"); Node nodeTwo = new Node("nodeTwo"); Node nodeThree = new Node("nodeThree"); Node nodeFour = new Node("nodeFour"); Node nodeFive = new Node("nodeFive"); Graphs myGraph = new Graphs(nodeOne); myGraph.AddEdge(nodeOne, new Tuple <Node, int>(nodeTwo, 5)); myGraph.AddEdge(nodeTwo, new Tuple <Node, int>(nodeThree, 10)); myGraph.AddEdge(nodeThree, new Tuple <Node, int>(nodeFour, 15)); myGraph.AddEdge(nodeFour, new Tuple <Node, int>(nodeFive, 20)); myGraph.AddEdge(nodeFive, new Tuple <Node, int>(nodeOne, 25)); Assert.NotEmpty(myGraph.GetNodes()); }