plexus-svn Mailing List for Plexus Graph Library
Status: Alpha
Brought to you by:
rconner
You can subscribe to this list here.
2010 |
Jan
(3) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(50) |
Oct
(2) |
Nov
(3) |
Dec
|
---|
From: <rc...@us...> - 2010-11-19 23:45:48
|
Revision: 905 http://plexus.svn.sourceforge.net/plexus/?rev=905&view=rev Author: rconner Date: 2010-11-19 23:45:41 +0000 (Fri, 19 Nov 2010) Log Message: ----------- refactor failure testing to use new matchers Modified Paths: -------------- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AbstractGraphTest.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-11-19 23:42:32 UTC (rev 904) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AbstractGraphTest.java 2010-11-19 23:45:41 UTC (rev 905) @@ -15,29 +15,32 @@ package com.phoenixst.plexus; +import static com.phoenixst.test.TaskMatchers.cannot; +import static com.phoenixst.test.TaskMatchers.isDone; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.matchers.JUnitMatchers.everyItem; import static org.junit.matchers.JUnitMatchers.hasItem; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; +import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; -import java.util.NoSuchElementException; import java.util.Set; -import org.apache.commons.collections.Closure; import org.apache.commons.collections.Predicate; import org.junit.Test; import com.phoenixst.collections.OrderedPair; import com.phoenixst.plexus.Graph.Edge; +import com.phoenixst.test.TaskMatchers.AbstractTask; +import com.phoenixst.test.TaskMatchers.Task; /** @@ -49,12 +52,6 @@ public abstract class AbstractGraphTest { - private static final String SHOULD_THROW_MESSAGE = "Should throw an Exception."; - - private static final String SHOULD_THROW_NO_SUCH_ELEMENT_MESSAGE = "Should throw a NoSuchElementException."; - - private static final String SHOULD_THROW_ILLEGAL_ARGUMENT_MESSAGE = "Should throw IllegalArgumentException."; - /** * Everything but directed in. */ @@ -308,6 +305,7 @@ return ( tail == null ) ? head == null : tail.equals( head ); } + @SuppressWarnings( "unchecked" ) private void validateEdge( final Edge edge, final Object tail, final Object head ) { Object edgeTail = edge.getTail(); @@ -340,37 +338,29 @@ assertThat( edge.getOtherEndpoint( head ), is( tail ) ); assertThat( edge.getOtherEndpoint( tail ), is( head ) ); - for( Object node : notPresentNodes ) { - try { - edge.getOtherEndpoint( node ); - fail( SHOULD_THROW_ILLEGAL_ARGUMENT_MESSAGE ); - } catch( IllegalArgumentException e ) { - // Do nothing + validateNotPresentNodes( new AbstractTask( "edge.getOtherEndpoint(node)" ) + { + public void execute( Object object ) + throws Throwable + { + edge.getOtherEndpoint( object ); } - } + }, IllegalArgumentException.class ); } - private void validateNotPresentNodes( final Closure closure ) + private void validateNotPresentNodes( final Task task, final Class< ? extends Throwable > ... exceptionTypes ) { - // Check that using nodes not present in the graph throws an - // exception. - for( Object node : notPresentNodes ) { - try { - closure.execute( node ); - fail( SHOULD_THROW_MESSAGE ); - } catch( ClassCastException e ) { - // Do nothing - } catch( IllegalArgumentException e ) { - // Do nothing - } catch( NoSuchNodeException e ) { - // Do nothing - } catch( NullPointerException e ) { - // Do nothing - } - } + assertThat( Arrays.asList( notPresentNodes ), + everyItem( cannot( task, exceptionTypes ) ) ); } + @SuppressWarnings( "unchecked" ) + private void validateNotPresentNodes( final Task task ) + { + validateNotPresentNodes( task, IllegalArgumentException.class, NoSuchNodeException.class, ClassCastException.class ); + } + //////////////////////////////////////// // Public test methods //////////////////////////////////////// @@ -405,9 +395,10 @@ assertThat( g.degree( node ), is( count ) ); } - validateNotPresentNodes( new Closure() + validateNotPresentNodes( new AbstractTask( "degree(node)" ) { - public void execute( final Object object ) + public void execute( Object object ) + throws Throwable { getGraph().degree( object ); } @@ -428,9 +419,10 @@ assertThat( g.degree( node, GraphUtils.OUT_TRAVERSER_PREDICATE ), is( count ) ); } - validateNotPresentNodes( new Closure() + validateNotPresentNodes( new AbstractTask( "degree(node,GraphUtils.OUT_TRAVERSER_PREDICATE)" ) { - public void execute( final Object object ) + public void execute( Object object ) + throws Throwable { getGraph().degree( object, GraphUtils.OUT_TRAVERSER_PREDICATE ); } @@ -451,9 +443,10 @@ assertThat( g.degree( node, GraphUtils.IN_TRAVERSER_PREDICATE ), is( count ) ); } - validateNotPresentNodes( new Closure() + validateNotPresentNodes( new AbstractTask( "degree(node,GraphUtils.IN_TRAVERSER_PREDICATE)" ) { - public void execute( final Object object ) + public void execute( Object object ) + throws Throwable { getGraph().degree( object, GraphUtils.IN_TRAVERSER_PREDICATE ); } @@ -529,13 +522,8 @@ for( count = 0; nodeIter.hasNext(); count++ ) { nodeIter.next(); } - try { - nodeIter.next(); - fail( SHOULD_THROW_NO_SUCH_ELEMENT_MESSAGE ); - } catch( NoSuchElementException e ) { - // Do nothing - } + assertThat( nodeIter, isDone() ); assertThat( nodes.size(), is( count ) ); } @@ -555,13 +543,8 @@ Edge edge = (Edge) edgeIter.next(); validateEdge( edge, edge.getTail(), edge.getHead() ); } - try { - edgeIter.next(); - fail( SHOULD_THROW_NO_SUCH_ELEMENT_MESSAGE ); - } catch( NoSuchElementException e ) { - // Do nothing - } + assertThat( edgeIter, isDone() ); assertThat( realEdges.size(), is( count ) ); } @@ -592,12 +575,8 @@ totalCount++; } } - try { - edgeIter.next(); - fail( SHOULD_THROW_NO_SUCH_ELEMENT_MESSAGE ); - } catch( NoSuchElementException e ) { - // Do nothing - } + + assertThat( edgeIter, isDone() ); } } @@ -648,22 +627,19 @@ validateEdge( edge, adjNode, node ); } } - try { - t.next(); - fail( SHOULD_THROW_NO_SUCH_ELEMENT_MESSAGE ); - } catch( NoSuchElementException e ) { - // Do nothing - } + assertThat( t, isDone() ); + // Check that each edge accessed by the traverser is unique. assertThat( edges.size(), is( count ) ); } assertThat( totalCount + selfCount, is( 2 * realEdges.size() ) ); - validateNotPresentNodes( new Closure() + validateNotPresentNodes( new AbstractTask( "traverser(node,null)" ) { - public void execute( final Object object ) + public void execute( Object object ) + throws Throwable { getGraph().traverser( object, null ); } @@ -691,20 +667,17 @@ edges.add( edge ); validateEdge( edge, node, adjNode ); } - try { - t.next(); - fail( SHOULD_THROW_NO_SUCH_ELEMENT_MESSAGE ); - } catch( NoSuchElementException e ) { - // Do nothing - } + assertThat( t, isDone() ); + // Check that each edge accessed by the traverser is unique. assertThat( edges.size(), is( count ) ); } - validateNotPresentNodes( new Closure() + validateNotPresentNodes( new AbstractTask( "traverser(node,OUT_TRAVERSER_PREDICATE)" ) { - public void execute( final Object object ) + public void execute( Object object ) + throws Throwable { getGraph().traverser( object, GraphUtils.OUT_TRAVERSER_PREDICATE ); } @@ -732,20 +705,17 @@ edges.add( edge ); validateEdge( edge, adjNode, node ); } - try { - t.next(); - fail( SHOULD_THROW_NO_SUCH_ELEMENT_MESSAGE ); - } catch( NoSuchElementException e ) { - // Do nothing - } + assertThat( t, isDone() ); + // Check that each edge accessed by the traverser is unique. assertThat( edges.size(), is( count ) ); } - validateNotPresentNodes( new Closure() + validateNotPresentNodes( new AbstractTask( "traverser(node,IN_TRAVERSER_PREDICATE)" ) { - public void execute( final Object object ) + public void execute( Object object ) + throws Throwable { getGraph().traverser( object, GraphUtils.IN_TRAVERSER_PREDICATE ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2010-11-19 23:42:38
|
Revision: 904 http://plexus.svn.sourceforge.net/plexus/?rev=904&view=rev Author: rconner Date: 2010-11-19 23:42:32 +0000 (Fri, 19 Nov 2010) Log Message: ----------- Making the behavior of a Product graph consistent with the documented Graph API. Graphs which don't allow null nodes should throw IllegalArgumentException when given them, everywhere except containsNode(). Modified Paths: -------------- trunk/plexus-graph/src/changes/changes.xml trunk/plexus-graph/src/main/java/com/phoenixst/plexus/operations/Product.java Modified: trunk/plexus-graph/src/changes/changes.xml =================================================================== --- trunk/plexus-graph/src/changes/changes.xml 2010-11-19 23:41:00 UTC (rev 903) +++ trunk/plexus-graph/src/changes/changes.xml 2010-11-19 23:42:32 UTC (rev 904) @@ -14,6 +14,13 @@ Fixed DefaultGraph deserialization. </action> + <action dev="rconner" type="fix"> + Product now throws an IllegalArgumentException when given a null + node argument instead of a NullPointerException, as mandated by + the Graph interface API. PlanarMesh, Prism, and ToroidalMesh are + subclasses of Product. + </action> + <action dev="rconner" type="update"> Reorganized into a standard maven project. </action> Modified: trunk/plexus-graph/src/main/java/com/phoenixst/plexus/operations/Product.java =================================================================== --- trunk/plexus-graph/src/main/java/com/phoenixst/plexus/operations/Product.java 2010-11-19 23:41:00 UTC (rev 903) +++ trunk/plexus-graph/src/main/java/com/phoenixst/plexus/operations/Product.java 2010-11-19 23:42:32 UTC (rev 904) @@ -181,6 +181,9 @@ @Override protected Traverser traverser( Object node ) { + if( node == null ) { + throw new IllegalArgumentException( "This graph does not permit null nodes." ); + } OrderedPair baseNode = (OrderedPair) node; Object leftNode = baseNode.getFirst(); Object rightNode = baseNode.getSecond(); @@ -254,6 +257,9 @@ @Override public int degree( Object node ) { + if( node == null ) { + throw new IllegalArgumentException( "This graph does not permit null nodes." ); + } OrderedPair baseNode = (OrderedPair) node; Object leftNode = baseNode.getFirst(); Object rightNode = baseNode.getSecond(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2010-11-19 23:41:06
|
Revision: 903 http://plexus.svn.sourceforge.net/plexus/?rev=903&view=rev Author: rconner Date: 2010-11-19 23:41:00 +0000 (Fri, 19 Nov 2010) Log Message: ----------- Checking in some pending changes while I'm waiting for unit tests elsewhere to run.... Added an AbstractTask base class so that toString() is easy to specify. Added a Matcher which matches if the argument Iterator.next() throws a NoSuchElementException. Modified Paths: -------------- trunk/plexus-graph/src/test/java/com/phoenixst/test/TaskMatchers.java Modified: trunk/plexus-graph/src/test/java/com/phoenixst/test/TaskMatchers.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/test/TaskMatchers.java 2010-10-20 17:01:27 UTC (rev 902) +++ trunk/plexus-graph/src/test/java/com/phoenixst/test/TaskMatchers.java 2010-11-19 23:41:00 UTC (rev 903) @@ -15,6 +15,9 @@ package com.phoenixst.test; +import java.util.Iterator; +import java.util.NoSuchElementException; + import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Factory; @@ -28,10 +31,8 @@ */ public final class TaskMatchers { - static final ThreadLocal< String > FAILURE_STRING = new ThreadLocal< String >(); - private TaskMatchers() { // prevent instantiation @@ -39,6 +40,29 @@ @Factory + public static Matcher< Iterator< ? > > isDone() + { + return new BaseMatcher< Iterator< ? > >() + { + public boolean matches( Object obj ) + { + try { + ((Iterator< ? >) obj).next(); + } catch( NoSuchElementException e ) { + return true; + } + return false; + } + + public void describeTo( Description description ) + { + description.appendText( "Iterator should be exhausted " ); + } + }; + } + + + @Factory public static < T > Matcher< T > can( final Task task ) { return new BaseMatcher< T >() @@ -108,4 +132,21 @@ public void execute( Object object ) throws Throwable; } + public abstract static class AbstractTask + implements Task + { + private final String name; + + public AbstractTask( String name ) + { + this.name = name; + } + + @Override + public String toString() + { + return name; + } + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2010-10-20 17:01:33
|
Revision: 902 http://plexus.svn.sourceforge.net/plexus/?rev=902&view=rev Author: rconner Date: 2010-10-20 17:01:27 +0000 (Wed, 20 Oct 2010) Log Message: ----------- updating changelog Modified Paths: -------------- trunk/plexus-graph/src/changes/changes.xml Modified: trunk/plexus-graph/src/changes/changes.xml =================================================================== --- trunk/plexus-graph/src/changes/changes.xml 2010-10-20 16:59:33 UTC (rev 901) +++ trunk/plexus-graph/src/changes/changes.xml 2010-10-20 17:01:27 UTC (rev 902) @@ -19,6 +19,10 @@ </action> <action dev="rconner" type="update"> + Migrated to JUnit 4. + </action> + + <action dev="rconner" type="update"> Removed @since and @version javadoc tags since they're not accurate, and it's not worth it to fix them. </action> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2010-10-20 16:59:39
|
Revision: 901 http://plexus.svn.sourceforge.net/plexus/?rev=901&view=rev Author: rconner Date: 2010-10-20 16:59:33 +0000 (Wed, 20 Oct 2010) Log Message: ----------- Removing DOCTYPE declaration, because the DTD is no longer at the specified URL, and eclipse spends many minutes trying to get it. Modified Paths: -------------- trunk/plexus-graph/src/main/config/checkstyle/checkstyle.xml Modified: trunk/plexus-graph/src/main/config/checkstyle/checkstyle.xml =================================================================== --- trunk/plexus-graph/src/main/config/checkstyle/checkstyle.xml 2010-09-30 17:15:54 UTC (rev 900) +++ trunk/plexus-graph/src/main/config/checkstyle/checkstyle.xml 2010-10-20 16:59:33 UTC (rev 901) @@ -1,7 +1,4 @@ <?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE module PUBLIC - "-//Puppy Crawl//DTD Check Configuration 1.2//EN" - "http://www.puppycrawl.com/dtds/configuration_1_2.dtd"> <!-- Checkstyle configuration for Plexus. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2010-09-30 17:16:00
|
Revision: 900 http://plexus.svn.sourceforge.net/plexus/?rev=900&view=rev Author: rconner Date: 2010-09-30 17:15:54 +0000 (Thu, 30 Sep 2010) Log Message: ----------- Before I forget, adding some custom hamcrest matchers I wrote. While a bit more generic, the real use case is being able to assert that doing something with every element of a collection throws an expected exception. The JUnit @Test(expected=...) will only assert that a method throws, not that something throws 100 times for 100 tested items. Added Paths: ----------- trunk/plexus-graph/src/test/java/com/phoenixst/test/ trunk/plexus-graph/src/test/java/com/phoenixst/test/TaskMatchers.java trunk/plexus-graph/src/test/java/com/phoenixst/test/TaskMatchersTest.java Added: trunk/plexus-graph/src/test/java/com/phoenixst/test/TaskMatchers.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/test/TaskMatchers.java (rev 0) +++ trunk/plexus-graph/src/test/java/com/phoenixst/test/TaskMatchers.java 2010-09-30 17:15:54 UTC (rev 900) @@ -0,0 +1,111 @@ +/* + * $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.test; + +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.hamcrest.Factory; +import org.hamcrest.Matcher; + + +/** + * Custom hamcrest matchers. + * + * @author rconner + */ +public final class TaskMatchers +{ + + static final ThreadLocal< String > FAILURE_STRING = new ThreadLocal< String >(); + + + private TaskMatchers() + { + // prevent instantiation + } + + + @Factory + public static < T > Matcher< T > can( final Task task ) + { + return new BaseMatcher< T >() + { + public boolean matches( final Object obj ) + { + FAILURE_STRING.remove(); + try { + task.execute( obj ); + return true; + } catch( Throwable t ) { + FAILURE_STRING.set( "item <" + obj + "> threw <" + t + ">" ); + return false; + } + } + + public void describeTo( final Description description ) + { + description.appendText( "can execute " ) + .appendValue( task ) + .appendText( "; " ) + .appendText( FAILURE_STRING.get() ); + } + }; + } + + @Factory + public static < T > Matcher< T > cannot( final Task task, final Class< ? extends Throwable > ... exceptionTypes ) + { + return new BaseMatcher< T >() + { + public boolean matches( final Object obj ) + { + FAILURE_STRING.remove(); + try { + task.execute( obj ); + FAILURE_STRING.set( "item <" + obj + "> did not throw" ); + return false; + } catch( Throwable t ) { + if( exceptionTypes.length == 0 ) { + return true; + } + for( Class< ? extends Throwable > type : exceptionTypes ) { + if( type.isInstance( t ) ) { + return true; + } + } + FAILURE_STRING.set( "item <" + obj + "> threw <" + t + ">" ); + return false; + } + } + + public void describeTo( final Description description ) + { + description.appendText( "throws one of " ) + .appendValue( exceptionTypes ) + .appendText( " when executing " ) + .appendValue( task ) + .appendText( "; " ) + .appendText( FAILURE_STRING.get() ); + } + }; + } + + public static interface Task + { + public void execute( Object object ) throws Throwable; + } + +} Property changes on: trunk/plexus-graph/src/test/java/com/phoenixst/test/TaskMatchers.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Date Revision Id Added: svn:eol-style + native Added: trunk/plexus-graph/src/test/java/com/phoenixst/test/TaskMatchersTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/test/TaskMatchersTest.java (rev 0) +++ trunk/plexus-graph/src/test/java/com/phoenixst/test/TaskMatchersTest.java 2010-09-30 17:15:54 UTC (rev 900) @@ -0,0 +1,117 @@ +/* + * $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.test; + +import static com.phoenixst.test.TaskMatchers.can; +import static com.phoenixst.test.TaskMatchers.cannot; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; +import static org.junit.matchers.JUnitMatchers.everyItem; +import static org.junit.matchers.JUnitMatchers.hasItem; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; + +import com.phoenixst.test.TaskMatchers.Task; + + +/** + * Tests for TaskMatchers. + * + * @author rconner + */ +@SuppressWarnings( { "boxing", "unchecked" } ) +public class TaskMatchersTest +{ + + private static final Task castToString = new Task() + { + public void execute( Object input ) + { + ( (String) input ).toString(); + } + + @Override + public String toString() + { + return "Cast to String"; + } + }; + + public TaskMatchersTest() + { + // do nothing + } + + @Test + public void allStrings() + { + List< Object > strings = Arrays.< Object >asList( "abc", "xyz", "foo" ); + assertThat( strings, everyItem( can( castToString ) ) ); + assertThat( strings, not( hasItem( cannot( castToString ) ) ) ); + } + + @Test + public void someStrings() + { + List< Object > mixed = Arrays.< Object >asList( "abc", 5, "foo" ); + assertThat( mixed, hasItem( can( castToString ) ) ); + assertThat( mixed, hasItem( not( can( castToString ) ) ) ); + assertThat( mixed, hasItem( cannot( castToString, ClassCastException.class ) ) ); + assertThat( mixed, hasItem( not( cannot( castToString ) ) ) ); + } + + @Test + public void noStrings() + { + List< Object > none = Arrays.< Object >asList( 1, 3, 24 ); + assertThat( none, not( hasItem( can( castToString ) ) ) ); + assertThat( none, everyItem( cannot( castToString, ClassCastException.class ) ) ); + } + + @Test + public void singleItems() + { + assertThat( "abc", can( castToString ) ); + assertThat( 5, cannot( castToString, ClassCastException.class ) ); + assertThat( null, cannot( castToString, NullPointerException.class ) ); + } + + // These methods are not part of the unit test, since they actually fail. + // They are here only to see what the assertion failure text looks like. + + public void failsToThrow() + { + List< Object > array = Arrays.< Object >asList( "abc", 5 ); + assertThat( array, everyItem( cannot( castToString, ClassCastException.class ) ) ); + } + + public void throwsWrongException() + { + List< Object > array = Arrays.< Object >asList( null, "abc" ); + assertThat( array, everyItem( cannot( castToString, ClassCastException.class ) ) ); + } + + public void throwsException() + { + List< Object > array = Arrays.< Object >asList( "abc", 5 ); + assertThat( array, everyItem( can( castToString ) ) ); + } + +} Property changes on: trunk/plexus-graph/src/test/java/com/phoenixst/test/TaskMatchersTest.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-16 17:56:36
|
Revision: 899 http://plexus.svn.sourceforge.net/plexus/?rev=899&view=rev Author: rconner Date: 2010-09-16 17:56:29 +0000 (Thu, 16 Sep 2010) Log Message: ----------- migrate to matcher idiom for tests Modified Paths: -------------- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AbstractGraphTest.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 17:49:36 UTC (rev 898) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/AbstractGraphTest.java 2010-09-16 17:56:29 UTC (rev 899) @@ -15,12 +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.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; +import static org.junit.matchers.JUnitMatchers.hasItem; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -44,6 +45,7 @@ * * @author rconner */ +@SuppressWarnings( { "boxing", "PMD.TooManyStaticImports" } ) public abstract class AbstractGraphTest { @@ -61,25 +63,25 @@ /** * The <code>Graph</code> to be tested. */ - private Graph g = null; + private Graph g; /** * Contains all nodes accessed by the graph's * <code>nodes( null ).iterator()</code> method. */ - private Set< Object > nodes = null; + private Set< Object > nodes; /** * Contains all edges accessed by the graph's * <code>edges( null ).iterator()</code> method. */ - private Set< Edge > realEdges = null; + private Set< Edge > realEdges; /** * Contains <code>SimpleObjectEdges</code> corresponding to all edges * accessed by the graph's <code>edges( null ).iterator()</code> method. */ - private Set< Edge > testEdges = null; + private Set< Edge > testEdges; /** * @@ -128,7 +130,7 @@ 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( createEdge( edge ) ); } } @@ -196,13 +198,13 @@ Object tail = Integer.valueOf( tailIndex ); for( int headIndex = 0; headIndex < limit; headIndex++ ) { Object head = Integer.valueOf( headIndex ); - Edge edge = new SimpleObjectEdge( null, tail, head, false ); + Edge edge = createEdge( null, tail, head, false ); if( pred.evaluate( edge ) ) { goodEdges.add( edge ); } else { badEdges.add( edge ); } - edge = new SimpleObjectEdge( null, tail, head, true ); + edge = createEdge( null, tail, head, true ); if( pred.evaluate( edge ) ) { goodEdges.add( edge ); } else { @@ -226,13 +228,13 @@ for( int headA = 0; headA < limitA; headA++ ) { for( int headB = 0; headB < limitB; headB++ ) { Object head = new OrderedIntPair( headA, headB ); - Edge edge = new SimpleObjectEdge( null, tail, head, false ); + Edge edge = createEdge( null, tail, head, false ); if( pred.evaluate( edge ) ) { goodEdges.add( edge ); } else { badEdges.add( edge ); } - edge = new SimpleObjectEdge( null, tail, head, true ); + edge = createEdge( null, tail, head, true ); if( pred.evaluate( edge ) ) { goodEdges.add( edge ); } else { @@ -289,6 +291,16 @@ // Helper methods //////////////////////////////////////// + protected static Edge createEdge( final Edge edge ) + { + return new SimpleObjectEdge( edge.getUserObject(), edge.getTail(), edge.getHead(), edge.isDirected() ); + } + + protected static Edge createEdge( final Object object, final Object tail, final Object head, final boolean isDirected ) + { + return new SimpleObjectEdge( object, tail, head, isDirected ); + } + private static boolean isSelfEdge( final Edge edge ) { Object tail = edge.getTail(); @@ -302,31 +314,31 @@ Object edgeHead = edge.getHead(); // Check that the edge endpoints are in the graph. - assertTrue( g.containsNode( edgeTail ) ); - assertTrue( g.containsNode( edgeHead ) ); - assertTrue( nodes.contains( edgeTail ) ); - assertTrue( nodes.contains( edgeHead ) ); + assertThat( g.containsNode( edgeTail ), is( true ) ); + assertThat( g.containsNode( edgeHead ), is( true ) ); + assertThat( nodes.contains( edgeTail ), is( true ) ); + assertThat( nodes.contains( edgeHead ), is( true ) ); // Check that the edge, actually goes from tail to head. if( edge.isDirected() ) { - assertEquals( tail, edgeTail ); - assertEquals( head, edgeHead ); + assertThat( edgeTail, is( tail ) ); + assertThat( edgeHead, is( head ) ); } else { if( ( tail == null ) ? ( edgeTail == null ) : tail.equals( edgeTail ) ) { - assertEquals( head, edgeHead ); + assertThat( edgeHead, is( head ) ); } else { - assertEquals( tail, edgeHead ); - assertEquals( head, edgeTail ); + assertThat( edgeHead, is( tail ) ); + assertThat( edgeTail, is( head ) ); } } // 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() ) ) ); + assertThat( realEdges, hasItem( edge ) ); + assertThat( testEdges, hasItem( createEdge( edge.getUserObject(), tail, head, edge.isDirected() ) ) ); // Check that getOtherEndpoint() works. - assertEquals( tail, edge.getOtherEndpoint( head ) ); - assertEquals( head, edge.getOtherEndpoint( tail ) ); + assertThat( edge.getOtherEndpoint( head ), is( tail ) ); + assertThat( edge.getOtherEndpoint( tail ), is( head ) ); for( Object node : notPresentNodes ) { try { @@ -366,13 +378,13 @@ @Test public void testNodeSize() { - assertEquals( nodes.size(), g.nodes( null ).size() ); + assertThat( g.nodes( null ).size(), is( nodes.size() ) ); } @Test public void testEdgeSize() { - assertEquals( realEdges.size(), g.edges( null ).size() ); + assertThat( g.edges( null ).size(), is( realEdges.size() ) ); } @Test @@ -390,7 +402,7 @@ count++; } } - assertEquals( count, g.degree( node ) ); + assertThat( g.degree( node ), is( count ) ); } validateNotPresentNodes( new Closure() @@ -413,7 +425,7 @@ for( count = 0; t.hasNext(); count++ ) { t.next(); } - assertEquals( count, g.degree( node, GraphUtils.OUT_TRAVERSER_PREDICATE ) ); + assertThat( g.degree( node, GraphUtils.OUT_TRAVERSER_PREDICATE ), is( count ) ); } validateNotPresentNodes( new Closure() @@ -436,7 +448,7 @@ for( count = 0; t.hasNext(); count++ ) { t.next(); } - assertEquals( count, g.degree( node, GraphUtils.IN_TRAVERSER_PREDICATE ) ); + assertThat( g.degree( node, GraphUtils.IN_TRAVERSER_PREDICATE ), is( count ) ); } validateNotPresentNodes( new Closure() @@ -454,15 +466,15 @@ // Check that every node accessed by the node iterator is // present in the graph. for( Object node : g.nodes( null ) ) { - assertTrue( g.containsNode( node ) ); + assertThat( g.containsNode( node ), is( true ) ); } // Check for supposedly present and not present nodes. for( Object node : presentNodes ) { - assertTrue( g.containsNode( node ) ); + assertThat( g.containsNode( node ), is( true ) ); } for( Object node : notPresentNodes ) { - assertFalse( g.containsNode( node ) ); + assertThat( g.containsNode( node ), is( false ) ); } } @@ -473,7 +485,7 @@ // Check that every edge accessed by the edge iterator is // present in the graph. for( Edge edge : (Collection< Edge >) g.edges( null ) ) { - assertTrue( g.containsEdge( edge ) ); + assertThat( g.containsEdge( edge ), is( true ) ); } } @@ -494,11 +506,11 @@ // Check for supposedly present and not present edges. for( Edge edge : presentEdges ) { Predicate edgePred = EdgePredicateFactory.create( edge ); - assertNotNull( g.getEdge( edgePred ) ); + assertThat( g.getEdge( edgePred ), notNullValue() ); } for( Edge edge : notPresentEdges ) { Predicate edgePred = EdgePredicateFactory.create( edge ); - assertNull( g.getEdge( edgePred ) ); + assertThat( g.getEdge( edgePred ), nullValue() ); } } @@ -506,10 +518,10 @@ public void testNodeIterator() { for( Object node : presentNodes ) { - assertTrue( nodes.contains( node ) ); + assertThat( nodes, hasItem( node ) ); } for( Object node : notPresentNodes ) { - assertFalse( nodes.contains( node ) ); + assertThat( nodes, not( hasItem( node ) ) ); } Iterator< ? > nodeIter = g.nodes( null ).iterator(); @@ -524,19 +536,17 @@ // Do nothing } - assertEquals( count, nodes.size() ); + assertThat( nodes.size(), is( count ) ); } @Test public void testEdgeIterator() { for( Edge edge : presentEdges ) { - assertTrue( testEdges.contains( new SimpleObjectEdge( edge.getUserObject(), edge.getTail(), edge.getHead(), - edge.isDirected() ) ) ); + assertThat( testEdges, hasItem( createEdge( edge ) ) ); } for( Edge edge : notPresentEdges ) { - assertFalse( testEdges.contains( new SimpleObjectEdge( edge.getUserObject(), edge.getTail(), - edge.getHead(), edge.isDirected() ) ) ); + assertThat( testEdges, not( hasItem( createEdge( edge ) ) ) ); } Iterator< ? > edgeIter = g.edges( null ).iterator(); @@ -552,7 +562,7 @@ // Do nothing } - assertEquals( count, realEdges.size() ); + assertThat( realEdges.size(), is( count ) ); } @Test @@ -565,9 +575,9 @@ Predicate edgePred = EdgePredicateFactory.createEqualsNodes( tail, head, DIR_MASK ); Iterator< ? > edgeIter = g.edges( edgePred ).iterator(); if( edgeIter.hasNext() ) { - assertNotNull( g.getEdge( edgePred ) ); + assertThat( g.getEdge( edgePred ), notNullValue() ); } else { - assertNull( g.getEdge( edgePred ) ); + assertThat( g.getEdge( edgePred ), nullValue() ); } while( edgeIter.hasNext() ) { Edge edge = (Edge) edgeIter.next(); @@ -591,19 +601,19 @@ } } - assertEquals( totalCount + selfCount, 2 * realEdges.size() ); + assertThat( totalCount + selfCount, is( 2 * realEdges.size() ) ); // Check for supposedly present and not present edges. for( Edge edge : presentEdges ) { Predicate edgePred = EdgePredicateFactory.create( edge ); Iterator< ? > edgeIter = g.edges( edgePred ).iterator(); - assertTrue( edgeIter.hasNext() ); - assertNotNull( edgeIter.next() ); + assertThat( edgeIter.hasNext(), is( true ) ); + assertThat( edgeIter.next(), notNullValue() ); } for( Edge edge : notPresentEdges ) { Predicate edgePred = EdgePredicateFactory.create( edge ); Iterator< ? > edgeIter = g.edges( edgePred ).iterator(); - assertFalse( edgeIter.hasNext() ); + assertThat( edgeIter.hasNext(), is( false ) ); } } @@ -623,8 +633,8 @@ Object adjNode = t.next(); // Check that the adjacent node is in the graph. - assertTrue( g.containsNode( adjNode ) ); - assertTrue( nodes.contains( adjNode ) ); + assertThat( g.containsNode( adjNode ), is( true ) ); + assertThat( nodes, hasItem( adjNode ) ); Edge edge = t.getEdge(); if( isSelfEdge( edge ) ) { @@ -646,10 +656,10 @@ } // Check that each edge accessed by the traverser is unique. - assertEquals( count, edges.size() ); + assertThat( edges.size(), is( count ) ); } - assertEquals( totalCount + selfCount, 2 * realEdges.size() ); + assertThat( totalCount + selfCount, is( 2 * realEdges.size() ) ); validateNotPresentNodes( new Closure() { @@ -674,8 +684,8 @@ Object adjNode = t.next(); // Check that the adjacent node is in the graph. - assertTrue( g.containsNode( adjNode ) ); - assertTrue( nodes.contains( adjNode ) ); + assertThat( g.containsNode( adjNode ), is( true ) ); + assertThat( nodes, hasItem( adjNode ) ); Edge edge = t.getEdge(); edges.add( edge ); @@ -689,7 +699,7 @@ } // Check that each edge accessed by the traverser is unique. - assertEquals( count, edges.size() ); + assertThat( edges.size(), is( count ) ); } validateNotPresentNodes( new Closure() @@ -715,8 +725,8 @@ Object adjNode = t.next(); // Check that the adjacent node is in the graph. - assertTrue( g.containsNode( adjNode ) ); - assertTrue( nodes.contains( adjNode ) ); + assertThat( g.containsNode( adjNode ), is( true ) ); + assertThat( nodes, hasItem( adjNode ) ); Edge edge = t.getEdge(); edges.add( edge ); @@ -730,7 +740,7 @@ } // Check that each edge accessed by the traverser is unique. - assertEquals( count, edges.size() ); + assertThat( edges.size(), is( count ) ); } validateNotPresentNodes( new Closure() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2010-09-16 17:49:42
|
Revision: 898 http://plexus.svn.sourceforge.net/plexus/?rev=898&view=rev Author: rconner Date: 2010-09-16 17:49:36 +0000 (Thu, 16 Sep 2010) Log Message: ----------- I don't like the no-spaces generics convention Modified Paths: -------------- trunk/plexus-graph/src/main/config/checkstyle/checkstyle.xml Modified: trunk/plexus-graph/src/main/config/checkstyle/checkstyle.xml =================================================================== --- trunk/plexus-graph/src/main/config/checkstyle/checkstyle.xml 2010-09-16 17:00:19 UTC (rev 897) +++ trunk/plexus-graph/src/main/config/checkstyle/checkstyle.xml 2010-09-16 17:49:36 UTC (rev 898) @@ -259,7 +259,7 @@ <module name="EmptyForIteratorPad"> <property name="option" value="space"/> </module> - <module name="GenericWhitespace"/> +<!-- <module name="GenericWhitespace"/> --> <module name="MethodParamPad"/> <module name="NoWhitespaceAfter"> <!-- Omitting: ARRAY_INIT, TYPECAST --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2010-09-16 17:00:28
|
Revision: 897 http://plexus.svn.sourceforge.net/plexus/?rev=897&view=rev Author: rconner Date: 2010-09-16 17:00:19 +0000 (Thu, 16 Sep 2010) Log Message: ----------- migrate to matcher idiom for tests Modified Paths: -------------- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/DefaultGraphTest.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 16:38:05 UTC (rev 896) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/DefaultGraphTest.java 2010-09-16 17:00:19 UTC (rev 897) @@ -15,7 +15,9 @@ package com.phoenixst.plexus; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -59,12 +61,18 @@ setNotPresentEdges( setup.badEdges.toArray( EMPTY_EDGE_ARRAY ) ); } + private static < T > Set< T > toSet( final T ... elements ) + { + return new HashSet< T >( Arrays.asList( elements ) ); + } + @Test public void testDeserialization() throws IOException, ClassNotFoundException { // Make sure we're not being tested inappropriately. - assertEquals( DefaultGraph.class, getGraph().getClass() ); + assertThat( "Graph is not a DefaultGraph; this test has been improperly initialized.", + getGraph(), instanceOf( DefaultGraph.class ) ); // Tests serialize->deserialize, and then compares with the original. ByteArrayOutputStream bos = new ByteArrayOutputStream( 2048 ); @@ -78,14 +86,14 @@ Object copy = in.readObject(); in.close(); - assertEquals( DefaultGraph.class, copy.getClass() ); + assertThat( "Deserialized copy is not a DefaultGraph.", copy, instanceOf( DefaultGraph.class ) ); // 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 ); + assertThat( "Deserialized nodes not equal.", setup.goodNodes, is( toSet( getPresentNodes() ) ) ); + assertThat( "Deserialized edges not equal.", setup.goodEdges, is( toSet( getPresentEdges() ) ) ); + assertThat( "Deserialized absent edges not equal.", setup.badEdges, is( toSet( getNotPresentEdges() ) ) ); } private static class GraphSetup 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. |
From: <rc...@us...> - 2010-09-16 16:17:50
|
Revision: 895 http://plexus.svn.sourceforge.net/plexus/?rev=895&view=rev Author: rconner Date: 2010-09-16 16:17:44 +0000 (Thu, 16 Sep 2010) Log Message: ----------- Going back to excluding the local variable could be final rule. Modified Paths: -------------- trunk/plexus-graph/src/main/config/checkstyle/checkstyle.xml Modified: trunk/plexus-graph/src/main/config/checkstyle/checkstyle.xml =================================================================== --- trunk/plexus-graph/src/main/config/checkstyle/checkstyle.xml 2010-09-16 16:11:33 UTC (rev 894) +++ trunk/plexus-graph/src/main/config/checkstyle/checkstyle.xml 2010-09-16 16:17:44 UTC (rev 895) @@ -121,7 +121,7 @@ <module name="EqualsHashCode"/> <module name="ExplicitInitialization"/> <module name="FallThrough"/> - <module name="FinalLocalVariable"/> +<!-- <module name="FinalLocalVariable"/> --> <module name="HiddenField"> <property name="ignoreSetter" value="true"/> <property name="ignoreConstructorParameter" value="true"/> 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:11:39
|
Revision: 894 http://plexus.svn.sourceforge.net/plexus/?rev=894&view=rev Author: rconner Date: 2010-09-16 16:11:33 +0000 (Thu, 16 Sep 2010) Log Message: ----------- Going back to excluding the local variable could be final rule. Modified Paths: -------------- trunk/plexus-graph/src/main/config/pmd/ruleset.xml Modified: trunk/plexus-graph/src/main/config/pmd/ruleset.xml =================================================================== --- trunk/plexus-graph/src/main/config/pmd/ruleset.xml 2010-09-16 16:05:12 UTC (rev 893) +++ trunk/plexus-graph/src/main/config/pmd/ruleset.xml 2010-09-16 16:11:33 UTC (rev 894) @@ -146,6 +146,12 @@ <rule ref="rulesets/optimizations.xml"> <!-- + Excluding. This rule says that local variables should be final + if they're only assigned once. + --> + <exclude name="LocalVariableCouldBeFinal" /> + + <!-- Excluding. This hasn't been a problem in Java for a long time. --> 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 15:49:56
|
Revision: 892 http://plexus.svn.sourceforge.net/plexus/?rev=892&view=rev Author: rconner Date: 2010-09-16 15:49:47 +0000 (Thu, 16 Sep 2010) Log Message: ----------- forgot to change a variable name during the refactor, this works now Modified Paths: -------------- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PrismTest.java 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 15:48:07 UTC (rev 891) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PrismTest.java 2010-09-16 15:49:47 UTC (rev 892) @@ -54,7 +54,7 @@ return tailB + 1 == headB; } else if( tailB == headB ) { return (tailA + 1 == headA) - || (tailA == n - 1 && headA == 0); + || (tailA == m - 1 && headA == 0); } else { return false; } 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 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-15 22:40:45
|
Revision: 889 http://plexus.svn.sourceforge.net/plexus/?rev=889&view=rev Author: rconner Date: 2010-09-15 22:40:39 +0000 (Wed, 15 Sep 2010) Log Message: ----------- Import Graph.Edge, it just reads better. 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/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 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:37:56 UTC (rev 888) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteBipartiteGraphTest.java 2010-09-15 22:40:39 UTC (rev 889) @@ -19,7 +19,7 @@ import org.junit.Before; import com.phoenixst.plexus.AbstractGraphTest; -import com.phoenixst.plexus.Graph; +import com.phoenixst.plexus.Graph.Edge; /** @@ -37,7 +37,7 @@ { public boolean evaluate( Object object ) { - Graph.Edge edge = (Graph.Edge) object; + Edge edge = (Edge) object; if( !edge.isDirected() ) { return false; } 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:37:56 UTC (rev 888) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteGraphTest.java 2010-09-15 22:40:39 UTC (rev 889) @@ -19,7 +19,7 @@ import org.junit.Before; import com.phoenixst.plexus.AbstractGraphTest; -import com.phoenixst.plexus.Graph; +import com.phoenixst.plexus.Graph.Edge; /** @@ -37,7 +37,7 @@ { public boolean evaluate( Object object ) { - Graph.Edge edge = (Graph.Edge) object; + Edge edge = (Edge) object; if( !edge.isDirected() ) { return false; } 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:37:56 UTC (rev 888) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CompleteTreeTest.java 2010-09-15 22:40:39 UTC (rev 889) @@ -19,7 +19,7 @@ import org.junit.Before; import com.phoenixst.plexus.AbstractGraphTest; -import com.phoenixst.plexus.Graph; +import com.phoenixst.plexus.Graph.Edge; /** @@ -49,7 +49,7 @@ { public boolean evaluate( Object object ) { - Graph.Edge edge = (Graph.Edge) object; + Edge edge = (Edge) object; if( !edge.isDirected() ) { return false; } 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:37:56 UTC (rev 888) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/CycleTest.java 2010-09-15 22:40:39 UTC (rev 889) @@ -19,7 +19,7 @@ import org.junit.Before; import com.phoenixst.plexus.AbstractGraphTest; -import com.phoenixst.plexus.Graph; +import com.phoenixst.plexus.Graph.Edge; /** @@ -37,7 +37,7 @@ { public boolean evaluate( Object object ) { - Graph.Edge edge = (Graph.Edge) object; + Edge edge = (Edge) object; if( !edge.isDirected() ) { 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-15 22:37:56 UTC (rev 888) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PathTest.java 2010-09-15 22:40:39 UTC (rev 889) @@ -19,7 +19,7 @@ import org.junit.Before; import com.phoenixst.plexus.AbstractGraphTest; -import com.phoenixst.plexus.Graph; +import com.phoenixst.plexus.Graph.Edge; /** @@ -37,7 +37,7 @@ { public boolean evaluate( Object object ) { - Graph.Edge edge = (Graph.Edge) object; + Edge edge = (Edge) object; if( !edge.isDirected() ) { return false; } 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:37:56 UTC (rev 888) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PetersenGraphTest.java 2010-09-15 22:40:39 UTC (rev 889) @@ -19,7 +19,7 @@ import org.junit.Before; import com.phoenixst.plexus.AbstractGraphTest; -import com.phoenixst.plexus.Graph; +import com.phoenixst.plexus.Graph.Edge; /** @@ -50,7 +50,7 @@ public boolean evaluate( Object object ) { - Graph.Edge edge = (Graph.Edge) object; + Edge edge = (Edge) object; if( edge.isDirected() ) { return false; } 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:37:56 UTC (rev 888) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PlanarMeshTest.java 2010-09-15 22:40:39 UTC (rev 889) @@ -21,7 +21,7 @@ import org.junit.Before; import com.phoenixst.plexus.AbstractGraphTest; -import com.phoenixst.plexus.Graph; +import com.phoenixst.plexus.Graph.Edge; /** @@ -40,7 +40,7 @@ @SuppressWarnings( "unchecked" ) public boolean evaluate( Object object ) { - Graph.Edge edge = (Graph.Edge) object; + Edge edge = (Edge) object; if( !edge.isDirected() ) { return false; } 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:37:56 UTC (rev 888) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/PrismTest.java 2010-09-15 22:40:39 UTC (rev 889) @@ -21,7 +21,7 @@ import org.junit.Before; import com.phoenixst.plexus.AbstractGraphTest; -import com.phoenixst.plexus.Graph; +import com.phoenixst.plexus.Graph.Edge; /** @@ -40,7 +40,7 @@ @SuppressWarnings( "unchecked" ) public boolean evaluate( Object object ) { - Graph.Edge edge = (Graph.Edge) object; + Edge edge = (Edge) object; if( !edge.isDirected() ) { return false; } 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:37:56 UTC (rev 888) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/StarTest.java 2010-09-15 22:40:39 UTC (rev 889) @@ -19,7 +19,7 @@ import org.junit.Before; import com.phoenixst.plexus.AbstractGraphTest; -import com.phoenixst.plexus.Graph; +import com.phoenixst.plexus.Graph.Edge; /** @@ -37,7 +37,7 @@ { public boolean evaluate( Object object ) { - Graph.Edge edge = (Graph.Edge) object; + Edge edge = (Edge) object; if( !edge.isDirected() ) { return false; } 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:37:56 UTC (rev 888) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/ToroidalMeshTest.java 2010-09-15 22:40:39 UTC (rev 889) @@ -21,7 +21,7 @@ import org.junit.Before; import com.phoenixst.plexus.AbstractGraphTest; -import com.phoenixst.plexus.Graph; +import com.phoenixst.plexus.Graph.Edge; /** @@ -40,7 +40,7 @@ @SuppressWarnings( "unchecked" ) public boolean evaluate( Object object ) { - Graph.Edge edge = (Graph.Edge) object; + Edge edge = (Edge) object; if( !edge.isDirected() ) { return false; } 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:37:56 UTC (rev 888) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/examples/WheelTest.java 2010-09-15 22:40:39 UTC (rev 889) @@ -19,7 +19,7 @@ import org.junit.Before; import com.phoenixst.plexus.AbstractGraphTest; -import com.phoenixst.plexus.Graph; +import com.phoenixst.plexus.Graph.Edge; /** @@ -37,7 +37,7 @@ { public boolean evaluate( Object object ) { - Graph.Edge edge = (Graph.Edge) object; + Edge edge = (Edge) object; if( !edge.isDirected() ) { return false; } 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:38:02
|
Revision: 888 http://plexus.svn.sourceforge.net/plexus/?rev=888&view=rev Author: rconner Date: 2010-09-15 22:37:56 +0000 (Wed, 15 Sep 2010) Log Message: ----------- Clean up the code. Modified Paths: -------------- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/SimpleObjectEdge.java 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-15 22:22:57 UTC (rev 887) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/SimpleObjectEdge.java 2010-09-15 22:37:56 UTC (rev 888) @@ -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 @@ -19,18 +19,16 @@ /** - * An <code>Edge</code> which defines {@link #equals(Object) equals( - * Object )} differently for testing purposes. Because of how {@link - * #equals(Object) equals( Object )} is defined, instances of this - * class may only be used by multigraphs when the endpoints and - * contained user-defined object are sufficient to distinguish - * distinct edges. + * An <code>Edge</code> which defines {@link #equals(Object) equals( Object )} + * differently for testing purposes. Because of how {@link #equals(Object) + * equals( Object )} is defined, instances of this class may only be used by + * multigraphs when the endpoints and contained user-defined object are + * sufficient to distinguish distinct edges. * - * @author Ray A. Conner + * @author rconner */ public class SimpleObjectEdge extends DefaultObjectEdge { - private static final long serialVersionUID = 2L; @@ -38,13 +36,10 @@ // Constructor //////////////////////////////////////// - /** - * Creates a new <code>SimpleObjectEdge</code>. + * Creates a new <code>SimpleObjectEdge</code>. */ - public SimpleObjectEdge( Object object, - Object tail, Object head, - boolean directed ) + public SimpleObjectEdge( Object object, Object tail, Object head, boolean directed ) { super( object, tail, head, directed ); } @@ -54,41 +49,47 @@ // Other methods //////////////////////////////////////// + private boolean equals( Object tail, Object head ) + { + return GraphUtils.equals( getTail(), tail ) + && GraphUtils.equals( getHead(), head ); + } /** - * Two <code>SimpleObjectEdges</code> are equal if they have the - * same directedness, have equal endpoints, and contain the same - * user-defined object. + * Two <code>SimpleObjectEdges</code> are equal if they have the same + * directedness, have equal endpoints, and contain the same user-defined + * object. */ @Override public boolean equals( Object object ) { - if( !(object instanceof SimpleObjectEdge) ) { + if( !( object instanceof SimpleObjectEdge ) ) { return false; } SimpleObjectEdge edge = (SimpleObjectEdge) object; - if( isDirected() ) { - return edge.isDirected() - && GraphUtils.equals( getUserObject(), edge.getUserObject() ) - && GraphUtils.equals( getTail(), edge.getTail() ) - && GraphUtils.equals( getHead(), edge.getHead() ); + if( !isDirected() == edge.isDirected() ) { + return false; } - return !edge.isDirected() - && GraphUtils.equals( getUserObject(), edge.getUserObject() ) - && ( (GraphUtils.equals( getTail(), edge.getTail() ) && GraphUtils.equals( getHead(), edge.getHead() )) - || (GraphUtils.equals( getTail(), edge.getHead() ) && GraphUtils.equals( getHead(), edge.getTail() )) ); + if( !GraphUtils.equals( getUserObject(), edge.getUserObject() ) ) { + return false; + } + if( equals( edge.getTail(), edge.getHead() ) ) { + return true; + } + return !isDirected() + && equals( edge.getHead(), edge.getTail() ); } + private int hashCode( Object object ) + { + return object == null ? 0 : object.hashCode(); + } @Override public int hashCode() { - Object tail = getTail(); - Object head = getHead(); - Object object = getUserObject(); - return ((tail == null) ? 0 : tail.hashCode()) - ^ ((head == null) ? 0 : head.hashCode()) - ^ ((object == null) ? 0 : object.hashCode()); + return hashCode( getUserObject() ) + ^ hashCode( getTail() ) + ^ hashCode( getHead() ); } - } 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-15 22:00:24
|
Revision: 886 http://plexus.svn.sourceforge.net/plexus/?rev=886&view=rev Author: rconner Date: 2010-09-15 22:00:18 +0000 (Wed, 15 Sep 2010) Log Message: ----------- looks like you have to explicitly exclude something to override the default excludes Modified Paths: -------------- trunk/plexus-graph/pom.xml Modified: trunk/plexus-graph/pom.xml =================================================================== --- trunk/plexus-graph/pom.xml 2010-09-15 21:12:21 UTC (rev 885) +++ trunk/plexus-graph/pom.xml 2010-09-15 22:00:18 UTC (rev 886) @@ -80,8 +80,11 @@ <includes> <include>**/Test*.java</include> <include>**/*Test.java</include> - <include>**/*$Test*.java</include> + <include>**/*$Test*</include> </includes> + <excludes> + <exclude>Dummy.java</exclude> + </excludes> </configuration> </plugin> 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:12:28
|
Revision: 885 http://plexus.svn.sourceforge.net/plexus/?rev=885&view=rev Author: rconner Date: 2010-09-15 21:12:21 +0000 (Wed, 15 Sep 2010) Log Message: ----------- I was wrong, there's another way to do a pseudo-suite in JUnit4. Changed the surefire plugin to also run inner classes named Test* Modified Paths: -------------- trunk/plexus-graph/pom.xml Removed Paths: ------------- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/UtilSuite.java Modified: trunk/plexus-graph/pom.xml =================================================================== --- trunk/plexus-graph/pom.xml 2010-09-15 21:00:23 UTC (rev 884) +++ trunk/plexus-graph/pom.xml 2010-09-15 21:12:21 UTC (rev 885) @@ -74,6 +74,19 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.6</version> + <configuration> + <includes> + <include>**/Test*.java</include> + <include>**/*Test.java</include> + <include>**/*$Test*.java</include> + </includes> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3.1</version> <configuration> Deleted: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/UtilSuite.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/UtilSuite.java 2010-09-15 21:00:23 UTC (rev 884) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/util/UtilSuite.java 2010-09-15 21:12:21 UTC (rev 885) @@ -1,34 +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.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. -} 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 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 16:07:33
|
Revision: 882 http://plexus.svn.sourceforge.net/plexus/?rev=882&view=rev Author: rconner Date: 2010-09-15 16:07:22 +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/junit/ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/StaticGraphTest.java Deleted: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/StaticGraphTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/StaticGraphTest.java 2010-09-15 16:02:06 UTC (rev 881) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/StaticGraphTest.java 2010-09-15 16:07:22 UTC (rev 882) @@ -1,62 +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; - - -/** - * A {@link Graph} tester which uses a single static graph, mostly - * for ease of use when testing with beanshell. - * - * @author Ray A. Conner - */ -public class StaticGraphTest -{ - - private static Graph staticGraph = null; - - - private StaticGraphTest() - { - super(); - } - - - public static Graph getGraph() - { - return staticGraph; - } - - - public static void setGraph( Graph graph ) - { - staticGraph = graph; - } - - - public static Test suite() - { - String suiteName; - if( staticGraph instanceof DefaultGraph ) { - suiteName = ""; - } else { - suiteName = staticGraph.toString(); - } - return DefaultGraphTest.suite( staticGraph, suiteName ); - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2010-09-15 16:02:17
|
Revision: 881 http://plexus.svn.sourceforge.net/plexus/?rev=881&view=rev Author: rconner Date: 2010-09-15 16:02:06 +0000 (Wed, 15 Sep 2010) Log Message: ----------- Upgrading to junit 4, still need to actually migrate the test code. Modified Paths: -------------- trunk/plexus-graph/pom.xml trunk/plexus-graph/src/main/config/pmd/ruleset.xml Modified: trunk/plexus-graph/pom.xml =================================================================== --- trunk/plexus-graph/pom.xml 2010-09-14 16:59:01 UTC (rev 880) +++ trunk/plexus-graph/pom.xml 2010-09-15 16:02:06 UTC (rev 881) @@ -49,7 +49,7 @@ <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>3.8.2</version> + <version>4.8.1</version> <scope>test</scope> </dependency> Modified: trunk/plexus-graph/src/main/config/pmd/ruleset.xml =================================================================== --- trunk/plexus-graph/src/main/config/pmd/ruleset.xml 2010-09-14 16:59:01 UTC (rev 880) +++ trunk/plexus-graph/src/main/config/pmd/ruleset.xml 2010-09-15 16:02:06 UTC (rev 881) @@ -23,17 +23,20 @@ <rule ref="rulesets/finalizers.xml" /> <rule ref="rulesets/imports.xml" /> <rule ref="rulesets/j2ee.xml" /> + <rule ref="rulesets/junit.xml" /> <rule ref="rulesets/logging-jakarta-commons.xml" /> <rule ref="rulesets/logging-java.xml" /> <rule ref="rulesets/migrating_to_13.xml" /> <rule ref="rulesets/migrating_to_14.xml" /> <rule ref="rulesets/migrating_to_15.xml" /> + <rule ref="rulesets/migrating_to_junit4.xml" /> <rule ref="rulesets/strictexception.xml" /> <rule ref="rulesets/strings.xml" /> <rule ref="rulesets/sunsecure.xml" /> <rule ref="rulesets/typeresolution.xml" /> <rule ref="rulesets/unusedcode.xml" /> + <!-- Exclude some rules that I have serious problems with, some because I want to customize some properties (later in this @@ -125,16 +128,6 @@ </rule> - <rule ref="rulesets/junit.xml" > - <!-- FIXME: temporary --> - <exclude name="JUnitAssertionsShouldIncludeMessage" /> - </rule> - - <!-- FIXME: temporary - <rule ref="rulesets/migrating_to_junit4.xml" /> - --> - - <rule ref="rulesets/naming.xml" > <!-- FIXME: temporary, maybe --> <exclude name="ShortVariable" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |