*
*/
public void test_1() {
final int k = 5;
Object[] obj = GraphTestUtil.buildPerfectBinaryTree(builder(), k);
final Node root = (Node)obj[0];
final Map obj2node = (Map)obj[1];
try {
File victim = File.createTempFile( "graph", null );
victim.deleteOnExit();
m_serializer.setProperty(SerializedReaderWriter.FILENAME, victim.getAbsolutePath() );
m_serializer.write(builder().getGraph());
Graph before = builder().getGraph();
Graph after = m_serializer.read();
//ensure same number of nodes and edges
assertTrue(before.getNodes().size() == after.getNodes().size());
assertTrue(before.getEdges().size() == after.getEdges().size());
//ensure same structure
GraphVisitor visitor = new GraphVisitor() {
public int visit(Graphable component) {
Node n = (Node)component;
String id = (String)n.getObject();
assertTrue(obj2node.get(id) != null);
StringTokenizer st = new StringTokenizer(id, ".");
if (st.countTokens() == 1) {
//root
assertTrue(n.getDegree() == 2);
Node n0 = ((Edge)n.getEdges().get(0)).getOtherNode(n);
Node n1 = ((Edge)n.getEdges().get(1)).getOtherNode(n);
assertTrue(
n0.getObject().equals("0.0") && n1.getObject().equals("0.1")
|| n0.getObject().equals("0.1") && n1.getObject().equals("0.0")
);
}
else if (st.countTokens() == k+1) {
//leaf
assertTrue(n.getDegree() == 1);
Node parent = ((Edge)n.getEdges().get(0)).getOtherNode(n);
String parentid = (String)parent.getObject();
assertTrue(parentid.equals(id.substring(0, id.length()-2)));
}
else {
//internal