GraphSearch { public void searchBFS(GraphNode<T> root) { IQueue<GraphNode<T>> queue = new Queue<GraphNode<T>>(); if (searchPathBFS.length() > 0) { searchPathBFS.append("->"); } searchPathBFS.append(root.data.toString()); root.visited = true; queue.enqueue(root); while(!queue.isEmpty()){ GraphNode<T> r = queue.dequeue(); for (GraphNode<T> node : r.neighborList) { if (!node.visited) { searchPathBFS.append("->"); searchPathBFS.append(node.data.toString()); node.visited = true; queue.enqueue(node); } } } }  void searchDFS(GraphNode<T> root); void searchBFS(GraphNode<T> root); public StringBuffer searchPathDFS; public StringBuffer searchPathBFS; }
@Test public void searchBFSTest(){ GraphSearch<Integer> graphSearch = new GraphSearch<Integer>(); graphSearch.searchBFS(node1); String expectedSearchPath = "1->2->3->4->5->6->7->8->9->10"; Assert.assertEquals(expectedSearchPath, graphSearch.searchPathBFS.toString()); }