commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1240515 - in /commons/sandbox/graph/trunk/src: changes/changes.xml test/java/org/apache/commons/graph/flow/FordFulkersonTestCase.java
Date Sat, 04 Feb 2012 15:04:29 GMT
Author: simonetripodi
Date: Sat Feb  4 15:04:29 2012
New Revision: 1240515

URL: http://svn.apache.org/viewvc?rev=1240515&view=rev
Log:
[SANDBOX-384] Add test for Flow Algorithms - patch provided by Marco Speranza

Modified:
    commons/sandbox/graph/trunk/src/changes/changes.xml
    commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/FordFulkersonTestCase.java

Modified: commons/sandbox/graph/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/changes/changes.xml?rev=1240515&r1=1240514&r2=1240515&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/changes/changes.xml (original)
+++ commons/sandbox/graph/trunk/src/changes/changes.xml Sat Feb  4 15:04:29 2012
@@ -23,6 +23,9 @@
   </properties>
   <body>
   <release version="0.1" date="201?-??-??" description="First release.">
+    <action dev="simonetripodi" type="fix" issue="SANDBOX-384" due-to="Marco Speranza">
+      Add test for Flow Algorithms
+    </action>
     <action dev="simonetripodi" type="fix" issue="SANDBOX-383" due-to="Marco Speranza">
       Add test for Connectivity
     </action>

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=1240515&r1=1240514&r2=1240515&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
Sat Feb  4 15:04:29 2012
@@ -23,6 +23,9 @@ import static org.apache.commons.graph.C
 import static org.apache.commons.graph.CommonsGraph.newDirectedMutableWeightedGraph;
 import static org.junit.Assert.assertEquals;
 
+import org.apache.commons.graph.DirectedGraph;
+import org.apache.commons.graph.Vertex;
+import org.apache.commons.graph.WeightedEdge;
 import org.apache.commons.graph.builder.AbstractGraphConnection;
 import org.apache.commons.graph.model.BaseLabeledVertex;
 import org.apache.commons.graph.model.BaseLabeledWeightedEdge;
@@ -37,6 +40,111 @@ import org.junit.Test;
  */
 public final class FordFulkersonTestCase
 {
+    @Test(expected=NullPointerException.class)
+    public void testNullGraph()
+    {
+        final BaseLabeledVertex a = new BaseLabeledVertex( "A" );
+        final BaseLabeledVertex d = new BaseLabeledVertex( "D" );
+
+        findMaxFlow( (DirectedGraph<Vertex, WeightedEdge<Integer>>) null ).from(
a ).to( d ).applyingFordFulkerson( new IntegerWeight() );
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void testNullGraphAndVertices()
+    {
+        findMaxFlow( (DirectedGraph<Vertex, WeightedEdge<Integer>>) null ).from(
null ).to( null ).applyingFordFulkerson( new IntegerWeight() );
+    }
+
+    @Test
+    public void testNotConnected()
+    {
+        final BaseLabeledVertex a = new BaseLabeledVertex( "A" );
+        final BaseLabeledVertex d = new BaseLabeledVertex( "D" );
+
+        DirectedMutableWeightedGraph<BaseLabeledVertex, BaseLabeledWeightedEdge<Integer>,
Integer> graph =
+        newDirectedMutableWeightedGraph( new AbstractGraphConnection<BaseLabeledVertex,
BaseLabeledWeightedEdge<Integer>>()
+        {
+
+            @Override
+            public void connect()
+            {
+                addVertex( a );
+                addVertex( new BaseLabeledVertex( "B" ) );
+                addVertex( new BaseLabeledVertex( "C" ) );
+                addVertex( d );
+
+            }
+
+        } );
+
+        // expected max flow
+        final Integer expected = 0;
+
+        // actual max flow
+        Integer actual = findMaxFlow( graph ).from( a ).to( d ).applyingFordFulkerson( new
IntegerWeight() );
+
+        assertEquals( actual, expected );
+    }
+
+    @Test
+    public void testNotConnected_2()
+    {
+        final BaseLabeledVertex a = new BaseLabeledVertex( "A" );
+        final BaseLabeledVertex d = new BaseLabeledVertex( "D" );
+
+        DirectedMutableWeightedGraph<BaseLabeledVertex, BaseLabeledWeightedEdge<Integer>,
Integer> graph =
+        newDirectedMutableWeightedGraph( new AbstractGraphConnection<BaseLabeledVertex,
BaseLabeledWeightedEdge<Integer>>()
+        {
+
+            @Override
+            public void connect()
+            {
+                addVertex( a );
+                BaseLabeledVertex b = addVertex( new BaseLabeledVertex( "B" ) );
+                addVertex( new BaseLabeledVertex( "C" ) );
+                addVertex( d );
+                addEdge( new BaseLabeledWeightedEdge<Integer>( "A -> B", 1000 )
).from( a ).to( b );
+
+            }
+
+        } );
+
+        // expected max flow
+        final Integer expected = 0;
+
+        // actual max flow
+        Integer actual = findMaxFlow( graph ).from( a ).to( d ).applyingFordFulkerson( new
IntegerWeight() );
+
+        assertEquals( actual, expected );
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void testNullVertices()
+    {
+        DirectedMutableWeightedGraph<BaseLabeledVertex, BaseLabeledWeightedEdge<Integer>,
Integer> 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 );
+            }
+
+        } );
+
+        // actual max flow
+        findMaxFlow( graph ).from( null ).to( null ).applyingFordFulkerson( new IntegerWeight()
);
+    }
 
     @Test
     public void findMaxFlowAndVerify()



Mime
View raw message