Author: mes
Date: 2009-12-11 11:55:05 -0800 (Fri, 11 Dec 2009)
New Revision: 18742
Added:
corelibs/trunk/graph.dynamic/lib/junit-3.8.1.jar
corelibs/trunk/graph.dynamic/tests/
corelibs/trunk/graph.dynamic/tests/cytoscape/
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/AddRemoveTest.java
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/GraphSerializationTest.java
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/GraphTest.java
Removed:
corelibs/trunk/graph.dynamic/src/cytoscape/graph/dynamic/util/test/
Log:
converted old test applications into junit tests
Added: corelibs/trunk/graph.dynamic/lib/junit-3.8.1.jar
===================================================================
(Binary files differ)
Property changes on: corelibs/trunk/graph.dynamic/lib/junit-3.8.1.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/AddRemoveTest.java
===================================================================
---
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/AddRemoveTest.java
(rev 0)
+++
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/AddRemoveTest.java
2009-12-11 19:55:05 UTC (rev 18742)
@@ -0,0 +1,112 @@
+
+/*
+ Copyright (c) 2006, 2007, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+
+package cytoscape.graph.dynamic;
+
+import cytoscape.graph.dynamic.util.DynamicGraphFactory;
+
+import junit.framework.*;
+
+public class AddRemoveTest extends TestCase {
+
+ public void testAddRemove() {
+ 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;
+
+ 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();
+ }
+ }
+ }
+}
Added:
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/GraphSerializationTest.java
===================================================================
---
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/GraphSerializationTest.java
(rev 0)
+++
corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/GraphSerializationTest.java
2009-12-11 19:55:05 UTC (rev 18742)
@@ -0,0 +1,183 @@
+
+/*
+ Copyright (c) 2006, 2007, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+
+package cytoscape.graph.dynamic;
+
+import cytoscape.graph.dynamic.DynamicGraph;
+import cytoscape.graph.dynamic.util.DynamicGraphFactory;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+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.");
+
+ 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");
+ }
+
+ graph = DynamicGraphFactory.instantiateDynamicGraph();
+
+ int[] nodes = new int[10];
+
+ for (int i = 0; i < nodes.length; i++)
+ nodes[i] = graph.nodeCreate();
+
+ 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);
+
+ 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");
+ }
+ }
+
+ {
+ 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();
+
+ 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 += 2)
+ graph.nodeRemove(nodes[i]);
+
+ 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");
+
+ ByteArrayOutputStream byteOut = new
ByteArrayOutputStream();
+ ObjectOutputStream objOut = new
ObjectOutputStream(byteOut);
+ long millisBegin = System.currentTimeMillis();
+ objOut.writeObject(graph);
+ objOut.flush();
+ objOut.close();
+
+ long millisEnd = System.currentTimeMillis();
+ System.out.println("serializing graph took " +
(millisEnd - millisBegin)
+ + " milliseconds");
+
+ byte[] serializedData = byteOut.toByteArray();
+ System.out.println("in serialized form, graph takes " +
serializedData.length
+ + " bytes");
+
+ ByteArrayInputStream byteIn = new
ByteArrayInputStream(serializedData);
+ millisBegin = System.currentTimeMillis();
+
+ 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");
+ }
+
+ {
+ DynamicGraph[] graphs = new DynamicGraph[2];
+ graphs[0] =
DynamicGraphFactory.instantiateDynamicGraph();
+ graphs[1] = graphs[0];
+
+ ByteArrayOutputStream byteOut = new
ByteArrayOutputStream();
+ ObjectOutputStream objOut = new
ObjectOutputStream(byteOut);
+ objOut.writeObject(graphs);
+ objOut.flush();
+ objOut.close();
+
+ ByteArrayInputStream byteIn = new
ByteArrayInputStream(byteOut.toByteArray());
+ ObjectInputStream objIn = new ObjectInputStream(byteIn);
+ graphs = (DynamicGraph[]) objIn.readObject();
+ objIn.close();
+
+ if (graphs.length != 2) {
+ throw new IllegalStateException("graphs.length
is not 2");
+ }
+
+ 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());
+ }
+ }
+}
Added: corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/GraphTest.java
===================================================================
--- corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/GraphTest.java
(rev 0)
+++ corelibs/trunk/graph.dynamic/tests/cytoscape/graph/dynamic/GraphTest.java
2009-12-11 19:55:05 UTC (rev 18742)
@@ -0,0 +1,239 @@
+
+/*
+ Copyright (c) 2006, 2007, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+
+package cytoscape.graph.dynamic;
+
+import cytoscape.graph.dynamic.util.DynamicGraphFactory;
+
+import cytoscape.util.intr.IntEnumerator;
+import cytoscape.util.intr.IntIterator;
+
+import junit.framework.*;
+
+public class GraphTest extends TestCase {
+
+ public void testGraph() {
+ final DynamicGraph graph =
DynamicGraphFactory.instantiateDynamicGraph();
+ System.out.println("Creating 10 nodes...");
+
+ for (int i = 0; i < 10; i++)
+ graph.nodeCreate();
+
+ IntEnumerator nodesEnum = graph.nodes();
+ int index = -1;
+ int[] nodes = new int[nodesEnum.numRemaining()];
+ System.out.print("Here are the nodes: ");
+
+ while (nodesEnum.numRemaining() > 0) {
+ nodes[++index] = nodesEnum.nextInt();
+ System.out.print(nodes[index] + " ");
+ }
+
+ System.out.println();
+ System.out.println();
+
+ boolean[] edgesDir = new boolean[] {
+ false, true, true, true, false, true,
false, false, true, true,
+ false, false, true, false, true
+ };
+ int[][] edgesDef = new int[][] {
+ { 2, 5 },
+ { 0, 8 },
+ { 4, 1 },
+ { 9, 0 },
+ { 9, 0 },
+ { 0, 8 },
+ { 1, 4 },
+ { 2, 2 },
+ { 7, 7 },
+ { 1, 1 },
+ { 3, 1 },
+ { 7, 2 },
+ { 1, 0 },
+ { 8, 5 },
+ { 4, 9 }
+ };
+
+ for (int i = 0; i < edgesDir.length; i++) {
+ System.out.println("Creating " + (edgesDir[i] ?
"directed" : "undirected")
+ + " edge from node " +
nodes[edgesDef[i][0]] + " to node "
+ + nodes[edgesDef[i][1]] + "...");
+ graph.edgeCreate(nodes[edgesDef[i][0]],
nodes[edgesDef[i][1]], edgesDir[i]);
+ }
+
+ IntEnumerator edgesEnum = graph.edges();
+ System.out.println();
+ System.out.println("Here are the edges:");
+
+ while (edgesEnum.numRemaining() > 0) {
+ final int edge = edgesEnum.nextInt();
+ System.out.println(((graph.edgeType(edge) ==
DynamicGraph.DIRECTED_EDGE) ? "Directed"
+
: "Undirected")
+ + " edge " + edge + " with source "
+ graph.edgeSource(edge)
+ + " and target " +
graph.edgeTarget(edge) + ".");
+ }
+
+ System.out.println();
+ System.out.println("All adjacent edges...");
+ nodesEnum = graph.nodes();
+
+ while (nodesEnum.numRemaining() > 0) {
+ final int node = nodesEnum.nextInt();
+ IntEnumerator adjEdges = graph.edgesAdjacent(node,
true, true, true);
+ System.out.print("For node " + node + ": ");
+
+ while (adjEdges.numRemaining() > 0) {
+ final int edge = adjEdges.nextInt();
+ System.out.print(edge + " ");
+ }
+
+ System.out.println();
+ }
+
+ System.out.println();
+ System.out.println("All undirected adjacent edges...");
+ nodesEnum = graph.nodes();
+
+ while (nodesEnum.numRemaining() > 0) {
+ final int node = nodesEnum.nextInt();
+ IntEnumerator adjEdges = graph.edgesAdjacent(node,
false, false, true);
+ System.out.print("For node " + node + ": ");
+
+ while (adjEdges.numRemaining() > 0) {
+ final int edge = adjEdges.nextInt();
+ System.out.print(edge + " ");
+ }
+
+ System.out.println();
+ }
+
+ System.out.println();
+ System.out.println("All undirected and incoming adjacent
edges...");
+ nodesEnum = graph.nodes();
+
+ while (nodesEnum.numRemaining() > 0) {
+ final int node = nodesEnum.nextInt();
+ IntEnumerator adjEdges = graph.edgesAdjacent(node,
false, true, true);
+ System.out.print("For node " + node + ": ");
+
+ while (adjEdges.numRemaining() > 0) {
+ final int edge = adjEdges.nextInt();
+ System.out.print(edge + " ");
+ }
+
+ System.out.println();
+ }
+
+ System.out.println();
+ System.out.println("All outgoing adjacent edges...");
+ nodesEnum = graph.nodes();
+
+ while (nodesEnum.numRemaining() > 0) {
+ final int node = nodesEnum.nextInt();
+ IntEnumerator adjEdges = graph.edgesAdjacent(node,
true, false, false);
+ System.out.print("For node " + node + ": ");
+
+ while (adjEdges.numRemaining() > 0) {
+ final int edge = adjEdges.nextInt();
+ System.out.print(edge + " ");
+ }
+
+ System.out.println();
+ }
+
+ System.out.println();
+ System.out.println("All outgoing and incoming adjacent
edges...");
+ nodesEnum = graph.nodes();
+
+ while (nodesEnum.numRemaining() > 0) {
+ final int node = nodesEnum.nextInt();
+ IntEnumerator adjEdges = graph.edgesAdjacent(node,
true, true, false);
+ System.out.print("For node " + node + ": ");
+
+ while (adjEdges.numRemaining() > 0) {
+ final int edge = adjEdges.nextInt();
+ System.out.print(edge + " ");
+ }
+
+ System.out.println();
+ }
+
+ System.out.println();
+
+ for (int i = 0; i < nodes.length; i++)
+ if ((i % 3) == 0) {
+ System.out.println("Removing node " + nodes[i]
+ "...");
+ graph.nodeRemove(nodes[i]);
+ }
+
+ System.out.println();
+ System.out.println("All adjacent edges...");
+ nodesEnum = graph.nodes();
+
+ while (nodesEnum.numRemaining() > 0) {
+ final int node = nodesEnum.nextInt();
+ IntEnumerator adjEdges = graph.edgesAdjacent(node,
true, true, true);
+ System.out.print("For node " + node + ": ");
+
+ while (adjEdges.numRemaining() > 0) {
+ final int edge = adjEdges.nextInt();
+ System.out.print(edge + " ");
+ }
+
+ System.out.println();
+ }
+
+ System.out.println();
+ nodesEnum = graph.nodes();
+
+ while (nodesEnum.numRemaining() > 0) {
+ final int node0 = nodesEnum.nextInt();
+ IntEnumerator nodesEnum2 = graph.nodes();
+
+ while (nodesEnum2.numRemaining() > 0) {
+ final int node1 = nodesEnum2.nextInt();
+ IntIterator connectingEdges =
graph.edgesConnecting(node0, node1, true, true, true);
+ System.out.print("All edges connecting node " +
node0 + " with node " + node1
+ + ": ");
+
+ while (connectingEdges.hasNext())
+
System.out.print(connectingEdges.nextInt() + " ");
+
+ System.out.println();
+ }
+ }
+ }
+}
--
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.