}
public void testGraph() {
boolean verbose = TestConfig.verbose();
Table nodes = graph.getNodeTable();
Table edges = graph.getEdgeTable();
// check the basics
assertEquals(NNODES, graph.getNodeCount());
assertEquals(NEDGES, graph.getEdgeCount());
assertEquals(NHEADERS[0], graph.getNodeKeyField());
assertEquals(EHEADERS[0], graph.getEdgeSourceField());
assertEquals(EHEADERS[1], graph.getEdgeTargetField());
// check all nodes, basic data
Iterator niter = graph.nodes();
while ( niter.hasNext() ) {
Node node = (Node)niter.next();
int nrow = node.getRow();
if ( verbose ) System.out.print(nrow+"\t");
// check data members
for ( int i=0; i<NNODECOLS; ++i ) {
assertEquals(NODES[i][nrow], node.get(NHEADERS[i]));
assertEquals(NODES[i][nrow], nodes.get(nrow, NHEADERS[i]));
if ( verbose ) System.out.print(NHEADERS[i]+":"+NODES[i][nrow]+"\t");
}
if ( verbose ) {
System.out.print("in:"+node.getInDegree());
System.out.print("\t");
System.out.print("out:"+node.getOutDegree());
System.out.println();
}
// check degrees
assertEquals(node.getInDegree(), INDEGREE[nrow]);
assertEquals(graph.getInDegree(nrow), INDEGREE[nrow]);
assertEquals(node.getOutDegree(), OUTDEGREE[nrow]);
assertEquals(graph.getOutDegree(nrow), OUTDEGREE[nrow]);
// check edges
Iterator eiter = node.inEdges();
while ( eiter.hasNext() ) {
Edge edge = (Edge)eiter.next();
int erow = edge.getRow();
assertEquals(nrow, edge.getTargetNode().getRow());
assertEquals(nrow, graph.getTargetNode(erow));
}
eiter = node.outEdges();
while ( eiter.hasNext() ) {
Edge edge = (Edge)eiter.next();
int erow = edge.getRow();
assertEquals(nrow, edge.getSourceNode().getRow());
assertEquals(nrow, graph.getSourceNode(erow));
}
}
// check all edges, basic data
Iterator eiter = graph.edges();
while ( eiter.hasNext() ) {
Edge edge = (Edge)eiter.next();
int erow = edge.getRow();
// check data members
for ( int i=0; i<NEDGECOLS; ++i ) {
assertEquals(EDGES[i][erow], edge.get(EHEADERS[i]));
assertEquals(EDGES[i][erow], edges.get(erow, EHEADERS[i]));
}
// check nodes
Node s = edge.getSourceNode();
int srow = s.getRow();
assertEquals(srow, graph.getSourceNode(erow));
int sk = nodes.getInt(srow, NHEADERS[0]);
assertEquals(sk, edges.getInt(erow, EHEADERS[0]));
Node t = edge.getTargetNode();
int trow = t.getRow();
assertEquals(trow, graph.getTargetNode(erow));
int tk = nodes.getInt(trow, NHEADERS[0]);
assertEquals(tk, edges.getInt(erow, EHEADERS[1]));
assertEquals(srow, edge.getAdjacentNode(t).getRow());
assertEquals(trow, edge.getAdjacentNode(s).getRow());
assertEquals(srow, graph.getAdjacentNode(erow, trow));
assertEquals(trow, graph.getAdjacentNode(erow, srow));