*/
public void test_0() {
final Coordinate base = new Coordinate(0d,0d);
final int n = 100;
for (int i = 1; i <= n; i++) {
Edge e = (Edge)generator().add(
new LineSegment(
new Coordinate(base.x + (i-1), base.y + (i-1)),
new Coordinate(base.x + i, base.y + i)
)
);
e.setID(i-1);
e.getNodeA().setID(i-1);
e.getNodeB().setID(i);
}
Graph built = generator().getGraph();
//ensure correct graph structure
assertTrue(built.getEdges().size() == n);
assertTrue(built.getNodes().size() == n+1);
GraphVisitor visitor = new GraphVisitor() {
public int visit(Graphable component) {
DirectedNode node = (DirectedNode)component;
Coordinate c = (Coordinate)node.getObject();
if (node.getDegree() == 1) {
assertTrue(
(node.getID()==0&&node.getInDegree()==0&&node.getOutDegree()==1)||
(node.getID()==n&&node.getInDegree()==1&&node.getOutDegree()==0)
);
}
else {
assertTrue(node.getInDegree() == 1 && node.getOutDegree() == 1);
}
assertTrue(
c.x == base.x + node.getID() && c.y == base.y + node.getID()
);
return(0);
}
};
built.visitNodes(visitor);
//ensure correct edge direction
visitor = new GraphVisitor() {
public int visit(Graphable component) {
DirectedEdge e = (DirectedEdge)component;
Coordinate c0 = (Coordinate)e.getInNode().getObject();
Coordinate c1 = (Coordinate)e.getOutNode().getObject();
LineSegment ls = (LineSegment)e.getObject();
assertTrue(ls.p0.equals(c0) && ls.p1.equals(c1));
return(0);
}