Author: mes
Date: 2009-12-11 12:12:00 -0800 (Fri, 11 Dec 2009)
New Revision: 18743
Modified:
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/AddRemoveTest.java
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/GraphSerializationTest.java
Log:
cleaned up some unit tests
Modified:
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/AddRemoveTest.java
===================================================================
---
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/AddRemoveTest.java
2009-12-11 19:55:05 UTC (rev 18742)
+++
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/AddRemoveTest.java
2009-12-11 20:12:00 UTC (rev 18743)
@@ -46,67 +46,26 @@
final DynamicGraph graph =
DynamicGraphFactory.instantiateDynamicGraph();
final int[][] nodesArr = new int[][] { new int[100000], new
int[99980], new int[100010] };
final int[] edges = new int[1000000];
- final int iterations = 10;
+ final int iterations = 3;
for (int foo = 0; foo < iterations; foo++) {
- boolean print = false;
- if ((foo % 10) == 0) {
- print = true;
- }
-
- if (print) {
- System.out.println("at add/remove iteration " +
(foo + 1) + " of " + iterations);
- }
-
- if (print) {
- System.out.println("creating nodes");
- }
-
final int[] nodes = nodesArr[foo % nodesArr.length];
for (int i = 0; i < nodes.length; i++)
nodes[i] = graph.nodeCreate();
- if (print) {
- System.out.println("creating edges");
- }
-
for (int i = 0; i < edges.length; i++)
edges[i] = graph.edgeCreate(nodes[i %
nodes.length], nodes[(i * 3) % nodes.length],
true);
- if (print) {
- System.out.println("in graph: " +
graph.nodes().numRemaining() + " nodes and "
- +
graph.edges().numRemaining() + " edges");
- }
-
- if (print) {
- System.out.println();
- }
-
- if (print) {
- System.out.println("removing edges");
- }
-
for (int i = 0; i < edges.length; i++)
graph.edgeRemove(edges[i]);
- if (print) {
- System.out.println("removing nodes");
- }
for (int i = 0; i < nodes.length; i++)
graph.nodeRemove(nodes[i]);
- if (print) {
- System.out.println("in graph: " +
graph.nodes().numRemaining() + " nodes and "
- +
graph.edges().numRemaining() + " edges");
- }
-
- if (print) {
- System.out.println();
- }
}
}
}
Modified:
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/GraphSerializationTest.java
===================================================================
---
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/GraphSerializationTest.java
2009-12-11 19:55:05 UTC (rev 18742)
+++
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/GraphSerializationTest.java
2009-12-11 20:12:00 UTC (rev 18743)
@@ -36,7 +36,6 @@
package cytoscape.graph.dynamic;
-import cytoscape.graph.dynamic.DynamicGraph;
import cytoscape.graph.dynamic.util.DynamicGraphFactory;
import java.io.ByteArrayInputStream;
@@ -47,137 +46,124 @@
import junit.framework.*;
public class GraphSerializationTest extends TestCase {
- public void testGraphSerialization() {
- try {
- {
- DynamicGraph graph =
DynamicGraphFactory.instantiateDynamicGraph();
- ByteArrayOutputStream byteOut = new
ByteArrayOutputStream();
- ObjectOutputStream objOut = new
ObjectOutputStream(byteOut);
- objOut.writeObject(graph);
- objOut.flush();
- objOut.close();
- System.out.println("An empty graph takes " +
byteOut.size()
- + " bytes in serialized form.");
+ public void testGraphSerialization() throws Exception {
+ DynamicGraph graph =
DynamicGraphFactory.instantiateDynamicGraph();
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ ObjectOutputStream objOut = new ObjectOutputStream(byteOut);
+ objOut.writeObject(graph);
+ objOut.flush();
+ objOut.close();
+ System.out.println("An empty graph takes " + byteOut.size()
+ + " bytes in serialized form.");
- ByteArrayInputStream byteIn = new
ByteArrayInputStream(byteOut.toByteArray());
- ObjectInputStream objIn = new ObjectInputStream(byteIn);
- graph = (DynamicGraph) objIn.readObject();
- objIn.close();
+ ByteArrayInputStream byteIn = new
ByteArrayInputStream(byteOut.toByteArray());
+ ObjectInputStream objIn = new ObjectInputStream(byteIn);
+ graph = (DynamicGraph) objIn.readObject();
+ objIn.close();
- if ((graph.nodes().numRemaining() != 0) ||
(graph.edges().numRemaining() != 0)) {
- throw new IllegalStateException("expected
restored graph to be empty");
- }
+ assertEquals("expected restored graph to be empty",
0,graph.nodes().numRemaining());
+ assertEquals("expected restored graph to be empty",
0,graph.edges().numRemaining());
- graph = DynamicGraphFactory.instantiateDynamicGraph();
+ graph = DynamicGraphFactory.instantiateDynamicGraph();
- int[] nodes = new int[10];
+ int[] nodes = new int[10];
- for (int i = 0; i < nodes.length; i++)
- nodes[i] = graph.nodeCreate();
+ for (int i = 0; i < nodes.length; i++)
+ nodes[i] = graph.nodeCreate();
- int[] edges = new int[20];
+ int[] edges = new int[20];
- for (int i = 0; i < edges.length; i++)
- edges[i] = graph.edgeCreate(nodes[i %
nodes.length], nodes[(i * 3) % nodes.length],
- true);
+ for (int i = 0; i < edges.length; i++)
+ edges[i] = graph.edgeCreate(nodes[i % nodes.length],
nodes[(i * 3) % nodes.length],
+ true);
- byteOut = new ByteArrayOutputStream();
- objOut = new ObjectOutputStream(byteOut);
- objOut.writeObject(graph);
- objOut.flush();
- objOut.close();
- System.out.println("A graph with " + nodes.length + "
nodes and " + edges.length
- + " edges takes " + byteOut.size() +
" bytes in serialized form.");
- byteIn = new
ByteArrayInputStream(byteOut.toByteArray());
- objIn = new ObjectInputStream(byteIn);
- graph = (DynamicGraph) objIn.readObject();
- objIn.close();
+ byteOut = new ByteArrayOutputStream();
+ objOut = new ObjectOutputStream(byteOut);
+ objOut.writeObject(graph);
+ objOut.flush();
+ objOut.close();
+ System.out.println("A graph with " + nodes.length + " nodes and
" + edges.length
+ + " edges takes " + byteOut.size() + " bytes
in serialized form.");
+ byteIn = new ByteArrayInputStream(byteOut.toByteArray());
+ objIn = new ObjectInputStream(byteIn);
+ graph = (DynamicGraph) objIn.readObject();
+ objIn.close();
- if ((graph.nodes().numRemaining() != nodes.length)
- || (graph.edges().numRemaining() != edges.length)) {
- throw new IllegalStateException("expected
restored graph to have proper number of nodes and edges");
- }
- }
+ assertEquals("expected restored graph to have proper number of
nodes",
+ graph.nodes().numRemaining(), nodes.length);
+ assertEquals("expected restored graph to have proper number of
edges",
+ graph.edges().numRemaining(), edges.length);
- {
- DynamicGraph graph =
DynamicGraphFactory.instantiateDynamicGraph();
- int[] nodes = new int[100000];
- int[] edges = new int[1000000];
+ }
- for (int i = 0; i < nodes.length; i++)
- nodes[i] = graph.nodeCreate();
+ public void testGraphSerialization2() throws Exception {
+ DynamicGraph graph =
DynamicGraphFactory.instantiateDynamicGraph();
+ int[] nodes = new int[100000];
+ int[] edges = new int[1000000];
- for (int i = 0; i < edges.length; i++)
- edges[i] = graph.edgeCreate(nodes[i %
nodes.length], nodes[(i * 3) % nodes.length],
- true);
+ for (int i = 0; i < nodes.length; i++)
+ nodes[i] = graph.nodeCreate();
- for (int i = 0; i < nodes.length; i += 2)
- graph.nodeRemove(nodes[i]);
+ for (int i = 0; i < edges.length; i++)
+ edges[i] = graph.edgeCreate(nodes[i % nodes.length],
nodes[(i * 3) % nodes.length],
+ true);
- System.out.println("graph has " +
graph.nodes().numRemaining() + " nodes and "
- + graph.edges().numRemaining() + "
edges");
- System.out.println("at one point graph had " +
nodes.length + " nodes and "
- + edges.length + " edges");
+ for (int i = 0; i < nodes.length; i += 2)
+ graph.nodeRemove(nodes[i]);
- ByteArrayOutputStream byteOut = new
ByteArrayOutputStream();
- ObjectOutputStream objOut = new
ObjectOutputStream(byteOut);
- long millisBegin = System.currentTimeMillis();
- objOut.writeObject(graph);
- objOut.flush();
- objOut.close();
+ System.out.println("graph has " + graph.nodes().numRemaining()
+ " nodes and "
+ + graph.edges().numRemaining() + " edges");
+ System.out.println("at one point graph had " + nodes.length + "
nodes and "
+ + edges.length + " edges");
- long millisEnd = System.currentTimeMillis();
- System.out.println("serializing graph took " +
(millisEnd - millisBegin)
- + " milliseconds");
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ ObjectOutputStream objOut = new ObjectOutputStream(byteOut);
+ long millisBegin = System.currentTimeMillis();
+ objOut.writeObject(graph);
+ objOut.flush();
+ objOut.close();
- byte[] serializedData = byteOut.toByteArray();
- System.out.println("in serialized form, graph takes " +
serializedData.length
- + " bytes");
+ long millisEnd = System.currentTimeMillis();
+ System.out.println("serializing graph took " + (millisEnd -
millisBegin)
+ + " milliseconds");
- ByteArrayInputStream byteIn = new
ByteArrayInputStream(serializedData);
- millisBegin = System.currentTimeMillis();
+ byte[] serializedData = byteOut.toByteArray();
+ System.out.println("in serialized form, graph takes " +
serializedData.length
+ + " bytes");
- ObjectInputStream objIn = new ObjectInputStream(byteIn);
- graph = (DynamicGraph) objIn.readObject();
- objIn.close();
- millisEnd = System.currentTimeMillis();
- System.out.println("deserializeing graph took " +
(millisEnd - millisBegin)
- + " milliseconds");
- System.out.println("deserialized graph has " +
graph.nodes().numRemaining()
- + " nodes and " +
graph.edges().numRemaining() + " edges");
- }
+ ByteArrayInputStream byteIn = new
ByteArrayInputStream(serializedData);
+ millisBegin = System.currentTimeMillis();
- {
- DynamicGraph[] graphs = new DynamicGraph[2];
- graphs[0] =
DynamicGraphFactory.instantiateDynamicGraph();
- graphs[1] = graphs[0];
+ ObjectInputStream objIn = new ObjectInputStream(byteIn);
+ graph = (DynamicGraph) objIn.readObject();
+ objIn.close();
+ millisEnd = System.currentTimeMillis();
+ System.out.println("deserializeing graph took " + (millisEnd -
millisBegin)
+ + " milliseconds");
+ System.out.println("deserialized graph has " +
graph.nodes().numRemaining()
+ + " nodes and " +
graph.edges().numRemaining() + " edges");
+ }
- ByteArrayOutputStream byteOut = new
ByteArrayOutputStream();
- ObjectOutputStream objOut = new
ObjectOutputStream(byteOut);
- objOut.writeObject(graphs);
- objOut.flush();
- objOut.close();
+
+ public void testGraphSerialization3() throws Exception {
+ DynamicGraph[] graphs = new DynamicGraph[2];
+ graphs[0] = DynamicGraphFactory.instantiateDynamicGraph();
+ graphs[1] = graphs[0];
- ByteArrayInputStream byteIn = new
ByteArrayInputStream(byteOut.toByteArray());
- ObjectInputStream objIn = new ObjectInputStream(byteIn);
- graphs = (DynamicGraph[]) objIn.readObject();
- objIn.close();
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ ObjectOutputStream objOut = new ObjectOutputStream(byteOut);
+ objOut.writeObject(graphs);
+ objOut.flush();
+ objOut.close();
- if (graphs.length != 2) {
- throw new IllegalStateException("graphs.length
is not 2");
- }
+ ByteArrayInputStream byteIn = new
ByteArrayInputStream(byteOut.toByteArray());
+ ObjectInputStream objIn = new ObjectInputStream(byteIn);
+ graphs = (DynamicGraph[]) objIn.readObject();
+ objIn.close();
- if ((graphs[0] == null) || (graphs[1] == null)) {
- throw new NullPointerException();
- }
-
- if (graphs[0] != graphs[1]) {
- throw new IllegalStateException("not the same
reference");
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
+ assertEquals("graphs.length is 2", 2, graphs.length);
+ assertFalse( "graph 0 is null", graphs[0] == null );
+ assertFalse( "graph 1 is null", graphs[1] == null );
+ assertTrue( "graph 0 is equal to graph 1 ", graphs[0] ==
graphs[1]);
}
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.