Thread: [Plexus-svn] SF.net SVN: plexus:[883] trunk/plexus-graph/src/test/java/com/phoenixst/ plexus
Status: Alpha
Brought to you by:
rconner
From: <rc...@us...> - 2010-09-15 16:09:24
|
Revision: 883 http://plexus.svn.sourceforge.net/plexus/?rev=883&view=rev Author: rconner Date: 2010-09-15 16:09:13 +0000 (Wed, 15 Sep 2010) Log Message: ----------- beginning to refactor test code, breaking the build Removed Paths: ------------- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AllTests.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/AllTests.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/AllTests.java Deleted: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AllTests.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AllTests.java 2010-09-15 16:07:22 UTC (rev 882) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AllTests.java 2010-09-15 16:09:13 UTC (rev 883) @@ -1,49 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, - * Inc. and others. All rights reserved. - * - * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE - * COMMON PUBLIC LICENSE ("AGREEMENT") WHICH ACCOMPANIES IT. ANY - * USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES - * RECIPIENT'S ACCEPTANCE OF THE AGREEMENT. - * - * The license text can also be found at - * http://opensource.org/licenses/cpl.php - */ - -package com.phoenixst.plexus; - -import junit.framework.Test; -import junit.framework.TestSuite; - - -/** - * Test suite for all tests in this package. - * - * @author Ray A. Conner - */ -public class AllTests -{ - - private AllTests() - { - super(); - } - - public static Test suite() - { - TestSuite suite = new TestSuite( "Graph Tests" ); - suite.addTest( com.phoenixst.plexus.examples.AllTests.suite() ); - suite.addTest( com.phoenixst.plexus.util.AllTests.suite() ); - suite.addTest( DefaultGraphTest.suite() ); - return suite; - } - - public static void main( String[] args ) - { - junit.textui.TestRunner.run( suite() ); - } - -} Deleted: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/AllTests.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/AllTests.java 2010-09-15 16:07:22 UTC (rev 882) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/AllTests.java 2010-09-15 16:09:13 UTC (rev 883) @@ -1,64 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, - * Inc. and others. All rights reserved. - * - * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE - * COMMON PUBLIC LICENSE ("AGREEMENT") WHICH ACCOMPANIES IT. ANY - * USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES - * RECIPIENT'S ACCEPTANCE OF THE AGREEMENT. - * - * The license text can also be found at - * http://opensource.org/licenses/cpl.php - */ - -package com.phoenixst.plexus.examples; - -import junit.framework.*; - - -/** - * Test suite for all tests in this package. - * - * @author Ray A. Conner - */ -public class AllTests -{ - - private AllTests() - { - super(); - } - - public static Test suite() - { - TestSuite suite = new TestSuite( "Graph Example Tests" ); - - suite.addTest( EmptyGraphTest.suite() ); - suite.addTest( CompleteGraphTest.suite() ); - suite.addTest( PathTest.suite() ); - suite.addTest( CycleTest.suite() ); - suite.addTest( CompleteTreeTest.suite() ); - - suite.addTest( CompleteBipartiteGraphTest.suite() ); - suite.addTest( StarTest.suite() ); - suite.addTest( WheelTest.suite() ); - - suite.addTest( PlanarMeshTest.suite() ); - suite.addTest( PrismTest.suite() ); - suite.addTest( ToroidalMeshTest.suite() ); - - suite.addTest( PetersenGraphTest.suite() ); - - suite.addTest( DefaultGraphExamplesTest.suite() ); - - return suite; - } - - public static void main( String[] args ) - { - junit.textui.TestRunner.run( suite() ); - } - -} Deleted: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/AllTests.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/AllTests.java 2010-09-15 16:07:22 UTC (rev 882) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/AllTests.java 2010-09-15 16:09:13 UTC (rev 883) @@ -1,48 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, - * Inc. and others. All rights reserved. - * - * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE - * COMMON PUBLIC LICENSE ("AGREEMENT") WHICH ACCOMPANIES IT. ANY - * USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES - * RECIPIENT'S ACCEPTANCE OF THE AGREEMENT. - * - * The license text can also be found at - * http://opensource.org/licenses/cpl.php - */ - -package com.phoenixst.plexus.util; - -import junit.framework.*; - - -/** - * Test suite for all tests in this package. - * - * @author Ray A. Conner - */ -public class AllTests -{ - - private AllTests() - { - super(); - } - - public static Test suite() - { - TestSuite suite = new TestSuite( "Graph Util Tests" ); - - suite.addTest( SingletonGraphTest.suite() ); - - return suite; - } - - public static void main( String[] args ) - { - junit.textui.TestRunner.run( suite() ); - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2010-09-15 21:00:31
|
Revision: 884 http://plexus.svn.sourceforge.net/plexus/?rev=884&view=rev Author: rconner Date: 2010-09-15 21:00:23 +0000 (Wed, 15 Sep 2010) Log Message: ----------- Refactoring test code, although the tests are only half-way to JUnit4 usage. However, the relationship between AbstractGraphTest, SingletonGraphTest, and UtilSuite appears to work. Running the same set of tests for a bunch of different data objects is not terribly clean in JUnit4. JUnit really wants every possible fixture to be a distinct class (this particular Path graph vs. that other Path graph, etc.); and this was the only way I found to avoid an explosion of top-level public classes. Modified Paths: -------------- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AbstractGraphTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/SingletonGraphTest.java Added Paths: ----------- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/UtilSuite.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-15 16:09:13 UTC (rev 883) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AbstractGraphTest.java 2010-09-15 21:00:23 UTC (rev 884) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2006 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -15,6 +15,13 @@ package com.phoenixst.plexus; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; @@ -26,81 +33,79 @@ import org.apache.commons.collections.Closure; import org.apache.commons.collections.Predicate; +import org.junit.Test; import com.phoenixst.collections.OrderedPair; -import com.phoenixst.junit.AbstractCloneableTestCase; +import com.phoenixst.plexus.Graph.Edge; /** - * A {@link Graph} tester. + * A {@link Graph} tester. * - * @author Ray A. Conner + * @author rconner */ -public abstract class AbstractGraphTest extends AbstractCloneableTestCase +public abstract class AbstractGraphTest { - protected static final String SHOULD_THROW_MESSAGE = "Should throw an Exception."; + private static final String SHOULD_THROW_MESSAGE = "Should throw an Exception."; - protected static final String SHOULD_THROW_NO_SUCH_ELEMENT_MESSAGE = "Should throw a NoSuchElementException."; + private static final String SHOULD_THROW_NO_SUCH_ELEMENT_MESSAGE = "Should throw a NoSuchElementException."; - protected static final String SHOULD_THROW_ILLEGAL_ARGUMENT_MESSAGE = "Should throw IllegalArgumentException."; + private static final String SHOULD_THROW_ILLEGAL_ARGUMENT_MESSAGE = "Should throw IllegalArgumentException."; /** - * Everything but directed in. + * Everything but directed in. */ - protected static final int DIR_MASK = GraphUtils.UNDIRECTED_MASK | GraphUtils.DIRECTED_OUT_MASK; + private static final int DIR_MASK = GraphUtils.UNDIRECTED_MASK | GraphUtils.DIRECTED_OUT_MASK; /** - * The <code>Graph</code> to be tested. + * The <code>Graph</code> to be tested. */ - protected Graph g; + Graph g = null; /** - * Contains all nodes accessed by the graph's - * <code>nodes( null ).iterator()</code> method. + * Contains all nodes accessed by the graph's + * <code>nodes( null ).iterator()</code> method. */ - private Set nodes = null; + private Set< Object > nodes = null; /** - * Contains all edges accessed by the graph's - * <code>edges( null ).iterator()</code> method. + * Contains all edges accessed by the graph's + * <code>edges( null ).iterator()</code> method. */ - private Set realEdges = null; + private Set< Edge > realEdges = null; /** - * Contains <code>SimpleObjectEdges</code> corresponding to all - * edges accessed by the graph's <code>edges( null ).iterator()</code> - * method. + * Contains <code>SimpleObjectEdges</code> corresponding to all edges + * accessed by the graph's <code>edges( null ).iterator()</code> method. */ - private Set testEdges = null; + private Set< Edge > testEdges = null; - /** * */ - protected Object[] presentNodes; + private Object[] presentNodes = new Object[] {}; /** * */ - protected Object[] notPresentNodes; + private Object[] notPresentNodes = new Object[] {}; /** * */ - protected Graph.Edge[] presentEdges; + private Edge[] presentEdges = new Edge[] {}; /** * */ - protected Graph.Edge[] notPresentEdges; + private Edge[] notPresentEdges = new Edge[] {}; //////////////////////////////////////// // Constructor //////////////////////////////////////// - protected AbstractGraphTest() { super(); @@ -108,96 +113,90 @@ //////////////////////////////////////// - // Fixture method + // Fixture methods //////////////////////////////////////// - - protected void setUp( Graph graph ) + @SuppressWarnings( "unchecked" ) + protected void setGraph( Graph graph ) { g = graph; - nodes = new HashSet(); - Iterator nodeIter = g.nodes( null ).iterator(); - while( nodeIter.hasNext() ) { - nodes.add( nodeIter.next() ); - } + nodes = new HashSet< Object >(); + nodes.addAll( g.nodes( null ) ); - realEdges = new HashSet(); - testEdges = new HashSet(); - Iterator edgeIter = g.edges( null ).iterator(); - while( edgeIter.hasNext() ) { - Graph.Edge edge = (Graph.Edge) edgeIter.next(); + realEdges = new HashSet< Edge >(); + testEdges = new HashSet< Edge >(); + for( Edge edge : (Collection< Edge >) g.edges( null ) ) { realEdges.add( edge ); - testEdges.add( new SimpleObjectEdge( edge.getUserObject(), - edge.getTail(), edge.getHead(), - edge.isDirected() ) ); + testEdges.add( new SimpleObjectEdge( edge.getUserObject(), edge.getTail(), edge.getHead(), edge.isDirected() ) ); } + } - presentNodes = new Object[] {}; - notPresentNodes = new Object[] {}; - presentEdges = new Graph.Edge[] {}; - notPresentEdges = new Graph.Edge[] {}; + protected void setPresentNodes( Object... presentNodes ) + { + this.presentNodes = presentNodes; } + protected void setNotPresentNodes( Object... notPresentNodes ) + { + this.notPresentNodes = notPresentNodes; + } - //////////////////////////////////////// - // Protected helper methods and stuff - //////////////////////////////////////// + protected void setPresentEdges( Edge... presentEdges ) + { + this.presentEdges = presentEdges; + } - - protected boolean isSelfEdge( Graph.Edge edge ) + protected void setNotPresentEdges( Edge... notPresentEdges ) { - Object tail = edge.getTail(); - Object head = edge.getHead(); - return (tail == null) ? head == null : tail.equals( head ); + this.notPresentEdges = notPresentEdges; } - protected void createPresentNodeRanges( int limit ) { - presentNodes = new Object[ limit ]; + presentNodes = new Object[limit]; for( int i = 0; i < limit; i++ ) { - presentNodes[i] = new Integer( i ); + presentNodes[i] = Integer.valueOf( i ); } - notPresentNodes = new Object[] { null, - new Object(), - new Integer( -1 ), - new Integer( limit ) }; + notPresentNodes = new Object[] + { null, + new Object(), + Integer.valueOf( -1 ), + Integer.valueOf( limit ) }; } - protected void createPresentNodeRanges( int limitA, int limitB ) { - presentNodes = new Object[ limitA * limitB ]; + presentNodes = new Object[limitA * limitB]; for( int i = 0; i < limitA; i++ ) { for( int j = 0; j < limitB; j++ ) { presentNodes[i * limitB + j] = new OrderedIntPair( i, j ); } } - notPresentNodes = new Object[] { null, - new Object(), - new OrderedIntPair( -1, 0 ), - new OrderedIntPair( 0, -1 ), - new OrderedIntPair( limitA, 0 ), - new OrderedIntPair( limitA - 1, -1 ), - new OrderedIntPair( 0, limitB ), - new OrderedIntPair( -1, limitB - 1 ), - new OrderedIntPair( limitA - 1, limitB ), - new OrderedIntPair( limitA, limitB - 1 ) }; + notPresentNodes = new Object[] + { null, + new Object(), + new OrderedIntPair( -1, 0 ), + new OrderedIntPair( 0, -1 ), + new OrderedIntPair( limitA, 0 ), + new OrderedIntPair( limitA - 1, -1 ), + new OrderedIntPair( 0, limitB ), + new OrderedIntPair( -1, limitB - 1 ), + new OrderedIntPair( limitA - 1, limitB ), + new OrderedIntPair( limitA, limitB - 1 ) }; } - protected void createEdgeArrays( int limit, Predicate pred ) { - Set goodEdges = new HashSet(); - Set badEdges = new HashSet(); + Set< Edge > goodEdges = new HashSet< Edge >(); + Set< Edge > badEdges = new HashSet< Edge >(); for( int tailIndex = 0; tailIndex < limit; tailIndex++ ) { - Object tail = new Integer( tailIndex ); + Object tail = Integer.valueOf( tailIndex ); for( int headIndex = 0; headIndex < limit; headIndex++ ) { - Object head = new Integer( headIndex ); - Graph.Edge edge = new SimpleObjectEdge( null, tail, head, false ); + Object head = Integer.valueOf( headIndex ); + Edge edge = new SimpleObjectEdge( null, tail, head, false ); if( pred.evaluate( edge ) ) { goodEdges.add( edge ); } else { @@ -216,11 +215,10 @@ notPresentEdges = createEdgeArray( badEdges ); } - protected void createEdgeArrays( int limitA, int limitB, Predicate pred ) { - Set goodEdges = new HashSet(); - Set badEdges = new HashSet(); + Set< Edge > goodEdges = new HashSet< Edge >(); + Set< Edge > badEdges = new HashSet< Edge >(); for( int tailA = 0; tailA < limitA; tailA++ ) { for( int tailB = 0; tailB < limitB; tailB++ ) { @@ -228,7 +226,7 @@ for( int headA = 0; headA < limitA; headA++ ) { for( int headB = 0; headB < limitB; headB++ ) { Object head = new OrderedIntPair( headA, headB ); - Graph.Edge edge = new SimpleObjectEdge( null, tail, head, false ); + Edge edge = new SimpleObjectEdge( null, tail, head, false ); if( pred.evaluate( edge ) ) { goodEdges.add( edge ); } else { @@ -249,17 +247,27 @@ notPresentEdges = createEdgeArray( badEdges ); } - - protected Graph.Edge[] createEdgeArray( Collection edges ) + protected static Edge[] createEdgeArray( Collection< Edge > edges ) { - Graph.Edge[] edgeArray = new Graph.Edge[ edges.size() ]; + Edge[] edgeArray = new Edge[edges.size()]; edges.toArray( edgeArray ); return edgeArray; } - protected void testEdge( Graph.Edge edge, Object tail, Object head ) + //////////////////////////////////////// + // helper methods + //////////////////////////////////////// + + private static boolean isSelfEdge( Edge edge ) { + Object tail = edge.getTail(); + Object head = edge.getHead(); + return ( tail == null ) ? head == null : tail.equals( head ); + } + + private void testEdge( Edge edge, Object tail, Object head ) + { Object edgeTail = edge.getTail(); Object edgeHead = edge.getHead(); @@ -274,7 +282,7 @@ assertEquals( tail, edgeTail ); assertEquals( head, edgeHead ); } else { - if( (tail == null) ? (edgeTail == null) : tail.equals( edgeTail ) ) { + if( ( tail == null ) ? ( edgeTail == null ) : tail.equals( edgeTail ) ) { assertEquals( head, edgeHead ); } else { assertEquals( tail, edgeHead ); @@ -284,17 +292,15 @@ // Check that the edge is accessed by the edge iterator. assertTrue( realEdges.contains( edge ) ); - assertTrue( testEdges.contains( new SimpleObjectEdge( edge.getUserObject(), - tail, head, - edge.isDirected() ) ) ); + assertTrue( testEdges.contains( new SimpleObjectEdge( edge.getUserObject(), tail, head, edge.isDirected() ) ) ); // Check that getOtherEndpoint() works. assertEquals( tail, edge.getOtherEndpoint( head ) ); assertEquals( head, edge.getOtherEndpoint( tail ) ); - for( int i = 0; i < notPresentNodes.length; i++ ) { + for( Object node : notPresentNodes ) { try { - edge.getOtherEndpoint( notPresentNodes[i] ); + edge.getOtherEndpoint( node ); fail( SHOULD_THROW_ILLEGAL_ARGUMENT_MESSAGE ); } catch( IllegalArgumentException e ) { // Do nothing @@ -302,14 +308,13 @@ } } - - protected void testNotPresentNodes( Closure closure ) + private void testNotPresentNodes( Closure closure ) { // Check that using nodes not present in the graph throws an // exception. - for( int i = 0; i < notPresentNodes.length; i++ ) { + for( Object node : notPresentNodes ) { try { - closure.execute( notPresentNodes[i] ); + closure.execute( node ); fail( SHOULD_THROW_MESSAGE ); } catch( ClassCastException e ) { // Do nothing @@ -324,79 +329,34 @@ } - protected void testNotPresentNodes( BinaryClosure bClosure ) - { - // Check that using nodes not present in the graph throws an - // exception. - for( int i = 0; i < notPresentNodes.length; i++ ) { - for( int j = 0; j < presentNodes.length; j++ ) { - try { - bClosure.execute( notPresentNodes[i], presentNodes[j] ); - fail( SHOULD_THROW_MESSAGE ); - } catch( ClassCastException e ) { - // Do nothing - } catch( IllegalArgumentException e ) { - // Do nothing - } catch( NoSuchNodeException e ) { - // Do nothing - } - try { - bClosure.execute( presentNodes[j], notPresentNodes[i] ); - fail( SHOULD_THROW_MESSAGE ); - } catch( ClassCastException e ) { - // Do nothing - } catch( IllegalArgumentException e ) { - // Do nothing - } catch( NoSuchNodeException e ) { - // Do nothing - } - } - for( int j = 0; j < notPresentNodes.length; j++ ) { - try { - bClosure.execute( notPresentNodes[i], notPresentNodes[j] ); - fail( SHOULD_THROW_MESSAGE ); - } catch( ClassCastException e ) { - // Do nothing - } catch( IllegalArgumentException e ) { - // Do nothing - } catch( NoSuchNodeException e ) { - // Do nothing - } - } - } - } - - //////////////////////////////////////// // Public test methods //////////////////////////////////////// - + @Test public void testNodeSize() { assertEquals( nodes.size(), g.nodes( null ).size() ); } - + @Test public void testEdgeSize() { assertEquals( realEdges.size(), g.edges( null ).size() ); } - + @Test public void testDegree() { // Check that the degree of a node is the same as the number // of edges accessed by the traverser. - Iterator nodeIter = g.nodes( null ).iterator(); - while( nodeIter.hasNext() ) { - Object node = nodeIter.next(); + for( Object node : g.nodes( null ) ) { int count; Traverser t = g.traverser( node, null ); for( count = 0; t.hasNext(); count++ ) { Object adjNode = t.next(); - if( (node == null) ? (adjNode == null) : node.equals( adjNode ) ) { + if( ( node == null ) ? ( adjNode == null ) : node.equals( adjNode ) ) { count++; } } @@ -404,17 +364,20 @@ } testNotPresentNodes( new Closure() - { public void execute( Object object ) { g.degree( object ); } } ); + { + public void execute( Object object ) + { + g.degree( object ); + } + } ); } - + @Test public void testOutDegree() { // Check that the out-degree of a node is the same as the // number of edges accessed by the out-traverser. - Iterator nodeIter = g.nodes( null ).iterator(); - while( nodeIter.hasNext() ) { - Object node = nodeIter.next(); + for( Object node : g.nodes( null ) ) { int count; Traverser t = g.traverser( node, GraphUtils.OUT_TRAVERSER_PREDICATE ); for( count = 0; t.hasNext(); count++ ) { @@ -424,17 +387,20 @@ } testNotPresentNodes( new Closure() - { public void execute( Object object ) { g.degree( object, GraphUtils.OUT_TRAVERSER_PREDICATE ); } } ); + { + public void execute( Object object ) + { + g.degree( object, GraphUtils.OUT_TRAVERSER_PREDICATE ); + } + } ); } - + @Test public void testInDegree() { // Check that the in-degree of a node is the same as the // number of edges accessed by the in-traverser. - Iterator nodeIter = g.nodes( null ).iterator(); - while( nodeIter.hasNext() ) { - Object node = nodeIter.next(); + for( Object node : g.nodes( null ) ) { int count; Traverser t = g.traverser( node, GraphUtils.IN_TRAVERSER_PREDICATE ); for( count = 0; t.hasNext(); count++ ) { @@ -444,51 +410,51 @@ } testNotPresentNodes( new Closure() - { public void execute( Object object ) { g.degree( object, GraphUtils.IN_TRAVERSER_PREDICATE ); } } ); + { + public void execute( Object object ) + { + g.degree( object, GraphUtils.IN_TRAVERSER_PREDICATE ); + } + } ); } - + @Test public void testContainsNode() { // Check that every node accessed by the node iterator is // present in the graph. - Iterator nodeIter = g.nodes( null ).iterator(); - while( nodeIter.hasNext() ) { - assertTrue( g.containsNode( nodeIter.next() ) ); + for( Object node : g.nodes( null ) ) { + assertTrue( g.containsNode( node ) ); } // Check for supposedly present and not present nodes. - for( int i = 0; i < presentNodes.length; i++ ) { - assertTrue( g.containsNode( presentNodes[i] ) ); + for( Object node : presentNodes ) { + assertTrue( g.containsNode( node ) ); } - for( int i = 0; i < notPresentNodes.length; i++ ) { - assertFalse( g.containsNode( notPresentNodes[i] ) ); + for( Object node : notPresentNodes ) { + assertFalse( g.containsNode( node ) ); } } - + @Test + @SuppressWarnings( "unchecked" ) public void testContainsEdge() { // Check that every edge accessed by the edge iterator is // present in the graph. - Iterator edgeIter = g.edges( null ).iterator(); - while( edgeIter.hasNext() ) { - assertTrue( g.containsEdge( (Graph.Edge) edgeIter.next() ) ); + for( Edge edge : (Collection< Edge >) g.edges( null ) ) { + assertTrue( g.containsEdge( edge ) ); } } - + @Test public void testGetEdge() { // Check an edge for each pair of nodes. - Iterator tailIter = g.nodes( null ).iterator(); - while( tailIter.hasNext() ) { - Object tail = tailIter.next(); - Iterator headIter = g.nodes( null ).iterator(); - while( headIter.hasNext() ) { - Object head = headIter.next(); + for( Object tail : g.nodes( null ) ) { + for( Object head : g.nodes( null ) ) { Predicate edgePred = EdgePredicateFactory.createEqualsNodes( tail, head, DIR_MASK ); - Graph.Edge edge = g.getEdge( edgePred ); + Edge edge = g.getEdge( edgePred ); if( edge != null ) { testEdge( edge, tail, head ); } @@ -496,29 +462,27 @@ } // Check for supposedly present and not present edges. - for( int i = 0; i < presentEdges.length; i++ ) { - Graph.Edge edge = presentEdges[i]; + for( Edge edge : presentEdges ) { Predicate edgePred = EdgePredicateFactory.create( edge ); assertNotNull( g.getEdge( edgePred ) ); } - for( int i = 0; i < notPresentEdges.length; i++ ) { - Graph.Edge edge = notPresentEdges[i]; + for( Edge edge : notPresentEdges ) { Predicate edgePred = EdgePredicateFactory.create( edge ); assertNull( g.getEdge( edgePred ) ); } } - + @Test public void testNodeIterator() { - for( int i = 0; i < presentNodes.length; i++ ) { - assertTrue( nodes.contains( presentNodes[i] ) ); + for( Object node : presentNodes ) { + assertTrue( nodes.contains( node ) ); } - for( int i = 0; i < notPresentNodes.length; i++ ) { - assertFalse( nodes.contains( notPresentNodes[i] ) ); + for( Object node : notPresentNodes ) { + assertFalse( nodes.contains( node ) ); } - Iterator nodeIter = g.nodes( null ).iterator(); + Iterator< ? > nodeIter = g.nodes( null ).iterator(); int count; for( count = 0; nodeIter.hasNext(); count++ ) { nodeIter.next(); @@ -533,27 +497,23 @@ assertEquals( count, nodes.size() ); } - + @Test public void testEdgeIterator() { - for( int i = 0; i < presentEdges.length; i++ ) { - Graph.Edge edge = presentEdges[i]; - assertTrue( testEdges.contains( new SimpleObjectEdge( edge.getUserObject(), - edge.getTail(), edge.getHead(), + for( Edge edge : presentEdges ) { + assertTrue( testEdges.contains( new SimpleObjectEdge( edge.getUserObject(), edge.getTail(), edge.getHead(), edge.isDirected() ) ) ); } - for( int i = 0; i < notPresentEdges.length; i++ ) { - Graph.Edge edge = notPresentEdges[i]; - assertFalse( testEdges.contains( new SimpleObjectEdge( edge.getUserObject(), - edge.getTail(), edge.getHead(), - edge.isDirected() ) ) ); + for( Edge edge : notPresentEdges ) { + assertFalse( testEdges.contains( new SimpleObjectEdge( edge.getUserObject(), edge.getTail(), + edge.getHead(), edge.isDirected() ) ) ); } - Iterator edgeIter = g.edges( null ).iterator(); + Iterator< ? > edgeIter = g.edges( null ).iterator(); int count; for( count = 0; edgeIter.hasNext(); count++ ) { - Graph.Edge edge = (Graph.Edge) edgeIter.next(); + Edge edge = (Edge) edgeIter.next(); testEdge( edge, edge.getTail(), edge.getHead() ); } try { @@ -566,26 +526,22 @@ assertEquals( count, realEdges.size() ); } - + @Test public void testEdgeIterator2() { int totalCount = 0; int selfCount = 0; - Iterator tailIter = g.nodes( null ).iterator(); - while( tailIter.hasNext() ) { - Object tail = tailIter.next(); - Iterator headIter = g.nodes( null ).iterator(); - while( headIter.hasNext() ) { - Object head = headIter.next(); + for( Object tail : g.nodes( null ) ) { + for( Object head : g.nodes( null ) ) { Predicate edgePred = EdgePredicateFactory.createEqualsNodes( tail, head, DIR_MASK ); - Iterator edgeIter = g.edges( edgePred ).iterator(); + Iterator< ? > edgeIter = g.edges( edgePred ).iterator(); if( edgeIter.hasNext() ) { assertNotNull( g.getEdge( edgePred ) ); } else { assertNull( g.getEdge( edgePred ) ); } while( edgeIter.hasNext() ) { - Graph.Edge edge = (Graph.Edge) edgeIter.next(); + Edge edge = (Edge) edgeIter.next(); if( isSelfEdge( edge ) ) { selfCount++; } @@ -609,30 +565,26 @@ assertEquals( totalCount + selfCount, 2 * realEdges.size() ); // Check for supposedly present and not present edges. - for( int i = 0; i < presentEdges.length; i++ ) { - Graph.Edge edge = presentEdges[i]; + for( Edge edge : presentEdges ) { Predicate edgePred = EdgePredicateFactory.create( edge ); - Iterator edgeIter = g.edges( edgePred ).iterator(); + Iterator< ? > edgeIter = g.edges( edgePred ).iterator(); assertTrue( edgeIter.hasNext() ); assertNotNull( edgeIter.next() ); } - for( int i = 0; i < notPresentEdges.length; i++ ) { - Graph.Edge edge = notPresentEdges[i]; + for( Edge edge : notPresentEdges ) { Predicate edgePred = EdgePredicateFactory.create( edge ); - Iterator edgeIter = g.edges( edgePred ).iterator(); + Iterator< ? > edgeIter = g.edges( edgePred ).iterator(); assertFalse( edgeIter.hasNext() ); } } - + @Test public void testTraverser() { int totalCount = 0; int selfCount = 0; - HashSet edges = new HashSet(); - Iterator nodeIter = g.nodes( null ).iterator(); - while( nodeIter.hasNext() ) { - Object node = nodeIter.next(); + HashSet< Edge > edges = new HashSet< Edge >(); + for( Object node : g.nodes( null ) ) { Traverser t = g.traverser( node, null ); edges.clear(); @@ -645,13 +597,13 @@ assertTrue( g.containsNode( adjNode ) ); assertTrue( nodes.contains( adjNode ) ); - Graph.Edge edge = t.getEdge(); + Edge edge = t.getEdge(); if( isSelfEdge( edge ) ) { selfCount++; } edges.add( edge ); Object tail = edge.getTail(); - if( (node == null) ? (tail == null) : node.equals( tail ) ) { + if( ( node == null ) ? ( tail == null ) : node.equals( tail ) ) { testEdge( edge, node, adjNode ); } else { testEdge( edge, adjNode, node ); @@ -671,16 +623,19 @@ assertEquals( totalCount + selfCount, 2 * realEdges.size() ); testNotPresentNodes( new Closure() - { public void execute( Object object ) { g.traverser( object, null ); } } ); + { + public void execute( Object object ) + { + g.traverser( object, null ); + } + } ); } - + @Test public void testOutTraverser() { - HashSet edges = new HashSet(); - Iterator nodeIter = g.nodes( null ).iterator(); - while( nodeIter.hasNext() ) { - Object node = nodeIter.next(); + HashSet< Edge > edges = new HashSet< Edge >(); + for( Object node : g.nodes( null ) ) { Traverser t = g.traverser( node, GraphUtils.OUT_TRAVERSER_PREDICATE ); edges.clear(); @@ -693,7 +648,7 @@ assertTrue( g.containsNode( adjNode ) ); assertTrue( nodes.contains( adjNode ) ); - Graph.Edge edge = t.getEdge(); + Edge edge = t.getEdge(); edges.add( edge ); testEdge( edge, node, adjNode ); } @@ -709,16 +664,19 @@ } testNotPresentNodes( new Closure() - { public void execute( Object object ) { g.traverser( object, GraphUtils.OUT_TRAVERSER_PREDICATE ); } } ); + { + public void execute( Object object ) + { + g.traverser( object, GraphUtils.OUT_TRAVERSER_PREDICATE ); + } + } ); } - + @Test public void testInTraverser() { - HashSet edges = new HashSet(); - Iterator nodeIter = g.nodes( null ).iterator(); - while( nodeIter.hasNext() ) { - Object node = nodeIter.next(); + HashSet< Edge > edges = new HashSet< Edge >(); + for( Object node : g.nodes( null ) ) { Traverser t = g.traverser( node, GraphUtils.IN_TRAVERSER_PREDICATE ); edges.clear(); @@ -731,7 +689,7 @@ assertTrue( g.containsNode( adjNode ) ); assertTrue( nodes.contains( adjNode ) ); - Graph.Edge edge = t.getEdge(); + Edge edge = t.getEdge(); edges.add( edge ); testEdge( edge, adjNode, node ); } @@ -747,10 +705,15 @@ } testNotPresentNodes( new Closure() - { public void execute( Object object ) { g.traverser( object, GraphUtils.IN_TRAVERSER_PREDICATE ); } } ); + { + public void execute( Object object ) + { + g.traverser( object, GraphUtils.IN_TRAVERSER_PREDICATE ); + } + } ); } - + @Test public void testSerialization() throws IOException { @@ -763,23 +726,16 @@ //////////////////////////////////////// - // Protected classes and interfaces + // Private classes //////////////////////////////////////// - - protected interface BinaryClosure + private static class OrderedIntPair extends OrderedPair { - public void execute( Object a, Object b ); - } - - - protected static class OrderedIntPair extends OrderedPair - { private static final long serialVersionUID = 1L; public OrderedIntPair( int first, int second ) { - super( new Integer( first ), new Integer( second ) ); + super( Integer.valueOf( first ), Integer.valueOf( second ) ); } } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/SingletonGraphTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/SingletonGraphTest.java 2010-09-15 16:09:13 UTC (rev 883) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/SingletonGraphTest.java 2010-09-15 21:00:23 UTC (rev 884) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2006 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -15,64 +15,48 @@ package com.phoenixst.plexus.util; -import junit.framework.*; +import org.junit.Before; -import com.phoenixst.plexus.*; +import com.phoenixst.plexus.AbstractGraphTest; +import com.phoenixst.plexus.SimpleObjectEdge; /** - * A {@link SingletonGraph} tester. + * A {@link SingletonGraph} tester. * - * @author Ray A. Conner + * @author rconner */ -public class SingletonGraphTest extends AbstractGraphTest +public abstract class SingletonGraphTest extends AbstractGraphTest { - - private final Object node; - - - public SingletonGraphTest( Object node ) + void setNode( Object node ) { - super(); - this.node = node; - } - - - @Override - protected void setUp() - throws Exception - { - super.setUp(); - setUp( new SingletonGraph( node ) ); - presentNodes = new Object[] { node }; + setGraph( new SingletonGraph( node ) ); + setPresentNodes( node ); if( node == null ) { - notPresentNodes = new Object[] { new Object() }; + setNotPresentNodes( new Object() ); } else { - notPresentNodes = new Object[] { null, new Object() }; + setNotPresentNodes( null, new Object() ); } - notPresentEdges = new Graph.Edge[] { new SimpleObjectEdge( null, node, node, false ), - new SimpleObjectEdge( null, node, node, true ) }; + setNotPresentEdges( new SimpleObjectEdge( null, node, node, false ), + new SimpleObjectEdge( null, node, node, true ) ); } - private static Test suite( Object node ) + public static class TestNull extends SingletonGraphTest { - return new SingletonGraphTest( node ).getInstanceSuite( "Singleton[" + node + "]" ); + @Before + public void init() + { + setNode( null ); + } } - - public static Test suite() + public static class TestInteger extends SingletonGraphTest { - TestSuite suite = new TestSuite( "SingletonGraph Tests" ); - suite.addTest( suite( null ) ); - suite.addTest( suite( new Integer( 5 ) ) ); - return suite; + @Before + public void init() + { + setNode( Integer.valueOf( 5 ) ); + } } - - - public static void main( String[] args ) - { - junit.textui.TestRunner.run( suite() ); - } - } Added: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/UtilSuite.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/UtilSuite.java (rev 0) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/UtilSuite.java 2010-09-15 21:00:23 UTC (rev 884) @@ -0,0 +1,34 @@ +/* + * $Id$ + * + * Copyright (C) 1994-2010 by Phoenix Software Technologists, + * Inc. and others. All rights reserved. + * + * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE + * COMMON PUBLIC LICENSE ("AGREEMENT") WHICH ACCOMPANIES IT. ANY + * USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES + * RECIPIENT'S ACCEPTANCE OF THE AGREEMENT. + * + * The license text can also be found at + * http://opensource.org/licenses/cpl.php + */ + +package com.phoenixst.plexus.util; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + + +/** + * Suite for all the tests in this package. + * + * @author rconner + */ +@RunWith( Suite.class ) +...@Su...iteClasses( { + SingletonGraphTest.TestNull.class, + SingletonGraphTest.TestInteger.class } ) +public class UtilSuite +{ + // This class merely exists to hold the JUnit annotations. +} Property changes on: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/UtilSuite.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Date Revision Id Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2010-09-15 22:23:05
|
Revision: 887 http://plexus.svn.sourceforge.net/plexus/?rev=887&view=rev Author: rconner Date: 2010-09-15 22:22:57 +0000 (Wed, 15 Sep 2010) Log Message: ----------- Getting most of the rest of the tests working Modified Paths: -------------- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteBipartiteGraphTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteGraphTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteTreeTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CycleTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/DefaultGraphExamplesTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/EmptyGraphTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PathTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PetersenGraphTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PlanarMeshTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PrismTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/StarTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/ToroidalMeshTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/WheelTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/SingletonGraphTest.java Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteBipartiteGraphTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteBipartiteGraphTest.java 2010-09-15 22:00:18 UTC (rev 886) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteBipartiteGraphTest.java 2010-09-15 22:22:57 UTC (rev 887) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -15,92 +15,109 @@ package com.phoenixst.plexus.examples; -import junit.framework.*; - import org.apache.commons.collections.Predicate; +import org.junit.Before; -import com.phoenixst.plexus.*; +import com.phoenixst.plexus.AbstractGraphTest; +import com.phoenixst.plexus.Graph; /** - * A {@link CompleteBipartiteGraph} tester. + * A {@link CompleteBipartiteGraph} tester. * - * @author Ray A. Conner + * @author rconner */ -public class CompleteBipartiteGraphTest extends AbstractGraphTest +public abstract class CompleteBipartiteGraphTest extends AbstractGraphTest { + void set( final int m, final int n ) + { + setGraph( new CompleteBipartiteGraph( m, n ) ); + createPresentNodeRanges( m + n ); + createEdgeArrays( m + n, new Predicate() + { + public boolean evaluate( Object object ) + { + Graph.Edge edge = (Graph.Edge) object; + if( !edge.isDirected() ) { + return false; + } + int tail = ((Integer) edge.getTail()).intValue(); + int head = ((Integer) edge.getHead()).intValue(); + return (tail < m && m <= head); + } + } ); + } - private static class TestPredicate - implements Predicate + + public static class Test_0_0 extends CompleteBipartiteGraphTest { - private final int m; + @Before + public void init() + { + set( 0, 0 ); + } + } - TestPredicate( int m ) + public static class Test_0_1 extends CompleteBipartiteGraphTest + { + @Before + public void init() { - super(); - this.m = m; + set( 0, 1 ); } + } - public boolean evaluate( Object object ) + public static class Test_1_0 extends CompleteBipartiteGraphTest + { + @Before + public void init() { - Graph.Edge edge = (Graph.Edge) object; - if( !edge.isDirected() ) { - return false; - } - int tail = ((Integer) edge.getTail()).intValue(); - int head = ((Integer) edge.getHead()).intValue(); - return (tail < m && m <= head); + set( 1, 0 ); } } - - private int m; - private int n; - - - public CompleteBipartiteGraphTest( int m, int n ) + public static class Test_0_5 extends CompleteBipartiteGraphTest { - super(); - this.m = m; - this.n = n; + @Before + public void init() + { + set( 0, 5 ); + } } - - @Override - protected void setUp() - throws Exception + public static class Test_5_0 extends CompleteBipartiteGraphTest { - super.setUp(); - setUp( new CompleteBipartiteGraph( m, n ) ); - createPresentNodeRanges( m + n ); - createEdgeArrays( m + n, new TestPredicate( m ) ); + @Before + public void init() + { + set( 5, 0 ); + } } - - private static Test suite( int m, int n ) + public static class Test_1_5 extends CompleteBipartiteGraphTest { - return new CompleteBipartiteGraphTest( m, n ).getInstanceSuite( "Bipartite[" + m + "," + n + "]" ); + @Before + public void init() + { + set( 1, 5 ); + } } - - public static Test suite() + public static class Test_5_1 extends CompleteBipartiteGraphTest { - TestSuite suite = new TestSuite( "CompleteBipartiteGraph Tests" ); - suite.addTest( suite( 0, 0 ) ); - suite.addTest( suite( 0, 1 ) ); - suite.addTest( suite( 1, 0 ) ); - suite.addTest( suite( 0, 5 ) ); - suite.addTest( suite( 5, 0 ) ); - suite.addTest( suite( 1, 5 ) ); - suite.addTest( suite( 5, 1 ) ); - suite.addTest( suite( 2, 3 ) ); - return suite; + @Before + public void init() + { + set( 5, 1 ); + } } - - public static void main( String[] args ) + public static class Test_2_3 extends CompleteBipartiteGraphTest { - junit.textui.TestRunner.run( suite() ); + @Before + public void init() + { + set( 2, 3 ); + } } - } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteGraphTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteGraphTest.java 2010-09-15 22:00:18 UTC (rev 886) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteGraphTest.java 2010-09-15 22:22:57 UTC (rev 887) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -15,22 +15,25 @@ package com.phoenixst.plexus.examples; -import junit.framework.*; - import org.apache.commons.collections.Predicate; +import org.junit.Before; -import com.phoenixst.plexus.*; +import com.phoenixst.plexus.AbstractGraphTest; +import com.phoenixst.plexus.Graph; /** - * A {@link CompleteGraph} tester. + * A {@link CompleteGraph} tester. * - * @author Ray A. Conner + * @author rconner */ -public class CompleteGraphTest extends AbstractGraphTest +public abstract class CompleteGraphTest extends AbstractGraphTest { - - private static final Predicate TEST_PREDICATE = new Predicate() + void set( final int n ) + { + setGraph( new CompleteGraph( n ) ); + createPresentNodeRanges( n ); + createEdgeArrays( n, new Predicate() { public boolean evaluate( Object object ) { @@ -42,50 +45,43 @@ int head = ((Integer) edge.getHead()).intValue(); return tail < head; } - }; - - - private final int n; - - - public CompleteGraphTest( int n ) - { - super(); - this.n = n; + } ); } - @Override - protected void setUp() - throws Exception + public static class Test_1 extends CompleteGraphTest { - super.setUp(); - setUp( new CompleteGraph( n ) ); - createPresentNodeRanges( n ); - createEdgeArrays( n, TEST_PREDICATE ); + @Before + public void init() + { + set( 1 ); + } } - - private static Test suite( int n ) + public static class Test_2 extends CompleteGraphTest { - return new CompleteGraphTest( n ).getInstanceSuite( "Complete[" + n + "]" ); + @Before + public void init() + { + set( 2 ); + } } - - public static Test suite() + public static class Test_3 extends CompleteGraphTest { - TestSuite suite = new TestSuite( "CompleteGraph Tests" ); - suite.addTest( suite( 1 ) ); - suite.addTest( suite( 2 ) ); - suite.addTest( suite( 3 ) ); - suite.addTest( suite( 5 ) ); - return suite; + @Before + public void init() + { + set( 3 ); + } } - - public static void main( String[] args ) + public static class Test_5 extends CompleteGraphTest { - junit.textui.TestRunner.run( suite() ); + @Before + public void init() + { + set( 5 ); + } } - } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteTreeTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteTreeTest.java 2010-09-15 22:00:18 UTC (rev 886) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteTreeTest.java 2010-09-15 22:22:57 UTC (rev 887) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -15,64 +15,24 @@ package com.phoenixst.plexus.examples; -import junit.framework.*; - import org.apache.commons.collections.Predicate; +import org.junit.Before; -import com.phoenixst.plexus.*; +import com.phoenixst.plexus.AbstractGraphTest; +import com.phoenixst.plexus.Graph; /** - * A {@link CompleteTree} tester. + * A {@link CompleteTree} tester. * - * @author Ray A. Conner + * @author rconner */ -public class CompleteTreeTest extends AbstractGraphTest +public abstract class CompleteTreeTest extends AbstractGraphTest { - - private static class TestPredicate - implements Predicate + void set( final int height, final int numChildren ) { - private final int numChildren; + setGraph( new CompleteTree( height, numChildren ) ); - TestPredicate( int numChildren ) - { - super(); - this.numChildren = numChildren; - } - - public boolean evaluate( Object object ) - { - Graph.Edge edge = (Graph.Edge) object; - if( !edge.isDirected() ) { - return false; - } - int tail = ((Integer) edge.getTail()).intValue(); - int head = ((Integer) edge.getHead()).intValue(); - return tail < head && tail == (head - 1) / numChildren; - } - } - - - private int height; - private int numChildren; - - - public CompleteTreeTest( int height, int numChildren ) - { - super(); - this.height = height; - this.numChildren = numChildren; - } - - - @Override - protected void setUp() - throws Exception - { - super.setUp(); - setUp( new CompleteTree( height, numChildren ) ); - int n; if( numChildren == 1 ) { n = height + 1; @@ -85,32 +45,73 @@ } createPresentNodeRanges( n ); - createEdgeArrays( n, new TestPredicate( numChildren ) ); + createEdgeArrays( n, new Predicate() + { + public boolean evaluate( Object object ) + { + Graph.Edge edge = (Graph.Edge) object; + if( !edge.isDirected() ) { + return false; + } + int tail = ((Integer) edge.getTail()).intValue(); + int head = ((Integer) edge.getHead()).intValue(); + return tail < head && tail == (head - 1) / numChildren; + } + } ); } - private static Test suite( int height, int numChildren ) + public static class Test_0_1 extends CompleteTreeTest { - return new CompleteTreeTest( height, numChildren ).getInstanceSuite( "Tree[" + height + "," + numChildren + "]" ); + @Before + public void init() + { + set( 0, 1 ); + } } + public static class Test_0_10 extends CompleteTreeTest + { + @Before + public void init() + { + set( 0, 10 ); + } + } - public static Test suite() + public static class Test_1_1 extends CompleteTreeTest { - TestSuite suite = new TestSuite( "CompleteTree Tests" ); - suite.addTest( suite( 0, 1 ) ); - suite.addTest( suite( 0, 10 ) ); - suite.addTest( suite( 1, 1 ) ); - suite.addTest( suite( 1, 5 ) ); - suite.addTest( suite( 5, 1 ) ); - suite.addTest( suite( 2, 3 ) ); - return suite; + @Before + public void init() + { + set( 1, 1 ); + } } + public static class Test_1_5 extends CompleteTreeTest + { + @Before + public void init() + { + set( 1, 5 ); + } + } - public static void main( String[] args ) + public static class Test_5_1 extends CompleteTreeTest { - junit.textui.TestRunner.run( suite() ); + @Before + public void init() + { + set( 5, 1 ); + } } + public static class Test_2_3 extends CompleteTreeTest + { + @Before + public void init() + { + set( 2, 3 ); + } + } } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CycleTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CycleTest.java 2010-09-15 22:00:18 UTC (rev 886) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CycleTest.java 2010-09-15 22:22:57 UTC (rev 887) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -15,85 +15,56 @@ package com.phoenixst.plexus.examples; -import junit.framework.*; - import org.apache.commons.collections.Predicate; +import org.junit.Before; -import com.phoenixst.plexus.*; +import com.phoenixst.plexus.AbstractGraphTest; +import com.phoenixst.plexus.Graph; /** - * A {@link Cycle} tester. + * A {@link Cycle} tester. * - * @author Ray A. Conner + * @author rconner */ -public class CycleTest extends AbstractGraphTest +public abstract class CycleTest extends AbstractGraphTest { - - private static class TestPredicate - implements Predicate + void set( final int n ) { - private final int n; - - TestPredicate( int n ) + setGraph( new Cycle( n ) ); + createPresentNodeRanges( n ); + createEdgeArrays( n, new Predicate() { - super(); - this.n = n; - } - - public boolean evaluate( Object object ) - { - Graph.Edge edge = (Graph.Edge) object; - if( !edge.isDirected() ) { - return false; + public boolean evaluate( Object object ) + { + Graph.Edge edge = (Graph.Edge) object; + if( !edge.isDirected() ) { + return false; + } + int tail = ((Integer) edge.getTail()).intValue(); + int head = ((Integer) edge.getHead()).intValue(); + return (tail + 1 == head) + || (tail == n - 1 && head == 0); } - int tail = ((Integer) edge.getTail()).intValue(); - int head = ((Integer) edge.getHead()).intValue(); - return (tail + 1 == head) - || (tail == n - 1 && head == 0); - } + } ); } - private int n; - - - public CycleTest( int n ) + public static class Test_3 extends CycleTest { - super(); - this.n = n; + @Before + public void init() + { + set( 3 ); + } } - - @Override - protected void setUp() - throws Exception + public static class Test_5 extends CycleTest { - super.setUp(); - setUp( new Cycle( n ) ); - createPresentNodeRanges( n ); - createEdgeArrays( n, new TestPredicate( n ) ); + @Before + public void init() + { + set( 5 ); + } } - - - private static Test suite( int n ) - { - return new CycleTest( n ).getInstanceSuite( "Cycle[" + n + "]" ); - } - - - public static Test suite() - { - TestSuite suite = new TestSuite( "Cycle Tests" ); - suite.addTest( suite( 3 ) ); - suite.addTest( suite( 5 ) ); - return suite; - } - - - public static void main( String[] args ) - { - junit.textui.TestRunner.run( suite() ); - } - } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/DefaultGraphExamplesTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/DefaultGraphExamplesTest.java 2010-09-15 22:00:18 UTC (rev 886) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/DefaultGraphExamplesTest.java 2010-09-15 22:22:57 UTC (rev 887) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -23,10 +23,10 @@ /** - * A {@link com.phoenixst.plexus.DefaultGraph} tester for copies - * of examples graphs, at least the immutable operations. + * A {@link com.phoenixst.plexus.DefaultGraph} tester for copies of examples + * graphs, at least the immutable operations. * - * @author Ray A. Conner + * @author rconner */ public class DefaultGraphExamplesTest extends AbstractGraphTest { @@ -101,10 +101,4 @@ return suite; } - - public static void main( String[] args ) - { - junit.textui.TestRunner.run( suite() ); - } - } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/EmptyGraphTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/EmptyGraphTest.java 2010-09-15 22:00:18 UTC (rev 886) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/EmptyGraphTest.java 2010-09-15 22:22:57 UTC (rev 887) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -15,70 +15,57 @@ package com.phoenixst.plexus.examples; -import junit.framework.*; - import org.apache.commons.collections.Predicate; +import org.junit.Before; import com.phoenixst.plexus.AbstractGraphTest; /** - * An {@link EmptyGraph} tester. + * An {@link EmptyGraph} tester. * - * @author Ray A. Conner + * @author rconner */ -public class EmptyGraphTest extends AbstractGraphTest +public abstract class EmptyGraphTest extends AbstractGraphTest { - - private static final Predicate TEST_PREDICATE = new Predicate() + void set( final int n ) + { + setGraph( new EmptyGraph( n ) ); + createPresentNodeRanges( n ); + createEdgeArrays( n, new Predicate() { public boolean evaluate( Object object ) { return false; } - }; - - - private final int n; - - - public EmptyGraphTest( int n ) - { - super(); - this.n = n; + } ); } - @Override - protected void setUp() - throws Exception + public static class Test_0 extends EmptyGraphTest { - super.setUp(); - setUp( new EmptyGraph( n ) ); - createPresentNodeRanges( n ); - createEdgeArrays( n, TEST_PREDICATE ); + @Before + public void init() + { + set( 0 ); + } } - - private static Test suite( int n ) + public static class Test_1 extends EmptyGraphTest { - return new EmptyGraphTest( n ).getInstanceSuite( "Empty[" + n + "]" ); + @Before + public void init() + { + set( 1 ); + } } - - public static Test suite() + public static class Test_5 extends EmptyGraphTest { - TestSuite suite = new TestSuite( "EmptyGraph Tests" ); - suite.addTest( suite( 0 ) ); - suite.addTest( suite( 1 ) ); - suite.addTest( suite( 5 ) ); - return suite; + @Before + public void init() + { + set( 5 ); + } } - - - public static void main( String[] args ) - { - junit.textui.TestRunner.run( suite() ); - } - } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PathTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PathTest.java 2010-09-15 22:00:18 UTC (rev 886) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PathTest.java 2010-09-15 22:22:57 UTC (rev 887) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -15,22 +15,25 @@ package com.phoenixst.plexus.examples; -import junit.framework.*; - import org.apache.commons.collections.Predicate; +import org.junit.Before; -import com.phoenixst.plexus.*; +import com.phoenixst.plexus.AbstractGraphTest; +import com.phoenixst.plexus.Graph; /** - * A {@link Path} tester. + * A {@link Path} tester. * - * @author Ray A. Conner + * @author rconner */ -public class PathTest extends AbstractGraphTest +public abstract class PathTest extends AbstractGraphTest { - - private static final Predicate TEST_PREDICATE = new Predicate() + void set( final int n ) + { + setGraph( new Path( n ) ); + createPresentNodeRanges( n ); + createEdgeArrays( n, new Predicate() { public boolean evaluate( Object object ) { @@ -42,49 +45,34 @@ int head = ((Integer) edge.getHead()).intValue(); return tail + 1 == head; } - }; - - - private final int n; - - - public PathTest( int n ) - { - super(); - this.n = n; + } ); } - @Override - protected void setUp() - throws Exception + public static class Test_2 extends PathTest { - super.setUp(); - setUp( new Path( n ) ); - createPresentNodeRanges( n ); - createEdgeArrays( n, TEST_PREDICATE ); + @Before + public void init() + { + set( 2 ); + } } - - private static Test suite( int n ) + public static class Test_3 extends PathTest { - return new PathTest( n ).getInstanceSuite( "Path[" + n + "]" ); + @Before + public void init() + { + set( 3 ); + } } - - public static Test suite() + public static class Test_5 extends PathTest { - TestSuite suite = new TestSuite( "Path Tests" ); - suite.addTest( suite( 2 ) ); - suite.addTest( suite( 3 ) ); - suite.addTest( suite( 5 ) ); - return suite; + @Before + public void init() + { + set( 5 ); + } } - - - public static void main( String[] args ) - { - junit.textui.TestRunner.run( suite() ); - } - } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PetersenGraphTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PetersenGraphTest.java 2010-09-15 22:00:18 UTC (rev 886) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PetersenGraphTest.java 2010-09-15 22:22:57 UTC (rev 887) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -15,22 +15,26 @@ package com.phoenixst.plexus.examples; -import junit.framework.*; - import org.apache.commons.collections.Predicate; +import org.junit.Before; -import com.phoenixst.plexus.*; +import com.phoenixst.plexus.AbstractGraphTest; +import com.phoenixst.plexus.Graph; /** - * A {@link PetersenGraph} tester. + * A {@link PetersenGraph} tester. * - * @author Ray A. Conner + * @author rconner */ public class PetersenGraphTest extends AbstractGraphTest { - - private static final Predicate TEST_PREDICATE = new Predicate() + @Before + public void init() + { + setGraph( PetersenGraph.INSTANCE ); + createPresentNodeRanges( 10 ); + createEdgeArrays( 10, new Predicate() { // Assumes tail < head private boolean evaluate( int tail, int head ) @@ -60,35 +64,6 @@ return false; } } - }; - - - public PetersenGraphTest() - { - super(); + } ); } - - - @Override - protected void setUp() - throws Exception - { - super.setUp(); - setUp( PetersenGraph.INSTANCE ); - createPresentNodeRanges( 10 ); - createEdgeArrays( 10, TEST_PREDICATE ); - } - - - public static Test suite() - { - return new TestSuite( PetersenGraphTest.class, "PetersenGraph Tests" ); - } - - - public static void main( String[] args ) - { - junit.textui.TestRunner.run( suite() ); - } - } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PlanarMeshTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PlanarMeshTest.java 2010-09-15 22:00:18 UTC (rev 886) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PlanarMeshTest.java 2010-09-15 22:22:57 UTC (rev 887) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -17,84 +17,79 @@ import java.util.List; -import junit.framework.*; - import org.apache.commons.collections.Predicate; +import org.junit.Before; -import com.phoenixst.plexus.*; +import com.phoenixst.plexus.AbstractGraphTest; +import com.phoenixst.plexus.Graph; /** - * A {@link PlanarMesh} tester. + * A {@link PlanarMesh} tester. * - * @author Ray A. Conner + * @author rconner */ -public class PlanarMeshTest extends AbstractGraphTest +public abstract class PlanarMeshTest extends AbstractGraphTest { - - private static final Predicate TEST_PREDICATE = new Predicate() + void set( final int m, final int n ) + { + setGraph( new PlanarMesh( m, n ) ); + createPresentNodeRanges( m, n ); + createEdgeArrays( m, n, new Predicate() { + @SuppressWarnings( "unchecked" ) public boolean evaluate( Object object ) { Graph.Edge edge = (Graph.Edge) object; if( !edge.isDirected() ) { return false; } - List tail = (List) edge.getTail(); - List head = (List) edge.getHead(); - int tailA = ((Integer) tail.get( 0 )).intValue(); - int tailB = ((Integer) tail.get( 1 )).intValue(); - int headA = ((Integer) head.get( 0 )).intValue(); - int headB = ((Integer) head.get( 1 )).intValue(); + List< Integer > tail = (List< Integer >) edge.getTail(); + List< Integer > head = (List< Integer >) edge.getHead(); + int tailA = tail.get( 0 ).intValue(); + int tailB = tail.get( 1 ).intValue(); + int headA = head.get( 0 ).intValue(); + int headB = head.get( 1 ).intValue(); return ( (tailA == headA) && (tailB + 1 == headB) ) || ( (tailB == headB) && (tailA + 1 == headA) ); } - }; - - - private final int m; - private final int n; - - - public PlanarMeshTest( int m, int n ) - { - super(); - this.m = m; - this.n = n; + } ); } - @Override - protected void setUp() - throws Exception + public static class Test_2_2 extends PlanarMeshTest { - super.setUp(); - setUp( new PlanarMesh( m, n ) ); - createPresentNodeRanges( m, n ); - createEdgeArrays( m, n, TEST_PREDICATE ); + @Before + public void init() + { + set( 2, 2 ); + } } - - private static Test suite( int m, int n ) + public static class Test_2_5 extends PlanarMeshTest { - return new PlanarMeshTest( m, n ).getInstanceSuite( "Plane[" + m + "," + n + "]" ); + @Before + public void init() + { + set( 2, 5 ); + } } - - public static Test suite() + public static class Test_5_2 extends PlanarMeshTest { - TestSuite suite = new TestSuite( "PlanarMesh Tests" ); - suite.addTest( suite( 2, 2 ) ); - suite.addTest( suite( 2, 5 ) ); - suite.addTest( suite( 5, 2 ) ); - suite.addTest( suite( 5, 5 ) ); - return suite; + @Before + public void init() + { + set( 5, 2 ); + } } - - public static void main( String[] args ) + public static class Test_5_5 extends PlanarMeshTest { - junit.textui.TestRunner.run( suite() ); + @Before + public void init() + { + set( 5, 5 ); + } } - } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PrismTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PrismTest.java 2010-09-15 22:00:18 UTC (rev 886) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PrismTest.java 2010-09-15 22:22:57 UTC (rev 887) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -17,99 +17,85 @@ import java.util.List; -import junit.framework.*; - import org.apache.commons.collections.Predicate; +import org.junit.Before; -import com.phoenixst.plexus.*; +import com.phoenixst.plexus.AbstractGraphTest; +import com.phoenixst.plexus.Graph; /** - * A {@link Prism} tester. + * A {@link Prism} tester. * - * @author Ray A. Conner + * @author rconner */ -public class PrismTest extends AbstractGraphTest +public abstract class PrismTest extends AbstractGraphTest { - - private static class TestPredicate - implements Predicate + void set( final int m, final int n ) { - private final int n; - - TestPredicate( int n ) + setGraph( new Prism( m, n ) ); + createPresentNodeRanges( m, n ); + createEdgeArrays( m, n, new Predicate() { - super(); - this.n = n; - } - - public boolean evaluate( Object object ) - { - Graph.Edge edge = (Graph.Edge) object; - if( !edge.isDirected() ) { - return false; + @SuppressWarnings( "unchecked" ) + public boolean evaluate( Object object ) + { + Graph.Edge edge = (Graph.Edge) object; + if( !edge.isDirected() ) { + return false; + } + List< Integer > tail = (List< Integer >) edge.getTail(); + List< Integer > head = (List< Integer >) edge.getHead(); + int tailA = tail.get( 0 ).intValue(); + int tailB = tail.get( 1 ).intValue(); + int headA = head.get( 0 ).intValue(); + int headB = head.get( 1 ).intValue(); + if( tailA == headA ) { + return tailB + 1 == headB; + } else if( tailB == headB ) { + return (tailA + 1 == headA) + || (tailA == n - 1 && headA == 0); + } else { + return false; + } } - List tail = (List) edge.getTail(); - List head = (List) edge.getHead(); - int tailA = ((Integer) tail.get( 0 )).intValue(); - int tailB = ((Integer) tail.get( 1 )).intValue(); - int headA = ((Integer) head.get( 0 )).intValue(); - int headB = ((Integer) head.get( 1 )).intValue(); - if( tailA == headA ) { - return tailB + 1 == headB; - } else if( tailB == headB ) { - return (tailA + 1 == headA) - || (tailA == n - 1 && headA == 0); - } else { - return false; - } - } + } ); } - private int m; - private int n; - - - public PrismTest( int m, int n ) + public static class Test_3_2 extends PrismTest { - super(); - this.m = m; - this.n = n; + @Before + public void init() + { + set( 3, 2 ); + } } - - @Override - protected void setUp() - throws Exception + public static class Test_3_5 extends PrismTest { - super.setUp(); - setUp( new Prism( m, n ) ); - createPresentNodeRanges( m, n ); - createEdgeArrays( m, n, new TestPredicate( m ) ); + @Before + public void init() + { + set( 3, 5 ); + } } - - private static Test suite( int m, int n ) + public static class Test_5_2 extends PrismTest { - return new PrismTest( m, n ).getInstanceSuite( "Prism[" + m + "," + n + "]" ); + @Before + public void init() + { + set( 5, 2 ); + } } - - public static Test suite() + public static class Test_5_5 extends PrismTest { - TestSuite suite = new TestSuite( "Prism Tests" ); - suite.addTest( suite( 3, 2 ) ); - suite.addTest( suite( 3, 5 ) ); - suite.addTest( suite( 5, 2 ) ); - suite.addTest( suite( 5, 5 ) ); - return suite; + @Before + public void init() + { + set( 5, 5 ); + } } - - - public static void main( String[] args ) - { - junit.textui.TestRunner.run( suite() ); - } - } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/StarTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/StarTest.java 2010-09-15 22:00:18 UTC (rev 886) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/StarTest.java 2010-09-15 22:22:57 UTC (rev 887) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -15,22 +15,25 @@ package com.phoenixst.plexus.examples; -import junit.framework.*; - import org.apache.commons.collections.Predicate; +import org.junit.Before; -import com.phoenixst.plexus.*; +import com.phoenixst.plexus.AbstractGraphTest; +import com.phoenixst.plexus.Graph; /** - * A {@link Star} tester. + * A {@link Star} tester. * - * @author Ray A. Conner + * @author rconner */ -public class StarTest extends AbstractGraphTest +public abstract class StarTest extends AbstractGraphTest { - - private static final Predicate TEST_PREDICATE = new Predicate() + void set( final int n ) + { + setGraph( new Star( n ) ); + createPresentNodeRanges( n + 1 ); + createEdgeArrays( n + 1, new Predicate() { public boolean evaluate( Object object ) { @@ -42,49 +45,43 @@ int head = ((Integer) edge.getHead()).intValue(); return tail == 0 && head != 0; } - }; - - - private final int n; - - - public StarTest( int n ) - { - super(); - this.n = n; + } ); } - @Override - protected void setUp() - throws Exception + public static class Test_0 extends StarTest { - super.setUp(); - setUp( new Star( n ) ); - createPresentNodeRanges( n + 1 ); - createEdgeArrays( n + 1, TEST_PREDICATE ); + @Before + public void init() + { + set( 0 ); + } } - - private static Test suite( int n ) + public static class Test_1 extends StarTest { - return new StarTest( n ).getInstanceSuite( "Star[" + n + "]" ); + @Before + public void init() + { + set( 1 ); + } } - - public static Test suite() + public static class Test_3 extends StarTest { - TestSuite suite = new TestSuite( "Star Tests" ); - suite.addTest( suite( 0 ) ); - suite.addTest( suite( 1 ) ); - suite.addTest( suite( 5 ) ); - return suite; + @Before + public void init() + { + set( 3 ); + } } - - public static void main( String[] args ) + public static class Test_5 extends StarTest { - junit.textui.TestRunner.run( suite() ); + @Before + public void init() + { + set( 5 ); + } } - } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/ToroidalMeshTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/ToroidalMeshTest.java 2010-09-15 22:00:18 UTC (rev 886) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/ToroidalMeshTest.java 2010-09-15 22:22:57 UTC (rev 887) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -17,102 +17,86 @@ import java.util.List; -import junit.framework.*; - import org.apache.commons.collections.Predicate; +import org.junit.Before; -import com.phoenixst.plexus.*; +import com.phoenixst.plexus.AbstractGraphTest; +import com.phoenixst.plexus.Graph; /** - * A {@link ToroidalMesh} tester. + * A {@link ToroidalMesh} tester. * - * @author Ray A. Conner + * @author rconner */ -public class ToroidalMeshTest extends AbstractGraphTest +public abstract class ToroidalMeshTest extends AbstractGraphTest { - - private static class TestPredicate - implements Predicate + void set( final int m, final int n ) { - private final int m; - private final int n; - - TestPredicate( int m, int n ) + setGraph( new ToroidalMesh( m, n ) ); + createPresentNodeRanges( m, n ); + createEdgeArrays( m, n, new Predicate() { - super(); - this.m = m; - this.n = n; - } - - public boolean evaluate( Object object ) - { - Graph.Edge edge = (Graph.Edge) object; - if( !edge.isDirected() ) { - return false; + @SuppressWarnings( "unchecked" ) + public boolean evaluate( Object object ) + { + Graph.Edge edge = (Graph.Edge) object; + if( !edge.isDirected() ) { + return false; + } + List< Integer > tail = (List< Integer >) edge.getTail(); + List< Integer > head = (List< Integer >) edge.getHead(); + int tailA = tail.get( 0 ).intValue(); + int tailB = tail.get( 1 ).intValue(); + int headA = head.get( 0 ).intValue(); + int headB = head.get( 1 ).intValue(); + if( tailA == headA ) { + return (tailB + 1 == headB) + || (tailB == n - 1 && headB == 0); + } else if( tailB == headB ) { + return (tailA + 1 == headA) + || (tailA == m - 1 && headA == 0); + } else { + return false; + } } - List tail = (List) edge.getTail(); - List head = (List) edge.getHead(); - int tailA = ((Integer) tail.get( 0 )).intValue(); - int tailB = ((Integer) tail.get( 1 )).intValue(); - int headA = ((Integer) head.get( 0 )).intValue(); - int headB = ((Integer) head.get( 1 )).intValue(); - if( tailA == headA ) { - return (tailB + 1 == headB) - || (tailB == n - 1 && headB == 0); - } else if( tailB == headB ) { - return (tailA + 1 == headA) - || (tailA == m - 1 && headA == 0); - } else { - return false; - } - } + } ); } - private int m; - private int n; - - - public ToroidalMeshTest( int m, int n ) + public static class Test_3_3 extends ToroidalMeshTest { - super(); - this.m = m; - this.n = n; + @Before + public void init() + { + set( 3, 3 ); + } } - - @Override - protected void setUp() - throws Exception + public static class Test_3_5 extends ToroidalMeshTest { - super.setUp(); - setUp( new ToroidalMesh( m, n ) ); - createPresentNodeRanges( m, n ); - createEdgeArrays( m, n, new TestPredicate( m, n ) ); + @Before + public void init() + { + set( 3, 5 ); + } } - - private static Test suite( int m, int n ) + public static class Test_5_3 extends ToroidalMeshTest { - return new ToroidalMeshTest( m, n ).getInstanceSuite( "Torus[" + m + "," + n + "]" ); + @Before + public void init() + { + set( 5, 3 ); + } } - - public static Test suite() + public static class Test_5_5 extends ToroidalMeshTest { - TestSuite suite = new TestSuite( "ToroidalMesh Tests" ); - suite.addTest( suite( 3, 3 ) ); - suite.addTest( suite( 3, 5 ) ); - suite.addTest( suite( 5, 3 ) ); - suite.addTest( suite( 5, 5 ) ); - return suite; + @Before + public void init() + { + set( 5, 5 ); + } } - - - public static void main( String[] args ) - { - junit.textui.TestRunner.run( suite() ); - } - } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/WheelTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/WheelTest.java 2010-09-15 22:00:18 UTC (rev 886) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/WheelTest.java 2010-09-15 22:22:57 UTC (rev 887) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -15,86 +15,57 @@ package com.phoenixst.plexus.examples; -import junit.framework.*; - import org.apache.commons.collections.Predicate; +import org.junit.Before; -import com.phoenixst.plexus.*; +import com.phoenixst.plexus.AbstractGraphTest; +import com.phoenixst.plexus.Graph; /** - * A {@link Wheel} tester. + * A {@link Wheel} tester. * - * @author Ray A. Conner + * @author rconner */ -public class WheelTest extends AbstractGraphTest +public abstract class WheelTest extends AbstractGraphTest { - - private static class TestPredicate - implements Predicate + void set( final int n ) { - private final int n; - - TestPredicate( int n ) + setGraph( new Wheel( n ) ); + createPresentNodeRanges( n + 1 ); + createEdgeArrays( n + 1, new Predicate() { - super(); - this.n = n; - } - - public boolean evaluate( Object object ) - { - Graph.Edge edge = (Graph.Edge) object; - if( !edge.isDirected() ) { - return false; + public boolean evaluate( Object object ) + { + Graph.Edge edge = (Graph.Edge) object; + if( !edge.isDirected() ) { + return false; + } + int tail = ((Integer) edge.getTail()).intValue(); + int head = ((Integer) edge.getHead()).intValue(); + return ( tail == 0 ) + ? head != 0 + : (tail + 1 == head) || (tail == n && head == 1); } - int tail = ((Integer) edge.getTail()).intValue(); - int head = ((Integer) edge.getHead()).intValue(); - return ( tail == 0 ) - ? head != 0 - : (tail + 1 == head) || (tail == n && head == 1); - } + } ); } - private int n; - - - public WheelTest( int n ) + public static class Test_3 extends WheelTest { - super(); - this.n = n; + @Before + public void init() + { + set( 3 ); + } } - - @Override - protected void setUp() - throws Exception + public static class Test_5 extends WheelTest { - super.setUp(); - setUp( new Wheel( n ) ); - createPresentNodeRanges( n + 1 ); - createEdgeArrays( n + 1, new TestPredicate( n ) ); + @Before + public void init() + { + set( 5 ); + } } - - - private static Test suite( int n ) - { - return new WheelTest( n ).getInstanceSuite( "Wheel[" + n + "]" ); - } - - - public static Test suite() - { - TestSuite suite = new TestSuite( "Wheel Tests" ); - suite.addTest( suite( 3 ) ); - suite.addTest( suite( 5 ) ); - return suite; - } - - - public static void main( String[] args ) - { - junit.textui.TestRunner.run( suite() ); - } - } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/SingletonGraphTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/SingletonGraphTest.java 2010-09-15 22:00:18 UTC (rev 886) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/SingletonGraphTest.java 2010-09-15 22:22:57 UTC (rev 887) @@ -28,7 +28,7 @@ */ public abstract class SingletonGraphTest extends AbstractGraphTest { - void setNode( Object node ) + void setNode( final Object node ) { setGraph( new SingletonGraph( node ) ); setPresentNodes( node ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2010-09-16 15:33:33
|
Revision: 890 http://plexus.svn.sourceforge.net/plexus/?rev=890&view=rev Author: rconner Date: 2010-09-16 15:33:22 +0000 (Thu, 16 Sep 2010) Log Message: ----------- minor cleanup Modified Paths: -------------- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AbstractGraphTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/GraphPrinter.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-15 22:40:39 UTC (rev 889) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AbstractGraphTest.java 2010-09-16 15:33:22 UTC (rev 890) @@ -247,7 +247,7 @@ notPresentEdges = createEdgeArray( badEdges ); } - protected static Edge[] createEdgeArray( Collection< Edge > edges ) + private static Edge[] createEdgeArray( Collection< Edge > edges ) { Edge[] edgeArray = new Edge[edges.size()]; edges.toArray( edgeArray ); @@ -503,7 +503,6 @@ for( Edge edge : presentEdges ) { assertTrue( testEdges.contains( new SimpleObjectEdge( edge.getUserObject(), edge.getTail(), edge.getHead(), edge.isDirected() ) ) ); - } for( Edge edge : notPresentEdges ) { assertFalse( testEdges.contains( new SimpleObjectEdge( edge.getUserObject(), edge.getTail(), Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/GraphPrinter.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/GraphPrinter.java 2010-09-15 22:40:39 UTC (rev 889) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/GraphPrinter.java 2010-09-16 15:33:22 UTC (rev 890) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2005 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -16,8 +16,8 @@ package com.phoenixst.plexus; import java.io.PrintStream; -import java.util.Iterator; +import com.phoenixst.plexus.Graph.Edge; import com.phoenixst.plexus.examples.CompleteBipartiteGraph; import com.phoenixst.plexus.examples.CompleteGraph; import com.phoenixst.plexus.examples.CompleteTree; @@ -33,9 +33,11 @@ /** - * A {@link Graph} printing utility. + * A {@link Graph} printing utility. * - * @author Ray A. Conner + * FIXME: Move this, it's not a test. + * + * @author rconner */ public class GraphPrinter { @@ -53,7 +55,7 @@ Traverser t = graph.traverser( node, null ); while( t.hasNext() ) { Object adj = t.next(); - Graph.Edge edge = t.getEdge(); + Edge edge = t.getEdge(); if( edge.isDirected() ) { if( GraphUtils.equals( node, edge.getTail() ) ) { out.println( " " + node + " -- " + edge.getUserObject() + " -> " + adj ); @@ -67,7 +69,7 @@ } - public static void printEdge( PrintStream out, Graph.Edge edge ) + public static void printEdge( PrintStream out, Edge edge ) { Object object = edge.getUserObject(); Object tail = edge.getTail(); @@ -88,13 +90,13 @@ out.println( "#edges = " + graph.edges( null ).size() ); out.println( "\nNodes:" ); - for( Iterator i = graph.nodes( null ).iterator(); i.hasNext(); ) { - printNode( out, graph, i.next() ); + for( Object node : graph.nodes( null ) ) { + printNode( out, graph, node ); } out.println( "\nEdges:" ); - for( Iterator i = graph.edges( null ).iterator(); i.hasNext(); ) { - printEdge( out, (Graph.Edge) i.next() ); + for( Object edge : graph.edges( null ) ) { + printEdge( out, (Edge) edge ); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2010-09-16 15:48:16
|
Revision: 891 http://plexus.svn.sourceforge.net/plexus/?rev=891&view=rev Author: rconner Date: 2010-09-16 15:48:07 +0000 (Thu, 16 Sep 2010) Log Message: ----------- Fixing DefaultGraphTest, and moving DefaultGraphExamplesTest test cases into it. Modified Paths: -------------- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/DefaultGraphTest.java Removed Paths: ------------- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/DefaultGraphExamplesTest.java 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:33:22 UTC (rev 890) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/DefaultGraphTest.java 2010-09-16 15:48:07 UTC (rev 891) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 1994-2006 by Phoenix Software Technologists, + * Copyright (C) 1994-2010 by Phoenix Software Technologists, * Inc. and others. All rights reserved. * * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE @@ -15,81 +15,69 @@ package com.phoenixst.plexus; +import static org.junit.Assert.assertEquals; + import java.io.ByteArrayInputStream; 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.Iterator; import java.util.Set; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.Before; +import org.junit.Test; +import com.phoenixst.plexus.Graph.Edge; +import com.phoenixst.plexus.examples.CompleteGraph; +import com.phoenixst.plexus.examples.CompleteTree; +import com.phoenixst.plexus.examples.EmptyGraph; +import com.phoenixst.plexus.examples.Prism; import com.phoenixst.plexus.examples.RandomGraphFactory; +import com.phoenixst.plexus.examples.Wheel; /** - * A {@link DefaultGraph} tester. + * A {@link DefaultGraph} tester. * - * @author Ray A. Conner + * @author rconner */ -public class DefaultGraphTest extends AbstractGraphTest +public abstract class DefaultGraphTest extends AbstractGraphTest { + private static final Edge[] EMPTY_EDGE_ARRAY = new Edge[0]; - protected Graph graph; - - - public DefaultGraphTest( Graph graph ) + @SuppressWarnings( "unchecked" ) + void set( final Graph graph ) { - super(); - this.graph = graph; - } - - - @Override - protected void setUp() - throws Exception - { - super.setUp(); Graph defaultGraph = new DefaultGraph(); - Set goodNodes = new HashSet(); - Set goodEdges = new HashSet(); - Set testEdges = new HashSet(); - Set badEdges = new HashSet(); + 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. - Iterator nodeIter = graph.nodes( null ).iterator(); - while( nodeIter.hasNext() ) { - Object node = nodeIter.next(); + for( Object node : graph.nodes( null ) ) { defaultGraph.addNode( node ); goodNodes.add( node ); } - Iterator edgeIter = graph.edges( null ).iterator(); - while( edgeIter.hasNext() ) { - Graph.Edge edge = (Graph.Edge) edgeIter.next(); + for( Edge edge : (Collection< Edge >) graph.edges( null ) ) { Object userObject = edge.getUserObject(); Object tail = edge.getTail(); Object head = edge.getHead(); boolean isDirected = edge.isDirected(); - Graph.Edge testEdge = new SimpleObjectEdge( null, tail, head, 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 ) ); } } - Iterator tailIter = graph.nodes( null ).iterator(); - while( tailIter.hasNext() ) { - Object tail = tailIter.next(); - Iterator headIter = graph.nodes( null ).iterator(); - while( headIter.hasNext() ) { - Object head = headIter.next(); - Graph.Edge edge = new SimpleObjectEdge( null, tail, head, true ); + 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 ); } @@ -100,16 +88,15 @@ } } - setUp( defaultGraph ); + setGraph( defaultGraph ); - presentNodes = goodNodes.toArray(); - notPresentNodes = new Object[] { new Object() }; - - presentEdges = createEdgeArray( goodEdges ); - notPresentEdges = createEdgeArray( badEdges ); + setPresentNodes( goodNodes.toArray() ); + setNotPresentNodes( new Object() ); + setPresentEdges( goodEdges.toArray( EMPTY_EDGE_ARRAY ) ); + setNotPresentEdges( badEdges.toArray( EMPTY_EDGE_ARRAY ) ); } - + @Test public void testDeserialization() throws Exception { @@ -132,44 +119,221 @@ // Run the copy through the same setup, so we can use // present/notPresentNodes/Edges to test equality. - DefaultGraphTest copyTest = new DefaultGraphTest( (Graph) copy ); - copyTest.setUp(); - 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 ) ) ); + // FIXME +// DefaultGraphTest copyTest = new DefaultGraphTest(); +// copyTest.setGraph( (Graph) copy ); + +// 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 ) ) ); } - public static Test suite( Graph graph ) + public static class TestRandom_5_050 extends DefaultGraphTest { - return suite( graph, graph.toString() ); + @Before + public void init() + { + set( RandomGraphFactory.createStandardGraph( 5, 0.50 ) ); + } } + public static class TestRandom_100_001 extends DefaultGraphTest + { + @Before + public void init() + { + set( RandomGraphFactory.createStandardGraph( 100, 0.01 ) ); + } + } - public static Test suite( Graph graph, String graphName ) + public static class TestRandom_100_050 extends DefaultGraphTest { - String suiteName = "Default[" + graphName + "] Tests"; - TestSuite suite = new TestSuite( suiteName ); - suite.addTest( new DefaultGraphTest( graph ).getInstanceSuite( suiteName ) ); - return suite; + @Before + public void init() + { + set( RandomGraphFactory.createStandardGraph( 100, 0.50 ) ); + } } + public static class TestRandom_100_099 extends DefaultGraphTest + { + @Before + public void init() + { + set( RandomGraphFactory.createStandardGraph( 100, 0.99 ) ); + } + } - public static Test suite() + public static class TestEmpty_0 extends DefaultGraphTest { - TestSuite suite = new TestSuite( "DefaultGraph Tests" ); + @Before + public void init() + { + set( new EmptyGraph( 0 ) ); + } + } - // Use some random graphs, it's as good as anything else. - // DefaultGraphs that are copies of the simple examples are already - // covered by DefaultGraphExamplesTest. + public static class TestEmpty_1 extends DefaultGraphTest + { + @Before + public void init() + { + set( new EmptyGraph( 1 ) ); + } + } - suite.addTest( DefaultGraphTest.suite( RandomGraphFactory.createStandardGraph( 5, 0.50 ), "Random[5, 0.5]" ) ); - suite.addTest( DefaultGraphTest.suite( RandomGraphFactory.createStandardGraph( 100, 0.01 ), "Random[100, 0.01]" ) ); - suite.addTest( DefaultGraphTest.suite( RandomGraphFactory.createStandardGraph( 100, 0.50 ), "Random[100, 0.50]" ) ); - suite.addTest( DefaultGraphTest.suite( RandomGraphFactory.createStandardGraph( 100, 0.99 ), "Random[100, 0.99]" ) ); + public static class TestEmpty_5 extends DefaultGraphTest + { + @Before + public void init() + { + set( new EmptyGraph( 5 ) ); + } + } - return suite; + public static class TestComplete_1 extends DefaultGraphTest + { + @Before + public void init() + { + set( new CompleteGraph( 1 ) ); + } } + public static class TestComplete_2 extends DefaultGraphTest + { + @Before + public void init() + { + set( new CompleteGraph( 2 ) ); + } + } + + public static class TestComplete_3 extends DefaultGraphTest + { + @Before + public void init() + { + set( new CompleteGraph( 3 ) ); + } + } + + public static class TestComplete_5 extends DefaultGraphTest + { + @Before + public void init() + { + set( new CompleteGraph( 5 ) ); + } + } + + public static class TestTree_0_1 extends DefaultGraphTest + { + @Before + public void init() + { + set( new CompleteTree( 0, 1 ) ); + } + } + + public static class TestTree_0_10 extends DefaultGraphTest + { + @Before + public void init() + { + set( new CompleteTree( 0, 10 ) ); + } + } + + public static class TestTree_1_1 extends DefaultGraphTest + { + @Before + public void init() + { + set( new CompleteTree( 1, 1 ) ); + } + } + + public static class TestTree_1_5 extends DefaultGraphTest + { + @Before + public void init() + { + set( new CompleteTree( 1, 5 ) ); + } + } + + public static class TestTree_5_1 extends DefaultGraphTest + { + @Before + public void init() + { + set( new CompleteTree( 5, 1 ) ); + } + } + + public static class TestTree_2_3 extends DefaultGraphTest + { + @Before + public void init() + { + set( new CompleteTree( 2, 3 ) ); + } + } + + public static class TestWheel_3 extends DefaultGraphTest + { + @Before + public void init() + { + set( new Wheel( 3 ) ); + } + } + + public static class TestWheel_5 extends DefaultGraphTest + { + @Before + public void init() + { + set( new Wheel( 5 ) ); + } + } + + public static class TestPrism_3_2 extends DefaultGraphTest + { + @Before + public void init() + { + set( new Prism( 3, 2 ) ); + } + } + + public static class TestPrism_3_5 extends DefaultGraphTest + { + @Before + public void init() + { + set( new Prism( 3, 5 ) ); + } + } + + public static class TestPrism_5_2 extends DefaultGraphTest + { + @Before + public void init() + { + set( new Prism( 5, 2 ) ); + } + } + + public static class TestPrism_5_5 extends DefaultGraphTest + { + @Before + public void init() + { + set( new Prism( 5, 5 ) ); + } + } } Deleted: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/DefaultGraphExamplesTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/DefaultGraphExamplesTest.java 2010-09-16 15:33:22 UTC (rev 890) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/DefaultGraphExamplesTest.java 2010-09-16 15:48:07 UTC (rev 891) @@ -1,104 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 1994-2010 by Phoenix Software Technologists, - * Inc. and others. All rights reserved. - * - * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE - * COMMON PUBLIC LICENSE ("AGREEMENT") WHICH ACCOMPANIES IT. ANY - * USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES - * RECIPIENT'S ACCEPTANCE OF THE AGREEMENT. - * - * The license text can also be found at - * http://opensource.org/licenses/cpl.php - */ - -package com.phoenixst.plexus.examples; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import com.phoenixst.plexus.AbstractGraphTest; -import com.phoenixst.plexus.DefaultGraphTest; - - -/** - * A {@link com.phoenixst.plexus.DefaultGraph} tester for copies of examples - * graphs, at least the immutable operations. - * - * @author rconner - */ -public class DefaultGraphExamplesTest extends AbstractGraphTest -{ - - private DefaultGraphExamplesTest() - { - super(); - } - - public static Test emptySuite() - { - TestSuite suite = new TestSuite( "Default-Empty Tests" ); - suite.addTest( DefaultGraphTest.suite( new EmptyGraph( 0 ), "Empty[0]" ) ); - suite.addTest( DefaultGraphTest.suite( new EmptyGraph( 1 ), "Empty[1]" ) ); - suite.addTest( DefaultGraphTest.suite( new EmptyGraph( 5 ), "Empty[5]" ) ); - return suite; - } - - - public static Test completeSuite() - { - TestSuite suite = new TestSuite( "Default-CompleteGraph Tests" ); - suite.addTest( DefaultGraphTest.suite( new CompleteGraph( 1 ), "Complete[1]" ) ); - suite.addTest( DefaultGraphTest.suite( new CompleteGraph( 2 ), "Complete[2]" ) ); - suite.addTest( DefaultGraphTest.suite( new CompleteGraph( 3 ), "Complete[3]" ) ); - suite.addTest( DefaultGraphTest.suite( new CompleteGraph( 5 ), "Complete[5]" ) ); - return suite; - } - - - public static Test treeSuite() - { - TestSuite suite = new TestSuite( "Default-Tree Tests" ); - suite.addTest( DefaultGraphTest.suite( new CompleteTree( 0, 1 ), "Tree[0,1]" ) ); - suite.addTest( DefaultGraphTest.suite( new CompleteTree( 0, 10 ), "Tree[0,10]" ) ); - suite.addTest( DefaultGraphTest.suite( new CompleteTree( 1, 1 ), "Tree[1,1]" ) ); - suite.addTest( DefaultGraphTest.suite( new CompleteTree( 1, 5 ), "Tree[1,5]" ) ); - suite.addTest( DefaultGraphTest.suite( new CompleteTree( 5, 1 ), "Tree[5,1]" ) ); - suite.addTest( DefaultGraphTest.suite( new CompleteTree( 2, 3 ), "Tree[2,3]" ) ); - return suite; - } - - - public static Test wheelSuite() - { - TestSuite suite = new TestSuite( "Default-Wheel Tests" ); - suite.addTest( DefaultGraphTest.suite( new Wheel( 3 ), "Wheel[3]" ) ); - suite.addTest( DefaultGraphTest.suite( new Wheel( 5 ), "Wheel[5]" ) ); - return suite; - } - - - public static Test prismSuite() - { - TestSuite suite = new TestSuite( "Default-Prism Tests" ); - suite.addTest( DefaultGraphTest.suite( new Prism( 3, 2 ), "Prism[3,2]" ) ); - suite.addTest( DefaultGraphTest.suite( new Prism( 3, 5 ), "Prism[3,5]" ) ); - suite.addTest( DefaultGraphTest.suite( new Prism( 5, 2 ), "Prism[5,2]" ) ); - suite.addTest( DefaultGraphTest.suite( new Prism( 5, 5 ), "Prism[5,5]" ) ); - return suite; - } - - - public static Test suite() - { - TestSuite suite = new TestSuite( "DefaultGraph Example Tests" ); - suite.addTest( emptySuite() ); - suite.addTest( completeSuite() ); - suite.addTest( treeSuite() ); - suite.addTest( wheelSuite() ); - suite.addTest( prismSuite() ); - return suite; - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <rc...@us...> - 2010-09-16 16:38:12
|
Revision: 896 http://plexus.svn.sourceforge.net/plexus/?rev=896&view=rev Author: rconner Date: 2010-09-16 16:38:05 +0000 (Thu, 16 Sep 2010) Log Message: ----------- getting rid of some PMD warnings. no functional change Modified Paths: -------------- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AbstractGraphTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/DefaultGraphTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/GraphPrinter.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/SimpleObjectEdge.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteBipartiteGraphTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteGraphTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteTreeTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CycleTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/EmptyGraphTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PathTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PetersenGraphTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PlanarMeshTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PrismTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/StarTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/ToroidalMeshTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/WheelTest.java trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/SingletonGraphTest.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 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AbstractGraphTest.java 2010-09-16 16:38:05 UTC (rev 896) @@ -117,7 +117,7 @@ //////////////////////////////////////// @SuppressWarnings( "unchecked" ) - protected void setGraph( Graph graph ) + protected void setGraph( final Graph graph ) { g = graph; @@ -132,27 +132,27 @@ } } - protected void setPresentNodes( Object... presentNodes ) + protected void setPresentNodes( final Object... presentNodes ) { this.presentNodes = presentNodes; } - protected void setNotPresentNodes( Object... notPresentNodes ) + protected void setNotPresentNodes( final Object... notPresentNodes ) { this.notPresentNodes = notPresentNodes; } - protected void setPresentEdges( Edge... presentEdges ) + protected void setPresentEdges( final Edge... presentEdges ) { this.presentEdges = presentEdges; } - protected void setNotPresentEdges( Edge... notPresentEdges ) + protected void setNotPresentEdges( final Edge... notPresentEdges ) { this.notPresentEdges = notPresentEdges; } - protected void createPresentNodeRanges( int limit ) + protected void createPresentNodeRanges( final int limit ) { presentNodes = new Object[limit]; for( int i = 0; i < limit; i++ ) { @@ -165,7 +165,7 @@ Integer.valueOf( limit ) }; } - protected void createPresentNodeRanges( int limitA, int limitB ) + protected void createPresentNodeRanges( final int limitA, final int limitB ) { presentNodes = new Object[limitA * limitB]; for( int i = 0; i < limitA; i++ ) { @@ -187,7 +187,7 @@ new OrderedIntPair( limitA, limitB - 1 ) }; } - protected void createEdgeArrays( int limit, Predicate pred ) + protected void createEdgeArrays( final int limit, final Predicate pred ) { Set< Edge > goodEdges = new HashSet< Edge >(); Set< Edge > badEdges = new HashSet< Edge >(); @@ -215,7 +215,7 @@ notPresentEdges = createEdgeArray( badEdges ); } - protected void createEdgeArrays( int limitA, int limitB, Predicate pred ) + protected void createEdgeArrays( final int limitA, final int limitB, final Predicate pred ) { Set< Edge > goodEdges = new HashSet< Edge >(); Set< Edge > badEdges = new HashSet< Edge >(); @@ -247,7 +247,7 @@ notPresentEdges = createEdgeArray( badEdges ); } - private static Edge[] createEdgeArray( Collection< Edge > edges ) + private static Edge[] createEdgeArray( final Collection< Edge > edges ) { Edge[] edgeArray = new Edge[edges.size()]; edges.toArray( edgeArray ); @@ -289,14 +289,14 @@ // Helper methods //////////////////////////////////////// - private static boolean isSelfEdge( Edge edge ) + private static boolean isSelfEdge( final Edge edge ) { Object tail = edge.getTail(); Object head = edge.getHead(); return ( tail == null ) ? head == null : tail.equals( head ); } - private void testEdge( Edge edge, Object tail, Object head ) + private void validateEdge( final Edge edge, final Object tail, final Object head ) { Object edgeTail = edge.getTail(); Object edgeHead = edge.getHead(); @@ -338,7 +338,7 @@ } } - private void testNotPresentNodes( Closure closure ) + private void validateNotPresentNodes( final Closure closure ) { // Check that using nodes not present in the graph throws an // exception. @@ -393,9 +393,9 @@ assertEquals( count, g.degree( node ) ); } - testNotPresentNodes( new Closure() + validateNotPresentNodes( new Closure() { - public void execute( Object object ) + public void execute( final Object object ) { getGraph().degree( object ); } @@ -416,9 +416,9 @@ assertEquals( count, g.degree( node, GraphUtils.OUT_TRAVERSER_PREDICATE ) ); } - testNotPresentNodes( new Closure() + validateNotPresentNodes( new Closure() { - public void execute( Object object ) + public void execute( final Object object ) { getGraph().degree( object, GraphUtils.OUT_TRAVERSER_PREDICATE ); } @@ -439,9 +439,9 @@ assertEquals( count, g.degree( node, GraphUtils.IN_TRAVERSER_PREDICATE ) ); } - testNotPresentNodes( new Closure() + validateNotPresentNodes( new Closure() { - public void execute( Object object ) + public void execute( final Object object ) { getGraph().degree( object, GraphUtils.IN_TRAVERSER_PREDICATE ); } @@ -486,7 +486,7 @@ Predicate edgePred = EdgePredicateFactory.createEqualsNodes( tail, head, DIR_MASK ); Edge edge = g.getEdge( edgePred ); if( edge != null ) { - testEdge( edge, tail, head ); + validateEdge( edge, tail, head ); } } } @@ -543,7 +543,7 @@ int count; for( count = 0; edgeIter.hasNext(); count++ ) { Edge edge = (Edge) edgeIter.next(); - testEdge( edge, edge.getTail(), edge.getHead() ); + validateEdge( edge, edge.getTail(), edge.getHead() ); } try { edgeIter.next(); @@ -574,7 +574,7 @@ if( isSelfEdge( edge ) ) { selfCount++; } - testEdge( edge, tail, head ); + validateEdge( edge, tail, head ); totalCount++; if( edge.isDirected() ) { // Make sure we get it twice since all @@ -633,9 +633,9 @@ edges.add( edge ); Object tail = edge.getTail(); if( ( node == null ) ? ( tail == null ) : node.equals( tail ) ) { - testEdge( edge, node, adjNode ); + validateEdge( edge, node, adjNode ); } else { - testEdge( edge, adjNode, node ); + validateEdge( edge, adjNode, node ); } } try { @@ -651,9 +651,9 @@ assertEquals( totalCount + selfCount, 2 * realEdges.size() ); - testNotPresentNodes( new Closure() + validateNotPresentNodes( new Closure() { - public void execute( Object object ) + public void execute( final Object object ) { getGraph().traverser( object, null ); } @@ -679,7 +679,7 @@ Edge edge = t.getEdge(); edges.add( edge ); - testEdge( edge, node, adjNode ); + validateEdge( edge, node, adjNode ); } try { t.next(); @@ -692,9 +692,9 @@ assertEquals( count, edges.size() ); } - testNotPresentNodes( new Closure() + validateNotPresentNodes( new Closure() { - public void execute( Object object ) + public void execute( final Object object ) { getGraph().traverser( object, GraphUtils.OUT_TRAVERSER_PREDICATE ); } @@ -720,7 +720,7 @@ Edge edge = t.getEdge(); edges.add( edge ); - testEdge( edge, adjNode, node ); + validateEdge( edge, adjNode, node ); } try { t.next(); @@ -733,9 +733,9 @@ assertEquals( count, edges.size() ); } - testNotPresentNodes( new Closure() + validateNotPresentNodes( new Closure() { - public void execute( Object object ) + public void execute( final Object object ) { getGraph().traverser( object, GraphUtils.IN_TRAVERSER_PREDICATE ); } @@ -762,7 +762,7 @@ { private static final long serialVersionUID = 1L; - public OrderedIntPair( int first, int second ) + public OrderedIntPair( final int first, final int second ) { super( Integer.valueOf( first ), Integer.valueOf( second ) ); } 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 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/DefaultGraphTest.java 2010-09-16 16:38:05 UTC (rev 896) @@ -19,6 +19,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Arrays; @@ -43,6 +44,7 @@ * * @author rconner */ +@SuppressWarnings( "PMD.AbstractNaming" ) public abstract class DefaultGraphTest extends AbstractGraphTest { private static final Edge[] EMPTY_EDGE_ARRAY = new Edge[0]; @@ -59,7 +61,7 @@ @Test public void testDeserialization() - throws Exception + throws IOException, ClassNotFoundException { // Make sure we're not being tested inappropriately. assertEquals( DefaultGraph.class, getGraph().getClass() ); @@ -95,7 +97,7 @@ Set< Edge > badEdges = new HashSet< Edge >(); @SuppressWarnings( "unchecked" ) - GraphSetup( Graph graph ) + GraphSetup( final Graph graph ) { // Assumption is that the graph being copied works just fine. Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/GraphPrinter.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/GraphPrinter.java 2010-09-16 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/GraphPrinter.java 2010-09-16 16:38:05 UTC (rev 896) @@ -39,7 +39,7 @@ * * @author rconner */ -public class GraphPrinter +public final class GraphPrinter { private GraphPrinter() @@ -47,7 +47,7 @@ super(); } - public static void printNode( PrintStream out, Graph graph, Object node ) + public static void printNode( final PrintStream out, final Graph graph, final Object node ) { out.println( "Node " + node ); @@ -69,7 +69,7 @@ } - public static void printEdge( PrintStream out, Edge edge ) + public static void printEdge( final PrintStream out, final Edge edge ) { Object object = edge.getUserObject(); Object tail = edge.getTail(); @@ -82,7 +82,7 @@ } - public static void printGraph( PrintStream out, String msg, Graph graph ) + public static void printGraph( final PrintStream out, final String msg, final Graph graph ) { out.println( "\n" + msg ); out.println( "Graph = " + graph ); @@ -101,7 +101,7 @@ } - public static void printGraph( String msg, Graph graph ) + public static void printGraph( final String msg, final Graph graph ) { printGraph( System.out, msg, graph ); } @@ -146,7 +146,7 @@ } - public static void main( String[] args ) + public static void main( final String[] args ) { printStandardGraphs(); } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/SimpleObjectEdge.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/SimpleObjectEdge.java 2010-09-16 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/SimpleObjectEdge.java 2010-09-16 16:38:05 UTC (rev 896) @@ -39,7 +39,7 @@ /** * Creates a new <code>SimpleObjectEdge</code>. */ - public SimpleObjectEdge( Object object, Object tail, Object head, boolean directed ) + public SimpleObjectEdge( final Object object, final Object tail, final Object head, final boolean directed ) { super( object, tail, head, directed ); } @@ -49,7 +49,7 @@ // Other methods //////////////////////////////////////// - private boolean equals( Object tail, Object head ) + private boolean equals( final Object tail, final Object head ) { return GraphUtils.equals( getTail(), tail ) && GraphUtils.equals( getHead(), head ); @@ -61,7 +61,7 @@ * object. */ @Override - public boolean equals( Object object ) + public boolean equals( final Object object ) { if( !( object instanceof SimpleObjectEdge ) ) { return false; @@ -80,7 +80,7 @@ && equals( edge.getHead(), edge.getTail() ); } - private int hashCode( Object object ) + private int hashCode( final Object object ) { return object == null ? 0 : object.hashCode(); } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteBipartiteGraphTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteBipartiteGraphTest.java 2010-09-16 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteBipartiteGraphTest.java 2010-09-16 16:38:05 UTC (rev 896) @@ -27,6 +27,7 @@ * * @author rconner */ +@SuppressWarnings( "PMD.AbstractNaming" ) public abstract class CompleteBipartiteGraphTest extends AbstractGraphTest { void set( final int m, final int n ) @@ -35,7 +36,7 @@ createPresentNodeRanges( m + n ); createEdgeArrays( m + n, new Predicate() { - public boolean evaluate( Object object ) + public boolean evaluate( final Object object ) { Edge edge = (Edge) object; if( !edge.isDirected() ) { Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteGraphTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteGraphTest.java 2010-09-16 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteGraphTest.java 2010-09-16 16:38:05 UTC (rev 896) @@ -27,6 +27,7 @@ * * @author rconner */ +@SuppressWarnings( "PMD.AbstractNaming" ) public abstract class CompleteGraphTest extends AbstractGraphTest { void set( final int n ) @@ -35,7 +36,7 @@ createPresentNodeRanges( n ); createEdgeArrays( n, new Predicate() { - public boolean evaluate( Object object ) + public boolean evaluate( final Object object ) { Edge edge = (Edge) object; if( !edge.isDirected() ) { Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteTreeTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteTreeTest.java 2010-09-16 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteTreeTest.java 2010-09-16 16:38:05 UTC (rev 896) @@ -27,6 +27,7 @@ * * @author rconner */ +@SuppressWarnings( "PMD.AbstractNaming" ) public abstract class CompleteTreeTest extends AbstractGraphTest { void set( final int height, final int numChildren ) @@ -47,7 +48,7 @@ createPresentNodeRanges( n ); createEdgeArrays( n, new Predicate() { - public boolean evaluate( Object object ) + public boolean evaluate( final Object object ) { Edge edge = (Edge) object; if( !edge.isDirected() ) { Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CycleTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CycleTest.java 2010-09-16 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CycleTest.java 2010-09-16 16:38:05 UTC (rev 896) @@ -27,6 +27,7 @@ * * @author rconner */ +@SuppressWarnings( "PMD.AbstractNaming" ) public abstract class CycleTest extends AbstractGraphTest { void set( final int n ) @@ -35,7 +36,7 @@ createPresentNodeRanges( n ); createEdgeArrays( n, new Predicate() { - public boolean evaluate( Object object ) + public boolean evaluate( final Object object ) { Edge edge = (Edge) object; if( !edge.isDirected() ) { Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/EmptyGraphTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/EmptyGraphTest.java 2010-09-16 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/EmptyGraphTest.java 2010-09-16 16:38:05 UTC (rev 896) @@ -26,6 +26,7 @@ * * @author rconner */ +@SuppressWarnings( "PMD.AbstractNaming" ) public abstract class EmptyGraphTest extends AbstractGraphTest { void set( final int n ) @@ -34,7 +35,7 @@ createPresentNodeRanges( n ); createEdgeArrays( n, new Predicate() { - public boolean evaluate( Object object ) + public boolean evaluate( final Object object ) { return false; } Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PathTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PathTest.java 2010-09-16 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PathTest.java 2010-09-16 16:38:05 UTC (rev 896) @@ -27,6 +27,7 @@ * * @author rconner */ +@SuppressWarnings( "PMD.AbstractNaming" ) public abstract class PathTest extends AbstractGraphTest { void set( final int n ) @@ -35,7 +36,7 @@ createPresentNodeRanges( n ); createEdgeArrays( n, new Predicate() { - public boolean evaluate( Object object ) + public boolean evaluate( final Object object ) { Edge edge = (Edge) object; if( !edge.isDirected() ) { Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PetersenGraphTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PetersenGraphTest.java 2010-09-16 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PetersenGraphTest.java 2010-09-16 16:38:05 UTC (rev 896) @@ -27,6 +27,7 @@ * * @author rconner */ +@SuppressWarnings( "PMD.TestClassWithoutTestCases" ) public class PetersenGraphTest extends AbstractGraphTest { @Before @@ -37,7 +38,7 @@ createEdgeArrays( 10, new Predicate() { // Assumes tail < head - private boolean evaluate( int tail, int head ) + private boolean evaluate( final int tail, final int head ) { int diff = head - tail; if( tail < 5 ) { @@ -48,7 +49,7 @@ return diff == 2 || diff == 3; } - public boolean evaluate( Object object ) + public boolean evaluate( final Object object ) { Edge edge = (Edge) object; if( edge.isDirected() ) { Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PlanarMeshTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PlanarMeshTest.java 2010-09-16 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PlanarMeshTest.java 2010-09-16 16:38:05 UTC (rev 896) @@ -29,6 +29,7 @@ * * @author rconner */ +@SuppressWarnings( "PMD.AbstractNaming" ) public abstract class PlanarMeshTest extends AbstractGraphTest { void set( final int m, final int n ) @@ -38,7 +39,7 @@ createEdgeArrays( m, n, new Predicate() { @SuppressWarnings( "unchecked" ) - public boolean evaluate( Object object ) + public boolean evaluate( final Object object ) { Edge edge = (Edge) object; if( !edge.isDirected() ) { Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PrismTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PrismTest.java 2010-09-16 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PrismTest.java 2010-09-16 16:38:05 UTC (rev 896) @@ -29,6 +29,7 @@ * * @author rconner */ +@SuppressWarnings( "PMD.AbstractNaming" ) public abstract class PrismTest extends AbstractGraphTest { void set( final int m, final int n ) @@ -38,7 +39,7 @@ createEdgeArrays( m, n, new Predicate() { @SuppressWarnings( "unchecked" ) - public boolean evaluate( Object object ) + public boolean evaluate( final Object object ) { Edge edge = (Edge) object; if( !edge.isDirected() ) { Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/StarTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/StarTest.java 2010-09-16 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/StarTest.java 2010-09-16 16:38:05 UTC (rev 896) @@ -27,6 +27,7 @@ * * @author rconner */ +@SuppressWarnings( "PMD.AbstractNaming" ) public abstract class StarTest extends AbstractGraphTest { void set( final int n ) @@ -35,7 +36,7 @@ createPresentNodeRanges( n + 1 ); createEdgeArrays( n + 1, new Predicate() { - public boolean evaluate( Object object ) + public boolean evaluate( final Object object ) { Edge edge = (Edge) object; if( !edge.isDirected() ) { Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/ToroidalMeshTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/ToroidalMeshTest.java 2010-09-16 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/ToroidalMeshTest.java 2010-09-16 16:38:05 UTC (rev 896) @@ -29,6 +29,7 @@ * * @author rconner */ +@SuppressWarnings( "PMD.AbstractNaming" ) public abstract class ToroidalMeshTest extends AbstractGraphTest { void set( final int m, final int n ) @@ -38,7 +39,7 @@ createEdgeArrays( m, n, new Predicate() { @SuppressWarnings( "unchecked" ) - public boolean evaluate( Object object ) + public boolean evaluate( final Object object ) { Edge edge = (Edge) object; if( !edge.isDirected() ) { Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/WheelTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/WheelTest.java 2010-09-16 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/WheelTest.java 2010-09-16 16:38:05 UTC (rev 896) @@ -27,6 +27,7 @@ * * @author rconner */ +@SuppressWarnings( "PMD.AbstractNaming" ) public abstract class WheelTest extends AbstractGraphTest { void set( final int n ) @@ -35,7 +36,7 @@ createPresentNodeRanges( n + 1 ); createEdgeArrays( n + 1, new Predicate() { - public boolean evaluate( Object object ) + public boolean evaluate( final Object object ) { Edge edge = (Edge) object; if( !edge.isDirected() ) { Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/SingletonGraphTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/SingletonGraphTest.java 2010-09-16 16:17:44 UTC (rev 895) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/SingletonGraphTest.java 2010-09-16 16:38:05 UTC (rev 896) @@ -26,6 +26,7 @@ * * @author rconner */ +@SuppressWarnings( "PMD.AbstractNaming" ) public abstract class SingletonGraphTest extends AbstractGraphTest { void setNode( final Object node ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |