Author: marcosperanza
Date: Wed Feb 15 17:57:19 2012
New Revision: 1244609
URL: http://svn.apache.org/viewvc?rev=1244609&view=rev
Log:
deleted unneeded fail invokation and tested that NPE exception is only thrown
by the method under test.
Modified:
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/EdmondsKarpTestCase.java
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/FordFulkersonTestCase.java
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/AStarTestCase.java
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/BellmannFordTestCase.java
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/DijkstraTestCase.java
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/FloydWarshallTestCase.java
Modified:
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/EdmondsKarpTestCase.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/EdmondsKarpTestCase.java?rev=1244609&r1=1244608&r2=1244609&view=diff
==============================================================================
---
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/EdmondsKarpTestCase.java
(original)
+++
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/EdmondsKarpTestCase.java
Wed Feb 15 17:57:19 2012
@@ -22,7 +22,6 @@ package org.apache.commons.graph.flow;
import static org.apache.commons.graph.CommonsGraph.findMaxFlow;
import static
org.apache.commons.graph.CommonsGraph.newDirectedMutableWeightedGraph;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import org.apache.commons.graph.Vertex;
import org.apache.commons.graph.WeightedEdge;
@@ -40,7 +39,7 @@ import org.junit.Test;
*/
public class EdmondsKarpTestCase
{
-
+
@Test( expected = NullPointerException.class )
public void testNullGraph()
{
@@ -49,7 +48,6 @@ public class EdmondsKarpTestCase
// actual max flow
findMaxFlow( (DirectedMutableWeightedGraph<Vertex,
WeightedEdge<Integer>, Integer>) null ).from( a ).to( g ).applyingEdmondsKarp(
new IntegerWeight() );
- fail( "Null Pointer Exception not caught" );
}
@Test( expected = NullPointerException.class )
@@ -71,7 +69,6 @@ public class EdmondsKarpTestCase
// actual max flow
findMaxFlow( graph ).from( a ).to( g ).applyingEdmondsKarp( new
IntegerWeight() );
- fail( "Null Pointer Exception not caught" );
}
@Test
@@ -94,7 +91,7 @@ public class EdmondsKarpTestCase
addVertex( new BaseLabeledVertex( "E" ) );
addVertex( new BaseLabeledVertex( "F" ) );
addVertex( g );
-
+
addEdge( new BaseLabeledWeightedEdge<Integer>( "A -> B", 3
) ).from( a ).to( b );
addEdge( new BaseLabeledWeightedEdge<Integer>( "B -> C", 4
) ).from( b ).to( c );
}
Modified:
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/FordFulkersonTestCase.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/FordFulkersonTestCase.java?rev=1244609&r1=1244608&r2=1244609&view=diff
==============================================================================
---
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/FordFulkersonTestCase.java
(original)
+++
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/FordFulkersonTestCase.java
Wed Feb 15 17:57:19 2012
@@ -22,6 +22,8 @@ package org.apache.commons.graph.flow;
import static org.apache.commons.graph.CommonsGraph.findMaxFlow;
import static
org.apache.commons.graph.CommonsGraph.newDirectedMutableWeightedGraph;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import org.apache.commons.graph.Vertex;
import org.apache.commons.graph.WeightedEdge;
@@ -121,26 +123,34 @@ public final class FordFulkersonTestCase
@Test(expected=NullPointerException.class)
public void testNullVertices()
{
- DirectedMutableWeightedGraph<BaseLabeledVertex,
BaseLabeledWeightedEdge<Integer>, Integer> graph =
- newDirectedMutableWeightedGraph( new
AbstractGraphConnection<BaseLabeledVertex, BaseLabeledWeightedEdge<Integer>>()
+ DirectedMutableWeightedGraph<BaseLabeledVertex,
BaseLabeledWeightedEdge<Integer>, Integer> graph = null;
+ try
{
-
- @Override
- public void connect()
- {
- BaseLabeledVertex a = addVertex( new BaseLabeledVertex( "A" )
);
- BaseLabeledVertex b = addVertex( new BaseLabeledVertex( "B" )
);
- BaseLabeledVertex c = addVertex( new BaseLabeledVertex( "C" )
);
- BaseLabeledVertex d = addVertex( new BaseLabeledVertex( "D" )
);
-
- addEdge( new BaseLabeledWeightedEdge<Integer>( "A -> B", 1000
) ).from( a ).to( b );
- addEdge( new BaseLabeledWeightedEdge<Integer>( "A -> C", 1000
) ).from( a ).to( c );
- addEdge( new BaseLabeledWeightedEdge<Integer>( "B -> C", 1 )
).from( b ).to( c );
- addEdge( new BaseLabeledWeightedEdge<Integer>( "B -> D", 1000
) ).from( b ).to( d );
- addEdge( new BaseLabeledWeightedEdge<Integer>( "C -> D", 1000
) ).from( c ).to( d );
- }
-
- } );
+ graph =
+ newDirectedMutableWeightedGraph( new
AbstractGraphConnection<BaseLabeledVertex, BaseLabeledWeightedEdge<Integer>>()
+ {
+
+ @Override
+ public void connect()
+ {
+ BaseLabeledVertex a = addVertex( new
BaseLabeledVertex( "A" ) );
+ BaseLabeledVertex b = addVertex( new
BaseLabeledVertex( "B" ) );
+ BaseLabeledVertex c = addVertex( new
BaseLabeledVertex( "C" ) );
+ BaseLabeledVertex d = addVertex( new
BaseLabeledVertex( "D" ) );
+
+ addEdge( new BaseLabeledWeightedEdge<Integer>( "A ->
B", 1000 ) ).from( a ).to( b );
+ addEdge( new BaseLabeledWeightedEdge<Integer>( "A ->
C", 1000 ) ).from( a ).to( c );
+ addEdge( new BaseLabeledWeightedEdge<Integer>( "B ->
C", 1 ) ).from( b ).to( c );
+ addEdge( new BaseLabeledWeightedEdge<Integer>( "B ->
D", 1000 ) ).from( b ).to( d );
+ addEdge( new BaseLabeledWeightedEdge<Integer>( "C ->
D", 1000 ) ).from( c ).to( d );
+ }
+
+ } );
+ }
+ catch ( NullPointerException e )
+ {
+ fail( e.getMessage() );
+ }
// actual max flow
findMaxFlow( graph ).from( null ).to( null ).applyingFordFulkerson(
new IntegerWeight() );
@@ -153,25 +163,25 @@ public final class FordFulkersonTestCase
final BaseLabeledVertex d = new BaseLabeledVertex( "D" );
DirectedMutableWeightedGraph<BaseLabeledVertex,
BaseLabeledWeightedEdge<Integer>, Integer> graph =
- newDirectedMutableWeightedGraph( new
AbstractGraphConnection<BaseLabeledVertex, BaseLabeledWeightedEdge<Integer>>()
- {
-
- @Override
- public void connect()
+ newDirectedMutableWeightedGraph( new
AbstractGraphConnection<BaseLabeledVertex, BaseLabeledWeightedEdge<Integer>>()
{
- addVertex( a );
- BaseLabeledVertex b = addVertex( new BaseLabeledVertex( "B" )
);
- BaseLabeledVertex c = addVertex( new BaseLabeledVertex( "C" )
);
- addVertex( d );
- addEdge( new BaseLabeledWeightedEdge<Integer>( "A -> B", 1000
) ).from( a ).to( b );
- addEdge( new BaseLabeledWeightedEdge<Integer>( "A -> C", 1000
) ).from( a ).to( c );
- addEdge( new BaseLabeledWeightedEdge<Integer>( "B -> C", 1 )
).from( b ).to( c );
- addEdge( new BaseLabeledWeightedEdge<Integer>( "B -> D", 1000
) ).from( b ).to( d );
- addEdge( new BaseLabeledWeightedEdge<Integer>( "C -> D", 1000
) ).from( c ).to( d );
- }
+ @Override
+ public void connect()
+ {
+ addVertex( a );
+ BaseLabeledVertex b = addVertex( new BaseLabeledVertex(
"B" ) );
+ BaseLabeledVertex c = addVertex( new BaseLabeledVertex(
"C" ) );
+ addVertex( d );
+
+ addEdge( new BaseLabeledWeightedEdge<Integer>( "A -> B",
1000 ) ).from( a ).to( b );
+ addEdge( new BaseLabeledWeightedEdge<Integer>( "A -> C",
1000 ) ).from( a ).to( c );
+ addEdge( new BaseLabeledWeightedEdge<Integer>( "B -> C", 1
) ).from( b ).to( c );
+ addEdge( new BaseLabeledWeightedEdge<Integer>( "B -> D",
1000 ) ).from( b ).to( d );
+ addEdge( new BaseLabeledWeightedEdge<Integer>( "C -> D",
1000 ) ).from( c ).to( d );
+ }
- } );
+ } );
// expected max flow
final Integer expected = 2000;
Modified:
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/AStarTestCase.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/AStarTestCase.java?rev=1244609&r1=1244608&r2=1244609&view=diff
==============================================================================
---
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/AStarTestCase.java
(original)
+++
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/AStarTestCase.java
Wed Feb 15 17:57:19 2012
@@ -41,10 +41,9 @@ public final class AStarTestCase
{
@Test( expected = NullPointerException.class )
- public void testNullGraah()
+ public void testNullGraph()
{
findShortestPath( (WeightedGraph<Vertex, WeightedEdge<Double>,
Double>) null ).from( null ).to( null ).applyingAStar( new DoubleWeight()
).withHeuristic( null );
- fail( "Null Pointer Exception not caught" );
}
@Test( expected = NullPointerException.class )
@@ -54,7 +53,6 @@ public final class AStarTestCase
new UndirectedMutableWeightedGraph<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double>();
findShortestPath( graph ).from( null ).to( null ).applyingAStar( new
DoubleWeight() ).withHeuristic( null );
- fail( "Null Pointer Exception not caught" );
}
@Test( expected = NullPointerException.class )
@@ -64,7 +62,6 @@ public final class AStarTestCase
new UndirectedMutableWeightedGraph<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double>();
findShortestPath( graph ).from( new BaseLabeledVertex( "a" ) ).to( new
BaseLabeledVertex( "b" ) ).applyingAStar( new DoubleWeight() ).withHeuristic(
null );
- fail( "Null Pointer Exception not caught" );
}
@Test( expected = NullPointerException.class )
@@ -75,23 +72,30 @@ public final class AStarTestCase
final BaseLabeledVertex a = new BaseLabeledVertex( "a" );
final BaseLabeledVertex b = new BaseLabeledVertex( "b" );
- graph.addVertex( a );
- graph.addVertex( b );
-
final Map<BaseLabeledVertex, Double> heuristics = new
HashMap<BaseLabeledVertex, Double>();
+ Heuristic<BaseLabeledVertex, Double> heuristic = null;
- Heuristic<BaseLabeledVertex, Double> heuristic = new
Heuristic<BaseLabeledVertex, Double>()
+ try
{
+ graph.addVertex( a );
+ graph.addVertex( b );
- public Double applyHeuristic( BaseLabeledVertex current,
BaseLabeledVertex goal )
+ heuristic = new Heuristic<BaseLabeledVertex, Double>()
{
- return heuristics.get( current );
- }
- };
+ public Double applyHeuristic( BaseLabeledVertex current,
BaseLabeledVertex goal )
+ {
+ return heuristics.get( current );
+ }
+
+ };
+ }
+ catch ( NullPointerException e )
+ {
+ fail( e.getMessage() );
+ }
findShortestPath( graph ).from( a ).to( b ).applyingAStar( null
).withHeuristic( heuristic );
- fail( "Null Pointer Exception not caught" );
}
@Test( expected = PathNotFoundException.class )
@@ -118,9 +122,8 @@ public final class AStarTestCase
};
findShortestPath( graph ).from( a ).to( b ).applyingAStar( new
DoubleWeight() ).withHeuristic( heuristic );
- fail( "Path not found Exception not cathed" );
}
-
+
/**
* Test Graph and Dijkstra's solution can be seen on
* <a href="http://en.wikipedia.org/wiki/A*_search_algorithm">Wikipedia</a>
@@ -182,7 +185,8 @@ public final class AStarTestCase
// expected path
InMemoryWeightedPath<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double> expected =
- new InMemoryWeightedPath<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double>( start, goal, new DoubleWeight() );
+ new InMemoryWeightedPath<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double>( start, goal,
+
new DoubleWeight() );
expected.addConnectionInTail( start, new
BaseLabeledWeightedEdge<Double>( "start <-> a", 1.5D ), a );
expected.addConnectionInTail( a, new BaseLabeledWeightedEdge<Double>(
"a <-> b", 2D ), b );
Modified:
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/BellmannFordTestCase.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/BellmannFordTestCase.java?rev=1244609&r1=1244608&r2=1244609&view=diff
==============================================================================
---
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/BellmannFordTestCase.java
(original)
+++
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/BellmannFordTestCase.java
Wed Feb 15 17:57:19 2012
@@ -39,11 +39,10 @@ public final class BellmannFordTestCase
{
@Test( expected = NullPointerException.class )
- public void testNullGraah()
+ public void testNullGraph()
{
// the actual weighted path
findShortestPath( (WeightedGraph<Vertex, WeightedEdge<Double>,
Double>) null ).from( null ).applyingBelmannFord( new DoubleWeight() );
- fail( "Null Pointer Exception not caught" );
}
@Test( expected = NullPointerException.class )
@@ -52,51 +51,60 @@ public final class BellmannFordTestCase
UndirectedMutableWeightedGraph<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double> graph =
new UndirectedMutableWeightedGraph<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double>();
- // the actual weighted path
AllVertexPairsShortestPath<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double> allVertexPairsShortestPath =
findShortestPath( graph ).from( null ).applyingBelmannFord( new
DoubleWeight() );
-
- allVertexPairsShortestPath.findShortestPath( null, null );
- fail( "Null Pointer Exception not caught" );
}
@Test( expected = NullPointerException.class )
public void testNullMonoid()
{
- UndirectedMutableWeightedGraph<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double> graph =
- new UndirectedMutableWeightedGraph<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double>();
-
- final BaseLabeledVertex a = new BaseLabeledVertex( "a" );
- final BaseLabeledVertex b = new BaseLabeledVertex( "b" );
- graph.addVertex( a );
- graph.addVertex( b );
+ UndirectedMutableWeightedGraph<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double> graph = null;
+ BaseLabeledVertex a = null;
+ try
+ {
+ graph = new UndirectedMutableWeightedGraph<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double>();
+
+ a = new BaseLabeledVertex( "a" );
+ final BaseLabeledVertex b = new BaseLabeledVertex( "b" );
+ graph.addVertex( a );
+ graph.addVertex( b );
+ }
+ catch ( NullPointerException e )
+ {
+ fail( e.getMessage() );
+ }
// the actual weighted path
- AllVertexPairsShortestPath<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double> allVertexPairsShortestPath =
- findShortestPath( graph ).from( a ).applyingBelmannFord( null );
-
- allVertexPairsShortestPath.findShortestPath( a, b );
- fail( "Null Pointer Exception not caught" );
+ findShortestPath( graph ).from( a ).applyingBelmannFord( null );
}
@Test( expected = PathNotFoundException.class )
public void testNotConnectGraph()
{
- UndirectedMutableWeightedGraph<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double> graph =
- new UndirectedMutableWeightedGraph<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double>();
-
- final BaseLabeledVertex a = new BaseLabeledVertex( "a" );
- final BaseLabeledVertex b = new BaseLabeledVertex( "b" );
- graph.addVertex( a );
- graph.addVertex( b );
-
+ BaseLabeledVertex a = null;
+ BaseLabeledVertex b = null;
// the actual weighted path
AllVertexPairsShortestPath<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double> allVertexPairsShortestPath =
- findShortestPath( graph ).from( a ).applyingBelmannFord( new
DoubleWeight() );
-
+ null;
+ try
+ {
+ UndirectedMutableWeightedGraph<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double> graph =
+ new UndirectedMutableWeightedGraph<BaseLabeledVertex,
BaseLabeledWeightedEdge<Double>, Double>();
+
+ a = new BaseLabeledVertex( "a" );
+ b = new BaseLabeledVertex( "b" );
+ graph.addVertex( a );
+ graph.addVertex( b );
+
+ allVertexPairsShortestPath = findShortestPath( graph ).from( a
).applyingBelmannFord( new DoubleWeight() );
+ }
+ catch ( PathNotFoundException e )
+ {
+ fail( e.getMessage() );
+ }
allVertexPairsShortestPath.findShortestPath( a, b );
}
-
+
/**
* Test Graph and Dijkstra's solution can be seen on
* <a
href="http://compprog.wordpress.com/2007/11/29/one-source-shortest-path-the-bellman-ford-algorithm/">Wikipedia</a>
Modified:
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/DijkstraTestCase.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/DijkstraTestCase.java?rev=1244609&r1=1244608&r2=1244609&view=diff
==============================================================================
---
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/DijkstraTestCase.java
(original)
+++
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/DijkstraTestCase.java
Wed Feb 15 17:57:19 2012
@@ -39,11 +39,10 @@ public final class DijkstraTestCase
{
@Test( expected = NullPointerException.class )
- public void testNullGraah()
+ public void testNullGraph()
{
// the actual weighted path
findShortestPath( (WeightedGraph<Vertex, WeightedEdge<Double>,
Double>) null ).from( null ).to( null ).applyingDijkstra( new DoubleWeight() );
- fail( "Null Pointer Exception not caught" );
}
@Test( expected = NullPointerException.class )
@@ -54,8 +53,6 @@ public final class DijkstraTestCase
// the actual weighted path
findShortestPath( graph ).from( null ).to( null ).applyingDijkstra(
new DoubleWeight() );
-
- fail( "Null Pointer Exception not caught" );
}
@Test( expected = NullPointerException.class )
@@ -71,10 +68,8 @@ public final class DijkstraTestCase
// the actual weighted path
findShortestPath( graph ).from( a ).to( b ).applyingDijkstra( null );
-
- fail( "Null Pointer Exception not caught" );
}
-
+
@Test( expected = PathNotFoundException.class )
public void testNotConnectGraph()
{
@@ -89,7 +84,7 @@ public final class DijkstraTestCase
// the actual weighted path
findShortestPath( graph ).from( a ).to( b ).applyingDijkstra( new
DoubleWeight() );
}
-
+
/**
* Test Graph and Dijkstra's solution can be seen on
* <a href="http://en.wikipedia.org/wiki/Dijkstra's_algorithm>Wikipedia</a>
Modified:
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/FloydWarshallTestCase.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/FloydWarshallTestCase.java?rev=1244609&r1=1244608&r2=1244609&view=diff
==============================================================================
---
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/FloydWarshallTestCase.java
(original)
+++
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/FloydWarshallTestCase.java
Wed Feb 15 17:57:19 2012
@@ -44,11 +44,10 @@ public class FloydWarshallTestCase
{
@Test( expected = NullPointerException.class )
- public void testNullGraah()
+ public void testNullGraph()
{
// the actual weighted path
findShortestPath( (WeightedGraph<Vertex, WeightedEdge<Double>,
Double>) null ).from( null ).to( null ).applyingDijkstra( new DoubleWeight() );
- fail( "Null Pointer Exception not caught" );
}
@Test( expected = PathNotFoundException.class )
@@ -67,9 +66,8 @@ public class FloydWarshallTestCase
findShortestPath( graph ).applyingFloydWarshall( new
DoubleWeight() );
p.findShortestPath( a, b );
- fail( "PathNotFoundException not caught" );
}
-
+
@Test
public void undirectedShortestPath()
{