[Plexus-svn] SF.net SVN: plexus:[893] trunk/plexus-graph/src/test/java/com/phoenixst/ plexus
Status: Alpha
Brought to you by:
rconner
|
From: <rc...@us...> - 2010-09-16 16:05:21
|
Revision: 893
http://plexus.svn.sourceforge.net/plexus/?rev=893&view=rev
Author: rconner
Date: 2010-09-16 16:05:12 +0000 (Thu, 16 Sep 2010)
Log Message:
-----------
fix the deserialization test
Modified Paths:
--------------
trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AbstractGraphTest.java
trunk/plexus-graph/src/test/java/com/phoenixst/plexus/DefaultGraphTest.java
Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AbstractGraphTest.java
===================================================================
--- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AbstractGraphTest.java 2010-09-16 15:49:47 UTC (rev 892)
+++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AbstractGraphTest.java 2010-09-16 16:05:12 UTC (rev 893)
@@ -61,7 +61,7 @@
/**
* The <code>Graph</code> to be tested.
*/
- Graph g = null;
+ private Graph g = null;
/**
* Contains all nodes accessed by the graph's
@@ -256,9 +256,39 @@
////////////////////////////////////////
- // helper methods
+ // Accessors
////////////////////////////////////////
+ protected Graph getGraph()
+ {
+ return g;
+ }
+
+ protected Object[] getPresentNodes()
+ {
+ return presentNodes.clone();
+ }
+
+ protected Object[] getNotPresentNodes()
+ {
+ return notPresentNodes.clone();
+ }
+
+ protected Edge[] getPresentEdges()
+ {
+ return presentEdges.clone();
+ }
+
+ protected Edge[] getNotPresentEdges()
+ {
+ return notPresentEdges.clone();
+ }
+
+
+ ////////////////////////////////////////
+ // Helper methods
+ ////////////////////////////////////////
+
private static boolean isSelfEdge( Edge edge )
{
Object tail = edge.getTail();
@@ -367,7 +397,7 @@
{
public void execute( Object object )
{
- g.degree( object );
+ getGraph().degree( object );
}
} );
}
@@ -390,7 +420,7 @@
{
public void execute( Object object )
{
- g.degree( object, GraphUtils.OUT_TRAVERSER_PREDICATE );
+ getGraph().degree( object, GraphUtils.OUT_TRAVERSER_PREDICATE );
}
} );
}
@@ -413,7 +443,7 @@
{
public void execute( Object object )
{
- g.degree( object, GraphUtils.IN_TRAVERSER_PREDICATE );
+ getGraph().degree( object, GraphUtils.IN_TRAVERSER_PREDICATE );
}
} );
}
@@ -625,7 +655,7 @@
{
public void execute( Object object )
{
- g.traverser( object, null );
+ getGraph().traverser( object, null );
}
} );
}
@@ -666,7 +696,7 @@
{
public void execute( Object object )
{
- g.traverser( object, GraphUtils.OUT_TRAVERSER_PREDICATE );
+ getGraph().traverser( object, GraphUtils.OUT_TRAVERSER_PREDICATE );
}
} );
}
@@ -707,7 +737,7 @@
{
public void execute( Object object )
{
- g.traverser( object, GraphUtils.IN_TRAVERSER_PREDICATE );
+ getGraph().traverser( object, GraphUtils.IN_TRAVERSER_PREDICATE );
}
} );
}
Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/DefaultGraphTest.java
===================================================================
--- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/DefaultGraphTest.java 2010-09-16 15:49:47 UTC (rev 892)
+++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/DefaultGraphTest.java 2010-09-16 16:05:12 UTC (rev 893)
@@ -21,6 +21,7 @@
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@@ -46,54 +47,14 @@
{
private static final Edge[] EMPTY_EDGE_ARRAY = new Edge[0];
- @SuppressWarnings( "unchecked" )
void set( final Graph graph )
{
- Graph defaultGraph = new DefaultGraph();
-
- Set< Object > goodNodes = new HashSet< Object >();
- Set< Edge > goodEdges = new HashSet< Edge >();
- Set< Edge > testEdges = new HashSet< Edge >();
- Set< Edge > badEdges = new HashSet< Edge >();
-
- // Assumption is that the graph being copied works just fine.
-
- for( Object node : graph.nodes( null ) ) {
- defaultGraph.addNode( node );
- goodNodes.add( node );
- }
-
- for( Edge edge : (Collection< Edge >) graph.edges( null ) ) {
- Object userObject = edge.getUserObject();
- Object tail = edge.getTail();
- Object head = edge.getHead();
- boolean isDirected = edge.isDirected();
- Edge testEdge = new SimpleObjectEdge( null, tail, head, isDirected );
- if( testEdges.add( testEdge ) ) {
- defaultGraph.addEdge( userObject, tail, head, isDirected );
- goodEdges.add( new SimpleObjectEdge( userObject, tail, head, isDirected ) );
- }
- }
-
- for( Object tail : graph.nodes( null ) ) {
- for( Object head : graph.nodes( null ) ) {
- Edge edge = new SimpleObjectEdge( null, tail, head, true );
- if( !testEdges.contains( edge ) ) {
- badEdges.add( edge );
- }
- edge = new SimpleObjectEdge( null, tail, head, false );
- if( !testEdges.contains( edge ) ) {
- badEdges.add( edge );
- }
- }
- }
-
- setGraph( defaultGraph );
-
- setPresentNodes( goodNodes.toArray() );
+ GraphSetup setup = new GraphSetup( graph );
+ setGraph( setup.defaultGraph );
+ setPresentNodes( setup.goodNodes.toArray() );
setNotPresentNodes( new Object() );
- setPresentEdges( goodEdges.toArray( EMPTY_EDGE_ARRAY ) );
- setNotPresentEdges( badEdges.toArray( EMPTY_EDGE_ARRAY ) );
+ setPresentEdges( setup.goodEdges.toArray( EMPTY_EDGE_ARRAY ) );
+ setNotPresentEdges( setup.badEdges.toArray( EMPTY_EDGE_ARRAY ) );
}
@Test
@@ -101,12 +62,12 @@
throws Exception
{
// Make sure we're not being tested inappropriately.
- assertEquals( DefaultGraph.class, g.getClass() );
+ assertEquals( DefaultGraph.class, getGraph().getClass() );
// Tests serialize->deserialize, and then compares with the original.
ByteArrayOutputStream bos = new ByteArrayOutputStream( 2048 );
ObjectOutputStream out = new ObjectOutputStream( bos );
- out.writeObject( g );
+ out.writeObject( getGraph() );
byte[] bytes = bos.toByteArray();
out.close();
@@ -119,17 +80,62 @@
// Run the copy through the same setup, so we can use
// present/notPresentNodes/Edges to test equality.
+ GraphSetup setup = new GraphSetup( (Graph) copy );
+ assertEquals( new HashSet< Object >( Arrays.asList( getPresentNodes() ) ), setup.goodNodes );
+ assertEquals( new HashSet< Edge >( Arrays.asList( getPresentEdges() ) ), setup.goodEdges );
+ assertEquals( new HashSet< Edge >( Arrays.asList( getNotPresentEdges() ) ), setup.badEdges );
+ }
- // FIXME
-// DefaultGraphTest copyTest = new DefaultGraphTest();
-// copyTest.setGraph( (Graph) copy );
+ private static class GraphSetup
+ {
+ Graph defaultGraph = new DefaultGraph();
+ Set< Object > goodNodes = new HashSet< Object >();
+ Set< Edge > goodEdges = new HashSet< Edge >();
+ Set< Edge > testEdges = new HashSet< Edge >();
+ Set< Edge > badEdges = new HashSet< Edge >();
-// assertEquals( new HashSet( Arrays.asList( presentNodes ) ), new HashSet( Arrays.asList( copyTest.presentNodes ) ) );
-// assertEquals( new HashSet( Arrays.asList( presentEdges ) ), new HashSet( Arrays.asList( copyTest.presentEdges ) ) );
-// assertEquals( new HashSet( Arrays.asList( notPresentEdges ) ), new HashSet( Arrays.asList( copyTest.notPresentEdges ) ) );
+ @SuppressWarnings( "unchecked" )
+ GraphSetup( Graph graph )
+ {
+ // Assumption is that the graph being copied works just fine.
+
+ for( Object node : graph.nodes( null ) ) {
+ defaultGraph.addNode( node );
+ goodNodes.add( node );
+ }
+
+ for( Edge edge : (Collection< Edge >) graph.edges( null ) ) {
+ Object userObject = edge.getUserObject();
+ Object tail = edge.getTail();
+ Object head = edge.getHead();
+ boolean isDirected = edge.isDirected();
+ Edge testEdge = new SimpleObjectEdge( null, tail, head, isDirected );
+ if( testEdges.add( testEdge ) ) {
+ defaultGraph.addEdge( userObject, tail, head, isDirected );
+ goodEdges.add( new SimpleObjectEdge( userObject, tail, head, isDirected ) );
+ }
+ }
+
+ for( Object tail : graph.nodes( null ) ) {
+ for( Object head : graph.nodes( null ) ) {
+ Edge edge = new SimpleObjectEdge( null, tail, head, true );
+ if( !testEdges.contains( edge ) ) {
+ badEdges.add( edge );
+ }
+ edge = new SimpleObjectEdge( null, tail, head, false );
+ if( !testEdges.contains( edge ) ) {
+ badEdges.add( edge );
+ }
+ }
+ }
+ }
}
+ ////////////////////////////////////////
+ // Test cases
+ ////////////////////////////////////////
+
public static class TestRandom_5_050 extends DefaultGraphTest
{
@Before
@@ -336,4 +342,5 @@
set( new Prism( 5, 5 ) );
}
}
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|