public void test_1() {
int nnodes = 100;
Node[] ends = GraphTestUtil.buildNoBifurcations(builder(), nnodes);
final int suspend = 50;;
CountingWalker walker = new CountingWalker() {
private int m_mode = 0;
public int visit(Graphable element, GraphTraversal traversal) {
super.visit(element, traversal);
if (m_mode == 0) {
//check for stopping node
if (element.getID() == suspend) {
m_mode++;
return(GraphTraversal.SUSPEND);
}
}
else if (m_mode == 1) {
//check first node after continue
assertTrue(element.getID() == suspend + 1);
m_mode++;
}
return(GraphTraversal.CONTINUE);
}
};
NoBifurcationIterator iterator = createIterator();
iterator.setSource(ends[0]);
BasicGraphTraversal traversal = new BasicGraphTraversal(
builder().getGraph(), walker, iterator
);
traversal.init();
traversal.traverse();
//stopping node should be visited and nodes with greater id should not
GraphVisitor visitor = new GraphVisitor() {
public int visit(Graphable component) {
if (component.getID() <= suspend) assertTrue(component.isVisited());
else assertTrue(!component.isVisited());
return(0);
}
};
builder().getGraph().visitNodes(visitor);
assertTrue(walker.getCount() == nnodes-suspend+1);
traversal.traverse();
//every node should now be visited
visitor = new GraphVisitor() {
public int visit(Graphable component) {
assertTrue(component.isVisited());
return(0);
}
};
builder().getGraph().visitNodes(visitor);
assertTrue(walker.getCount() == nnodes);
}