Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AC70D95FE for ; Thu, 1 Mar 2012 22:09:06 +0000 (UTC) Received: (qmail 79948 invoked by uid 500); 1 Mar 2012 22:09:06 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 79828 invoked by uid 500); 1 Mar 2012 22:09:06 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 79817 invoked by uid 99); 1 Mar 2012 22:09:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Mar 2012 22:09:06 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of simone.tripodi@gmail.com designates 209.85.216.179 as permitted sender) Received: from [209.85.216.179] (HELO mail-qy0-f179.google.com) (209.85.216.179) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Mar 2012 22:09:01 +0000 Received: by qcha6 with SMTP id a6so402881qch.38 for ; Thu, 01 Mar 2012 14:08:40 -0800 (PST) Received-SPF: pass (google.com: domain of simone.tripodi@gmail.com designates 10.224.187.129 as permitted sender) client-ip=10.224.187.129; Authentication-Results: mr.google.com; spf=pass (google.com: domain of simone.tripodi@gmail.com designates 10.224.187.129 as permitted sender) smtp.mail=simone.tripodi@gmail.com; dkim=pass header.i=simone.tripodi@gmail.com Received: from mr.google.com ([10.224.187.129]) by 10.224.187.129 with SMTP id cw1mr2038449qab.4.1330639720313 (num_hops = 1); Thu, 01 Mar 2012 14:08:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; bh=WLRiG+XYQFduai4dFNPPgtgfiwMNz5KbtWcMPt+mKYY=; b=zxom4VahBngDbBG+Mx+/RMIZCXoS/iU4YPKAlMivRxYbQvbGtL8K2rjTiH1CcEcvKv JlscMQIFVEwQYSJEGZDX3qI+MfuTnb1ZtLja68VosVBgUoilKirZ5t3A2XT4bn3HnaKc 6W3cCDAbL1PDo7b0fETARWe02dOlgGJG862IhwnYsifftT+O2WDtplUGWOZfjA1UJ1Lp gVF9Io91zNfVWTLZR0v9xNJv2l+Dgor6fPEilWfnmj6Iwlltl5FKY/pbBOyXIGzY6AF4 O8/iV/OpHc5ffSN3d4iyVJSQ5l9eyQ7D4/JLuLokEr5VlyVTOiRBxOByj3DSp5yFTl6E JDNg== MIME-Version: 1.0 Received: by 10.224.187.129 with SMTP id cw1mr1746140qab.4.1330639720172; Thu, 01 Mar 2012 14:08:40 -0800 (PST) Sender: simone.tripodi@gmail.com Received: by 10.224.195.73 with HTTP; Thu, 1 Mar 2012 14:08:40 -0800 (PST) In-Reply-To: <20120301215141.2E2C0238889B@eris.apache.org> References: <20120301215141.2E2C0238889B@eris.apache.org> Date: Thu, 1 Mar 2012 23:08:40 +0100 X-Google-Sender-Auth: eZ_JD4cfszf1rGkfCChCalk_Oqs Message-ID: Subject: Re: svn commit: r1295924 - in /commons/sandbox/graph/trunk/src: changes/changes.xml main/java/org/apache/commons/graph/scc/DefaultSccAlgorithmSelector.java test/java/org/apache/commons/graph/scc/KosarajuSharirTestCase.java From: Simone Tripodi To: dev@commons.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Ciao Marco, + DirectedMutableWeightedGraph, Integer> graph =3D + newDirectedMutableWeightedGraph( new AbstractGraphConnection>() + { + @Override + public void connect() + { + } + + } ); it would be more readable if you just create the graph instance, in these cases empty configuration is quiet useless ;) best, -Simo http://people.apache.org/~simonetripodi/ http://simonetripodi.livejournal.com/ http://twitter.com/simonetripodi http://www.99soft.org/ On Thu, Mar 1, 2012 at 10:51 PM, wrote: > Author: marcosperanza > Date: Thu Mar =C2=A01 21:51:40 2012 > New Revision: 1295924 > > URL: http://svn.apache.org/viewvc?rev=3D1295924&view=3Drev > Log: > [SANDBOX-392] Add test for Kosaraju Sharir Algorithm > > Modified: > =C2=A0 =C2=A0commons/sandbox/graph/trunk/src/changes/changes.xml > =C2=A0 =C2=A0commons/sandbox/graph/trunk/src/main/java/org/apache/commons= /graph/scc/DefaultSccAlgorithmSelector.java > =C2=A0 =C2=A0commons/sandbox/graph/trunk/src/test/java/org/apache/commons= /graph/scc/KosarajuSharirTestCase.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=3D1295924&r1=3D1295923&r2=3D1295924&view=3Ddiff > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- commons/sandbox/graph/trunk/src/changes/changes.xml (original) > +++ commons/sandbox/graph/trunk/src/changes/changes.xml Thu Mar =C2=A01 2= 1:51:40 2012 > @@ -23,6 +23,9 @@ > =C2=A0 > =C2=A0 > =C2=A0 > + =C2=A0 =C2=A0 > + =C2=A0 =C2=A0 =C2=A0Add test for Kosaraju Sharir Algorithm > + =C2=A0 =C2=A0 > =C2=A0 =C2=A0 > =C2=A0 =C2=A0 =C2=A0 Provide a Kosaraju-Sharir's algorithm implementation > =C2=A0 =C2=A0 > > Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/gr= aph/scc/DefaultSccAlgorithmSelector.java > URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/ja= va/org/apache/commons/graph/scc/DefaultSccAlgorithmSelector.java?rev=3D1295= 924&r1=3D1295923&r2=3D1295924&view=3Ddiff > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/sc= c/DefaultSccAlgorithmSelector.java (original) > +++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/sc= c/DefaultSccAlgorithmSelector.java Thu Mar =C2=A01 21:51:40 2012 > @@ -21,6 +21,8 @@ package org.apache.commons.graph.scc; > > =C2=A0import static java.lang.Math.min; > =C2=A0import static org.apache.commons.graph.CommonsGraph.visit; > +import static org.apache.commons.graph.utils.Assertions.checkState; > +import static org.apache.commons.graph.utils.Assertions.checkNotNull; > > =C2=A0import java.util.ArrayList; > =C2=A0import java.util.Collection; > @@ -62,6 +64,9 @@ public final class DefaultSccAlgorithmSe > =C2=A0 =C2=A0 =C2=A0*/ > =C2=A0 =C2=A0 public Set applyingKosarajuSharir( final V source ) > =C2=A0 =C2=A0 { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0checkNotNull( source, "Kosaraju Sharir algor= ithm cannot be calculated without expressing the source vertex" ); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0checkState( graph.containsVertex( source ), = "Vertex %s does not exist in the Graph", source ); > + > =C2=A0 =C2=A0 =C2=A0 =C2=A0 final Set visitedVertices =3D new HashSet<= V>(); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 final List expandedVertexList =3D getExpan= dedVertexList( source, visitedVertices ); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 final DirectedGraph reverted =3D new Re= vertedGraph( graph ); > > Modified: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/gr= aph/scc/KosarajuSharirTestCase.java > URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/ja= va/org/apache/commons/graph/scc/KosarajuSharirTestCase.java?rev=3D1295924&r= 1=3D1295923&r2=3D1295924&view=3Ddiff > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/sc= c/KosarajuSharirTestCase.java (original) > +++ commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/sc= c/KosarajuSharirTestCase.java Thu Mar =C2=A01 21:51:40 2012 > @@ -21,7 +21,7 @@ package org.apache.commons.graph.scc; > > =C2=A0import static org.apache.commons.graph.CommonsGraph.findStronglyCon= nectedComponent; > =C2=A0import static org.apache.commons.graph.CommonsGraph.newDirectedMuta= bleGraph; > - > +import static org.apache.commons.graph.CommonsGraph.newDirectedMutableWe= ightedGraph; > =C2=A0import static org.junit.Assert.assertEquals; > =C2=A0import static org.junit.Assert.assertFalse; > > @@ -32,7 +32,9 @@ import java.util.Set; > =C2=A0import org.apache.commons.graph.builder.AbstractGraphConnection; > =C2=A0import org.apache.commons.graph.model.BaseLabeledEdge; > =C2=A0import org.apache.commons.graph.model.BaseLabeledVertex; > +import org.apache.commons.graph.model.BaseLabeledWeightedEdge; > =C2=A0import org.apache.commons.graph.model.DirectedMutableGraph; > +import org.apache.commons.graph.model.DirectedMutableWeightedGraph; > =C2=A0import org.junit.Test; > > =C2=A0/** > @@ -42,8 +44,93 @@ import org.junit.Test; > =C2=A0public final class KosarajuSharirTestCase > =C2=A0{ > > + =C2=A0 =C2=A0@Test( expected =3D NullPointerException.class ) > + =C2=A0 =C2=A0public void testNullGraph() > + =C2=A0 =C2=A0{ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0DirectedMutableWeightedGraph, Integer> graph =3D null; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0findStronglyConnectedComponent( graph ).appl= yingKosarajuSharir(); > + =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0@Test( expected =3D NullPointerException.class ) > + =C2=A0 =C2=A0public void testNullVertices() > + =C2=A0 =C2=A0{ > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0final BaseLabeledVertex a =3D null; > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0DirectedMutableWeightedGraph, Integer> graph =3D > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0newDirectedMutableWeightedGrap= h( new AbstractGraphConnection>() > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0@Override > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0public void conn= ect() > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} ); > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0findStronglyConnectedComponent( graph ).appl= yingKosarajuSharir( a ); > + =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0@Test( expected =3D IllegalStateException.class ) > + =C2=A0 =C2=A0public void testNotExistVertex() > + =C2=A0 =C2=A0{ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0DirectedMutableWeightedGraph, Integer> graph =3D > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0newDirectedMutableWeightedGrap= h( new AbstractGraphConnection>() > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0@Override > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0public void conn= ect() > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} ); > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0findStronglyConnectedComponent( graph ).appl= yingKosarajuSharir( new BaseLabeledVertex( "NOT EXISTS" ) ); > + =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0@Test > + =C2=A0 =C2=A0public void testEmptyGraph() > + =C2=A0 =C2=A0{ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0DirectedMutableWeightedGraph, Integer> graph =3D > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0newDirectedMutableWeightedGrap= h( new AbstractGraphConnection>() > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0@Override > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0public void conn= ect() > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} ); > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0findStronglyConnectedComponent( graph ).appl= yingKosarajuSharir(); > + =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0@Test > + =C2=A0 =C2=A0public void testSparse() > + =C2=A0 =C2=A0{ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0DirectedMutableWeightedGraph, Integer> graph =3D > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0newDirectedMutableWeightedGrap= h( new AbstractGraphConnection>() > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0@Override > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0public void conn= ect() > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ad= dVertex( new BaseLabeledVertex( "A" ) ); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ad= dVertex( new BaseLabeledVertex( "B" ) ); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ad= dVertex( new BaseLabeledVertex( "C" ) ); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ad= dVertex( new BaseLabeledVertex( "D" ) ); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ad= dVertex( new BaseLabeledVertex( "E" ) ); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ad= dVertex( new BaseLabeledVertex( "F" ) ); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} ); > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0// expected strong components > + =C2=A0 =C2=A0 =C2=A0 =C2=A0final int expected =3D 6; > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0// actual strong components > + =C2=A0 =C2=A0 =C2=A0 =C2=A0Set> actual =3D findS= tronglyConnectedComponent( graph ).applyingKosarajuSharir(); > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0assertEquals( actual.size(), expected ); > + =C2=A0 =C2=A0} > + > =C2=A0 =C2=A0 @Test > - =C2=A0 =C2=A0//@Ignore > =C2=A0 =C2=A0 public void verifyHasStronglyConnectedComponents() > =C2=A0 =C2=A0 { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 final BaseLabeledVertex a =3D new BaseLabeled= Vertex( "A" ); > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org