}
@Test
public void testJSON() {
FlexibleUndirectedGraph graph = new FlexibleUndirectedGraph();
int nodes = 52;
for (int i = 0; i < nodes; i++) {
graph.addNode();
}
int[][] edges = new int[][] { { 0, 9 }, { 0, 10 }, { 0, 11 },
{ 0, 12 }, { 0, 13 }, { 0, 17 }, { 0, 18 }, { 0, 19 },
{ 0, 20 }, { 0, 24 }, { 0, 30 }, { 0, 41 }, { 0, 45 },
{ 0, 46 }, { 0, 47 }, { 0, 48 }, { 1, 9 }, { 1, 10 },
{ 1, 11 }, { 1, 12 }, { 1, 17 }, { 1, 18 }, { 1, 19 },
{ 1, 20 }, { 1, 24 }, { 1, 30 }, { 1, 37 }, { 1, 41 },
{ 1, 45 }, { 1, 46 }, { 1, 47 }, { 1, 48 }, { 1, 49 },
{ 2, 9 }, { 2, 10 }, { 2, 11 }, { 2, 14 }, { 2, 17 },
{ 2, 18 }, { 2, 19 }, { 2, 20 }, { 2, 24 }, { 2, 36 },
{ 2, 41 }, { 2, 45 }, { 2, 46 }, { 2, 47 }, { 2, 48 },
{ 2, 49 }, { 3, 5 }, { 3, 9 }, { 3, 10 }, { 3, 11 }, { 3, 14 },
{ 3, 17 }, { 3, 18 }, { 3, 19 }, { 3, 20 }, { 3, 24 },
{ 3, 36 }, { 3, 41 }, { 3, 45 }, { 3, 46 }, { 3, 47 },
{ 3, 48 }, { 4, 11 }, { 4, 18 }, { 4, 22 }, { 4, 28 },
{ 4, 40 }, { 4, 41 }, { 4, 44 }, { 4, 45 }, { 4, 46 },
{ 4, 50 }, { 4, 51 }, { 5, 14 }, { 5, 24 }, { 5, 36 },
{ 5, 41 }, { 5, 45 }, { 5, 46 }, { 5, 47 }, { 5, 48 },
{ 6, 18 }, { 6, 46 }, { 6, 51 }, { 7, 12 }, { 7, 24 },
{ 7, 31 }, { 7, 34 }, { 7, 37 }, { 7, 39 }, { 7, 41 },
{ 7, 45 }, { 7, 46 }, { 7, 47 }, { 8, 24 }, { 8, 41 },
{ 8, 46 }, { 8, 47 }, { 9, 15 }, { 9, 22 }, { 9, 26 },
{ 9, 28 }, { 9, 34 }, { 9, 35 }, { 9, 36 }, { 9, 40 },
{ 9, 41 }, { 9, 44 }, { 9, 46 }, { 9, 51 }, { 10, 13 },
{ 10, 15 }, { 10, 16 }, { 10, 21 }, { 10, 23 }, { 10, 26 },
{ 10, 31 }, { 10, 34 }, { 10, 36 }, { 10, 39 }, { 10, 40 },
{ 10, 41 }, { 10, 44 }, { 10, 45 }, { 10, 46 }, { 10, 50 },
{ 10, 51 }, { 11, 18 }, { 11, 35 }, { 11, 36 }, { 11, 46 },
{ 11, 51 }, { 12, 27 }, { 12, 34 }, { 12, 36 }, { 12, 40 },
{ 12, 41 }, { 12, 44 }, { 12, 45 }, { 12, 46 }, { 12, 50 },
{ 12, 51 }, { 13, 17 }, { 13, 28 }, { 13, 34 }, { 13, 35 },
{ 13, 41 }, { 13, 46 }, { 14, 31 }, { 14, 34 }, { 14, 37 },
{ 14, 39 }, { 14, 41 }, { 14, 45 }, { 14, 46 }, { 14, 47 },
{ 14, 49 }, { 15, 35 }, { 15, 46 }, { 15, 48 }, { 15, 51 },
{ 16, 17 }, { 16, 28 }, { 16, 34 }, { 16, 35 }, { 16, 40 },
{ 16, 41 }, { 16, 44 }, { 16, 46 }, { 16, 51 }, { 17, 26 },
{ 17, 34 }, { 17, 36 }, { 17, 40 }, { 17, 41 }, { 17, 44 },
{ 17, 46 }, { 17, 51 }, { 19, 26 }, { 19, 27 }, { 19, 31 },
{ 19, 34 }, { 19, 36 }, { 19, 39 }, { 19, 40 }, { 19, 41 },
{ 19, 44 }, { 19, 45 }, { 19, 46 }, { 19, 50 }, { 19, 51 },
{ 20, 21 }, { 20, 23 }, { 20, 26 }, { 20, 34 }, { 20, 36 },
{ 20, 40 }, { 20, 41 }, { 20, 44 }, { 20, 45 }, { 20, 46 },
{ 20, 50 }, { 20, 51 }, { 21, 28 }, { 21, 35 }, { 21, 51 },
{ 22, 48 }, { 22, 51 }, { 23, 35 }, { 23, 36 }, { 23, 40 },
{ 23, 41 }, { 23, 44 }, { 23, 51 }, { 24, 31 }, { 24, 34 },
{ 24, 35 }, { 24, 36 }, { 24, 40 }, { 24, 41 }, { 24, 44 },
{ 24, 45 }, { 24, 51 }, { 25, 41 }, { 25, 45 }, { 26, 35 },
{ 26, 48 }, { 26, 51 }, { 27, 34 }, { 27, 35 }, { 27, 39 },
{ 27, 49 }, { 28, 36 }, { 28, 48 }, { 28, 51 }, { 29, 41 },
{ 29, 45 }, { 30, 34 }, { 30, 36 }, { 30, 39 }, { 30, 40 },
{ 30, 41 }, { 30, 44 }, { 30, 45 }, { 30, 50 }, { 30, 51 },
{ 31, 34 }, { 31, 36 }, { 31, 40 }, { 31, 41 }, { 31, 44 },
{ 31, 51 }, { 33, 49 }, { 34, 40 }, { 34, 51 }, { 35, 36 },
{ 35, 51 }, { 37, 50 }, { 39, 45 }, { 39, 51 }, { 40, 51 },
{ 44, 51 }, { 47, 50 }, { 47, 51 }, { 48, 51 }, { 49, 50 } };
for (int i = 0; i < edges.length; i++) {
graph.addEdge(edges[i][0], edges[i][1]);
}
try {
JSONObject json = graph.toJSON();
FlexibleUndirectedGraph graph2 = FlexibleUndirectedGraph
.fromJSON(json);
Assert.assertEquals("Wrong number of nodes", graph.getNodeNum(),
graph2.getNodeNum());
Assert.assertEquals("Wrong number of edges", graph.getEdgeNum(),
graph2.getEdgeNum());
for (int i = 0; i < edges.length; i++) {
Assert.assertEquals("Missed an edge in the new graph "
+ edges[i][0] + " " + edges[i][1], true,
graph2.isNeighbours(edges[i][0], edges[i][1]));
}
} catch (JSONException e) {
Assert.fail("Got error in JSON format " + e.getMessage());
}