You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dd...@apache.org on 2002/05/08 20:24:48 UTC
cvs commit: jakarta-commons-sandbox/graph2/src/test/org/apache/commons/graph/contract AcyclicContractTest.java DAGTest.java
ddp 02/05/08 11:24:48
Modified: graph2/src/test/org/apache/commons/graph DirGraphTest.java
GraphTest.java UndirGraphTest.java
WeightedGraphTest.java
graph2/src/test/org/apache/commons/graph/contract
AcyclicContractTest.java DAGTest.java
Log:
Synching with the latest copy. Everything works, and the
tests all run. . .
Revision Changes Path
1.2 +478 -478 jakarta-commons-sandbox/graph2/src/test/org/apache/commons/graph/DirGraphTest.java
Index: DirGraphTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/graph2/src/test/org/apache/commons/graph/DirGraphTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DirGraphTest.java 17 Mar 2002 16:28:18 -0000 1.1
+++ DirGraphTest.java 8 May 2002 18:24:47 -0000 1.2
@@ -1,478 +1,478 @@
-package org.apache.commons.graph;
-
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Commons" must not be used to endorse or promote products
- * derived from this software without prior written permission. For
- * written permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * "Commons", nor may "Apache" appear in their name, without
- * prior written permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-/**
- * DirGraphTest This test will ensure that we can represent a Directed Graph.
- */
-
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Iterator;
-
-/**
- * Description of the Class
- */
-public class DirGraphTest
- extends GraphTest
-{
- private String testName = null;
-
- /**
- * Constructor for the DirGraphTest object
- *
- * @param name
- */
- public DirGraphTest(String name)
- {
- super(name);
- this.testName = name;
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDirNull()
- throws Throwable
- {
- verifyGraph(makeDirNullGraph(), 0, 0);
- }
-
- /**
- * A unit test for JUnit
- */
- public void testSingleVertex()
- throws Throwable
- {
- verifyGraph(makeDirSingleVertex(), 1, 0);
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDoubleVertex()
- throws Throwable
- {
- verifyGraph(makeDirDoubleVertex(), 2, 0);
- }
-
- /**
- * A unit test for JUnit
- */
- public void testSelfLoop()
- throws Throwable
- {
- DirectedGraph IUT = makeSelfLoop();
- try
- {
-
- verifyGraph(IUT, 1, 1);
-
- verifyAdjVertices(IUT, V1,
- makeSet(V1));
-
- verifyAdjVertices(IUT, V1,
- makeSet(V1),
- makeSet(V1));
- }
- catch (Throwable t)
- {
- printGraph(t, IUT);
- throw t;
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDirectedEdge()
- throws Throwable
- {
- DirectedGraph IUT = makeDirectedEdge();
- try
- {
-
- verifyGraph(IUT, 2, 1);
-
- verifyAdjVertices(IUT, V1,
- makeSet(V1, V2));
- verifyAdjVertices(IUT, V1,
- makeSet(V1, V2));
-
- verifyAdjVertices(IUT, V1,
- makeSet(),
- makeSet(V2));
- verifyAdjVertices(IUT, V2,
- makeSet(V1),
- makeSet());
- }
- catch (Throwable t)
- {
- printGraph(t, IUT);
- throw t;
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDirParallelEdges()
- throws Throwable
- {
- DirectedGraph IUT = makeDirParallelEdges();
- try
- {
-
- verifyGraph(IUT, 2, 2);
-
- verifyAdjVertices(IUT, V1,
- makeSet(V1, V2));
- verifyAdjVertices(IUT, V2,
- makeSet(V1, V2));
-
- verifyAdjVertices(IUT, V1,
- makeSet(),
- makeSet(V2));
- verifyAdjVertices(IUT, V2,
- makeSet(V1),
- makeSet());
-
- }
- catch (Throwable t)
- {
- printGraph(t, IUT);
- throw t;
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testTwoCycle()
- throws Throwable
- {
- DirectedGraph IUT = makeTwoCycle();
- try
- {
-
- verifyGraph(IUT, 2, 2);
-
- verifyAdjVertices(IUT, V1,
- makeSet(V1, V2));
- verifyAdjVertices(IUT, V2,
- makeSet(V1, V2));
-
- verifyAdjVertices(IUT, V1,
- makeSet(V2),
- makeSet(V2));
- verifyAdjVertices(IUT, V2,
- makeSet(V1),
- makeSet(V1));
- }
- catch (Throwable t)
- {
- printGraph(t, IUT);
- throw t;
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDirectedCycle()
- throws Throwable
- {
- DirectedGraph IUT = makeDirectedCycle();
- try
- {
-
- verifyGraph(IUT, 3, 3);
-
- verifyAdjVertices(IUT, V1,
- makeSet(V1, V2, V3));
- verifyAdjVertices(IUT, V2,
- makeSet(V1, V2, V3));
- verifyAdjVertices(IUT, V3,
- makeSet(V1, V2, V3));
-
- verifyAdjVertices(IUT, V1,
- makeSet(V3),
- makeSet(V2));
- verifyAdjVertices(IUT, V2,
- makeSet(V1),
- makeSet(V3));
- verifyAdjVertices(IUT, V3,
- makeSet(V2),
- makeSet(V1));
- }
- catch (Throwable t)
- {
- printGraph(t, IUT);
- throw t;
- }
- }
-
-
- /**
- * A unit test for JUnit
- */
- public void testPipe()
- throws Throwable
- {
- DirectedGraph IUT = makePipe();
- try
- {
-
- verifyGraph(IUT, 3, 2);
-
- verifyAdjVertices(IUT, V1,
- makeSet(V1, V2));
- verifyAdjVertices(IUT, V2,
- makeSet(V1, V2, V3));
- verifyAdjVertices(IUT, V3,
- makeSet(V2, V3));
-
- verifyAdjVertices(IUT, V1,
- makeSet(),
- makeSet(V2));
- verifyAdjVertices(IUT, V2,
- makeSet(V1),
- makeSet(V3));
- verifyAdjVertices(IUT, V3,
- makeSet(V2),
- makeSet());
- }
- catch (Throwable t)
- {
- printGraph(t, IUT);
- throw t;
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDiamond()
- throws Throwable
- {
- DirectedGraph IUT = makeDiamond();
- try
- {
-
- verifyGraph(IUT, 4, 4);
-
- verifyAdjVertices(IUT, V1,
- makeSet(V1, V2, V3));
- verifyAdjVertices(IUT, V2,
- makeSet(V1, V2, V4));
- verifyAdjVertices(IUT, V3,
- makeSet(V1, V3, V4));
- verifyAdjVertices(IUT, V4,
- makeSet(V2, V3, V4));
-
- verifyAdjVertices(IUT, V1,
- makeSet(),
- makeSet(V2, V3));
- verifyAdjVertices(IUT, V2,
- makeSet(V1),
- makeSet(V4));
- verifyAdjVertices(IUT, V3,
- makeSet(V1),
- makeSet(V4));
- verifyAdjVertices(IUT, V4,
- makeSet(V2, V3),
- makeSet());
- }
- catch (Throwable t)
- {
- printGraph(t, IUT);
- throw t;
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testPipelessCycle()
- throws Throwable
- {
- DirectedGraph IUT = makePipelessCycle();
- try
- {
-
- verifyGraph(IUT, 4, 4);
-
- verifyAdjVertices(IUT, V1,
- makeSet(V1, V2, V3));
- verifyAdjVertices(IUT, V2,
- makeSet(V1, V2, V4));
- verifyAdjVertices(IUT, V3,
- makeSet(V1, V3, V4));
- verifyAdjVertices(IUT, V4,
- makeSet(V2, V3, V4));
-
- verifyAdjVertices(IUT, V1,
- makeSet(),
- makeSet(V2, V3));
- verifyAdjVertices(IUT, V2,
- makeSet(V1, V4),
- makeSet());
- verifyAdjVertices(IUT, V3,
- makeSet(V1, V4),
- makeSet());
- verifyAdjVertices(IUT, V4,
- makeSet(),
- makeSet(V2, V3));
- }
- catch (Throwable t)
- {
- printGraph(t, IUT);
- throw t;
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testParentTree()
- throws Throwable
- {
- DirectedGraph IUT = makeParentTree();
- try
- {
-
- verifyGraph(IUT, 5, 4);
-
- verifyAdjVertices(IUT, V1,
- makeSet(V1, V2, V3));
- verifyAdjVertices(IUT, V2,
- makeSet(V1, V2));
- verifyAdjVertices(IUT, V3,
- makeSet(V1, V3, V4, V5));
- verifyAdjVertices(IUT, V4,
- makeSet(V3, V4));
- verifyAdjVertices(IUT, V5,
- makeSet(V3, V5));
-
- verifyAdjVertices(IUT, V1,
- makeSet(V2, V3),
- makeSet());
- verifyAdjVertices(IUT, V2,
- makeSet(),
- makeSet(V1));
- verifyAdjVertices(IUT, V3,
- makeSet(V4, V5),
- makeSet(V1));
- verifyAdjVertices(IUT, V4,
- makeSet(),
- makeSet(V3));
- verifyAdjVertices(IUT, V5,
- makeSet(),
- makeSet(V3));
- }
- catch (Throwable t)
- {
- printGraph(t, IUT);
- throw t;
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testChildTree()
- throws Throwable
- {
- DirectedGraph IUT = makeChildTree();
- try
- {
-
- verifyGraph(IUT, 5, 4);
-
- verifyAdjVertices(IUT, V1,
- makeSet(V1, V2, V3));
- verifyAdjVertices(IUT, V2,
- makeSet(V1, V2));
- verifyAdjVertices(IUT, V3,
- makeSet(V1, V3, V4, V5));
- verifyAdjVertices(IUT, V4,
- makeSet(V3, V4));
- verifyAdjVertices(IUT, V5,
- makeSet(V3, V5));
-
- verifyAdjVertices(IUT, V1,
- makeSet(),
- makeSet(V2, V3));
- verifyAdjVertices(IUT, V2,
- makeSet(V1),
- makeSet());
- verifyAdjVertices(IUT, V3,
- makeSet(V1),
- makeSet(V4, V5));
- verifyAdjVertices(IUT, V4,
- makeSet(V3),
- makeSet());
- verifyAdjVertices(IUT, V5,
- makeSet(V3),
- makeSet());
- }
- catch (Throwable t)
- {
- printGraph(t, IUT);
- throw t;
- }
- }
-
-}
+package org.apache.commons.graph;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Commons" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Commons", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+/**
+ * DirGraphTest This test will ensure that we can represent a Directed Graph.
+ */
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
+
+/**
+ * Description of the Class
+ */
+public class DirGraphTest
+ extends GraphTest
+{
+ private String testName = null;
+
+ /**
+ * Constructor for the DirGraphTest object
+ *
+ * @param name
+ */
+ public DirGraphTest(String name)
+ {
+ super(name);
+ this.testName = name;
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDirNull()
+ throws Throwable
+ {
+ verifyGraph(makeDirNullGraph(), 0, 0);
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testSingleVertex()
+ throws Throwable
+ {
+ verifyGraph(makeDirSingleVertex(), 1, 0);
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDoubleVertex()
+ throws Throwable
+ {
+ verifyGraph(makeDirDoubleVertex(), 2, 0);
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testSelfLoop()
+ throws Throwable
+ {
+ DirectedGraph IUT = makeSelfLoop();
+ try
+ {
+
+ verifyGraph(IUT, 1, 1);
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(V1));
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(V1),
+ makeSet(V1));
+ }
+ catch (Throwable t)
+ {
+ printGraph(t, IUT);
+ throw t;
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDirectedEdge()
+ throws Throwable
+ {
+ DirectedGraph IUT = makeDirectedEdge();
+ try
+ {
+
+ verifyGraph(IUT, 2, 1);
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(V1, V2));
+ verifyAdjVertices(IUT, V1,
+ makeSet(V1, V2));
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(),
+ makeSet(V2));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1),
+ makeSet());
+ }
+ catch (Throwable t)
+ {
+ printGraph(t, IUT);
+ throw t;
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDirParallelEdges()
+ throws Throwable
+ {
+ DirectedGraph IUT = makeDirParallelEdges();
+ try
+ {
+
+ verifyGraph(IUT, 2, 2);
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(V1, V2));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1, V2));
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(),
+ makeSet(V2));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1),
+ makeSet());
+
+ }
+ catch (Throwable t)
+ {
+ printGraph(t, IUT);
+ throw t;
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testTwoCycle()
+ throws Throwable
+ {
+ DirectedGraph IUT = makeTwoCycle();
+ try
+ {
+
+ verifyGraph(IUT, 2, 2);
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(V1, V2));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1, V2));
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(V2),
+ makeSet(V2));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1),
+ makeSet(V1));
+ }
+ catch (Throwable t)
+ {
+ printGraph(t, IUT);
+ throw t;
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDirectedCycle()
+ throws Throwable
+ {
+ DirectedGraph IUT = makeDirectedCycle();
+ try
+ {
+
+ verifyGraph(IUT, 3, 3);
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(V1, V2, V3));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1, V2, V3));
+ verifyAdjVertices(IUT, V3,
+ makeSet(V1, V2, V3));
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(V3),
+ makeSet(V2));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1),
+ makeSet(V3));
+ verifyAdjVertices(IUT, V3,
+ makeSet(V2),
+ makeSet(V1));
+ }
+ catch (Throwable t)
+ {
+ printGraph(t, IUT);
+ throw t;
+ }
+ }
+
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testPipe()
+ throws Throwable
+ {
+ DirectedGraph IUT = makePipe();
+ try
+ {
+
+ verifyGraph(IUT, 3, 2);
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(V1, V2));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1, V2, V3));
+ verifyAdjVertices(IUT, V3,
+ makeSet(V2, V3));
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(),
+ makeSet(V2));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1),
+ makeSet(V3));
+ verifyAdjVertices(IUT, V3,
+ makeSet(V2),
+ makeSet());
+ }
+ catch (Throwable t)
+ {
+ printGraph(t, IUT);
+ throw t;
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDiamond()
+ throws Throwable
+ {
+ DirectedGraph IUT = makeDiamond();
+ try
+ {
+
+ verifyGraph(IUT, 4, 4);
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(V1, V2, V3));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1, V2, V4));
+ verifyAdjVertices(IUT, V3,
+ makeSet(V1, V3, V4));
+ verifyAdjVertices(IUT, V4,
+ makeSet(V2, V3, V4));
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(),
+ makeSet(V2, V3));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1),
+ makeSet(V4));
+ verifyAdjVertices(IUT, V3,
+ makeSet(V1),
+ makeSet(V4));
+ verifyAdjVertices(IUT, V4,
+ makeSet(V2, V3),
+ makeSet());
+ }
+ catch (Throwable t)
+ {
+ printGraph(t, IUT);
+ throw t;
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testPipelessCycle()
+ throws Throwable
+ {
+ DirectedGraph IUT = makePipelessCycle();
+ try
+ {
+
+ verifyGraph(IUT, 4, 4);
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(V1, V2, V3));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1, V2, V4));
+ verifyAdjVertices(IUT, V3,
+ makeSet(V1, V3, V4));
+ verifyAdjVertices(IUT, V4,
+ makeSet(V2, V3, V4));
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(),
+ makeSet(V2, V3));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1, V4),
+ makeSet());
+ verifyAdjVertices(IUT, V3,
+ makeSet(V1, V4),
+ makeSet());
+ verifyAdjVertices(IUT, V4,
+ makeSet(),
+ makeSet(V2, V3));
+ }
+ catch (Throwable t)
+ {
+ printGraph(t, IUT);
+ throw t;
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testParentTree()
+ throws Throwable
+ {
+ DirectedGraph IUT = makeParentTree();
+ try
+ {
+
+ verifyGraph(IUT, 5, 4);
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(V1, V2, V3));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1, V2));
+ verifyAdjVertices(IUT, V3,
+ makeSet(V1, V3, V4, V5));
+ verifyAdjVertices(IUT, V4,
+ makeSet(V3, V4));
+ verifyAdjVertices(IUT, V5,
+ makeSet(V3, V5));
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(V2, V3),
+ makeSet());
+ verifyAdjVertices(IUT, V2,
+ makeSet(),
+ makeSet(V1));
+ verifyAdjVertices(IUT, V3,
+ makeSet(V4, V5),
+ makeSet(V1));
+ verifyAdjVertices(IUT, V4,
+ makeSet(),
+ makeSet(V3));
+ verifyAdjVertices(IUT, V5,
+ makeSet(),
+ makeSet(V3));
+ }
+ catch (Throwable t)
+ {
+ printGraph(t, IUT);
+ throw t;
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testChildTree()
+ throws Throwable
+ {
+ DirectedGraph IUT = makeChildTree();
+ try
+ {
+
+ verifyGraph(IUT, 5, 4);
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(V1, V2, V3));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1, V2));
+ verifyAdjVertices(IUT, V3,
+ makeSet(V1, V3, V4, V5));
+ verifyAdjVertices(IUT, V4,
+ makeSet(V3, V4));
+ verifyAdjVertices(IUT, V5,
+ makeSet(V3, V5));
+
+ verifyAdjVertices(IUT, V1,
+ makeSet(),
+ makeSet(V2, V3));
+ verifyAdjVertices(IUT, V2,
+ makeSet(V1),
+ makeSet());
+ verifyAdjVertices(IUT, V3,
+ makeSet(V1),
+ makeSet(V4, V5));
+ verifyAdjVertices(IUT, V4,
+ makeSet(V3),
+ makeSet());
+ verifyAdjVertices(IUT, V5,
+ makeSet(V3),
+ makeSet());
+ }
+ catch (Throwable t)
+ {
+ printGraph(t, IUT);
+ throw t;
+ }
+ }
+
+}
1.2 +1026 -952 jakarta-commons-sandbox/graph2/src/test/org/apache/commons/graph/GraphTest.java
Index: GraphTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/graph2/src/test/org/apache/commons/graph/GraphTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GraphTest.java 17 Mar 2002 16:28:18 -0000 1.1
+++ GraphTest.java 8 May 2002 18:24:47 -0000 1.2
@@ -1,952 +1,1026 @@
-package org.apache.commons.graph;
-
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Commons" must not be used to endorse or promote products
- * derived from this software without prior written permission. For
- * written permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * "Commons", nor may "Apache" appear in their name, without
- * prior written permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-/**
- * GraphTest This is a superclass of other tests to provide some utilities in
- * verifying graphs. This test will provide Undirected and Directed Graphs as
- * well. We will implement the following graphs. Undirected Graphs
- * ------------------- () No Vertex, No Edges @ One Vertex, No Edges @ @ Two
- * Vertices, No Edges @-@ Two Vertices, One edge /-\ @ @ Two Vertices, Two Edges
- * (Parallel Edges) \-/ @ / \ Three Vertices, Three Edges (Cycle) @---@ @--@--@
- * Three Vertices, Two Edges (No Cycle) @ / \ @ @ 5 Vertices, 4 Edges (Tree) / \
- * @ @ @-@ @-@ 4 Vertices, 2 Edges (Disconnected)
- */
-
-import java.util.Set;
-import java.util.Map;
-import java.util.HashSet;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import junit.framework.*;
-
-import org.apache.commons.graph.impl.*;
-import org.apache.commons.graph.exception.*;
-
-/**
- * Description of the Class
- */
-public class GraphTest extends TestCase
-{
- /**
- * Description of the Class
- */
- public class VertexImpl
- implements Vertex
- {
- private String name = null;
-
- /**
- * Constructor for the VertexImpl object
- *
- * @param name
- */
- public VertexImpl(String name)
- {
- this.name = name;
- }
-
- /**
- * Description of the Method
- */
- public String toString()
- {
- return name;
- }
- }
-
- /**
- * Description of the Class
- */
- public class EdgeImpl
- implements Edge
- {
- private Vertex start;
- private Vertex end;
-
- /**
- * Constructor for the EdgeImpl object
- *
- * @param start
- * @param end
- */
- public EdgeImpl(Vertex start,
- Vertex end)
- {
- this.start = start;
- this.end = end;
- }
-
- /**
- * Gets the otherVertex attribute of the EdgeImpl object
- */
- public Vertex getOtherVertex(Vertex v)
- {
- if (v == start)
- {
- return end;
- }
- if (v == end)
- {
- return start;
- }
- return null;
- }
-
- /**
- * Gets the vertices attribute of the EdgeImpl object
- */
- public Set getVertices()
- {
- Set RC = new HashSet();
- RC.add(start);
- RC.add(end);
- return RC;
- }
-
- /**
- * Gets the source attribute of the EdgeImpl object
- */
- public Vertex getSource()
- {
- return start;
- }
-
- /**
- * Gets the target attribute of the EdgeImpl object
- */
- public Vertex getTarget()
- {
- return end;
- }
-
- /**
- * Description of the Method
- */
- public String toString()
- {
- return start.toString() + " <-> " + end.toString();
- }
- }
-
- /**
- * Description of the Field
- */
- public Vertex V1 = new VertexImpl("V1");
- /**
- * Description of the Field
- */
- public Vertex V2 = new VertexImpl("V2");
- /**
- * Description of the Field
- */
- public Vertex V3 = new VertexImpl("V3");
- /**
- * Description of the Field
- */
- public Vertex V4 = new VertexImpl("V4");
- /**
- * Description of the Field
- */
- public Vertex V5 = new VertexImpl("V5");
-
- /**
- * Description of the Field
- */
- public EdgeImpl V1_V1 = new EdgeImpl(V1, V1);// For Self-Loops.
- /**
- * Description of the Field
- */
- public EdgeImpl V1_V2 = new EdgeImpl(V1, V2);
- /**
- * Description of the Field
- */
- public EdgeImpl V1_V2_ = new EdgeImpl(V1, V2);// For Parallel
- /**
- * Description of the Field
- */
- public EdgeImpl V1_V2__ = new EdgeImpl(V1, V2);// For Parallel #2
- /**
- * Description of the Field
- */
- public EdgeImpl V1_V3 = new EdgeImpl(V1, V3);
- /**
- * Description of the Field
- */
- public EdgeImpl V1_V4 = new EdgeImpl(V1, V4);
- /**
- * Description of the Field
- */
- public EdgeImpl V1_V5 = new EdgeImpl(V1, V5);
-
- /**
- * Description of the Field
- */
- public EdgeImpl V2_V1 = new EdgeImpl(V2, V1);
- /**
- * Description of the Field
- */
- public EdgeImpl V2_V3 = new EdgeImpl(V2, V3);
- /**
- * Description of the Field
- */
- public EdgeImpl V2_V4 = new EdgeImpl(V2, V4);
- /**
- * Description of the Field
- */
- public EdgeImpl V2_V5 = new EdgeImpl(V2, V5);
-
- /**
- * Description of the Field
- */
- public EdgeImpl V3_V1 = new EdgeImpl(V3, V1);
- /**
- * Description of the Field
- */
- public EdgeImpl V3_V2 = new EdgeImpl(V3, V2);
- /**
- * Description of the Field
- */
- public EdgeImpl V3_V4 = new EdgeImpl(V3, V4);
- /**
- * Description of the Field
- */
- public EdgeImpl V3_V5 = new EdgeImpl(V3, V5);
-
- /**
- * Description of the Field
- */
- public EdgeImpl V4_V1 = new EdgeImpl(V4, V1);
- /**
- * Description of the Field
- */
- public EdgeImpl V4_V2 = new EdgeImpl(V4, V2);
- /**
- * Description of the Field
- */
- public EdgeImpl V4_V3 = new EdgeImpl(V4, V3);
- /**
- * Description of the Field
- */
- public EdgeImpl V4_V5 = new EdgeImpl(V4, V5);
-
- /**
- * Description of the Field
- */
- public EdgeImpl V5_V1 = new EdgeImpl(V5, V1);
- /**
- * Description of the Field
- */
- public EdgeImpl V5_V2 = new EdgeImpl(V5, V2);
- /**
- * Description of the Field
- */
- public EdgeImpl V5_V3 = new EdgeImpl(V5, V3);
- /**
- * Description of the Field
- */
- public EdgeImpl V5_V4 = new EdgeImpl(V5, V4);
-
- /**
- * Constructor for the GraphTest object
- *
- * @param name
- */
- public GraphTest(String name)
- {
- super(name);
- this.testName = name;
- }
-
- private String testName = null;
-
- /**
- * Return this graph: ()
- */
- public UndirectedGraph makeNullGraph()
- throws GraphException
- {
- return new UndirectedGraphImpl();
- }
-
- /**
- * Description of the Method
- */
- public DirectedGraph makeDirNullGraph()
- throws GraphException
- {
- return new DirectedGraphImpl();
- }
-
- /**
- * Return this graph: v1
- */
- public UndirectedGraph makeSingleVertex()
- throws GraphException
- {
- UndirectedGraphImpl RC = new UndirectedGraphImpl();
- RC.addVertex(V1);
- return RC;
- }
-
- /**
- * Description of the Method
- */
- public DirectedGraph makeDirSingleVertex()
- throws GraphException
- {
- DirectedGraphImpl RC = new DirectedGraphImpl();
- RC.addVertex(V1);
- return RC;
- }
-
- /**
- * /--\ v1 | ^--/
- */
- public DirectedGraph makeSelfLoop()
- throws GraphException
- {
- DirectedGraphImpl RC = new DirectedGraphImpl();
- RC.addVertex(V1);
- RC.addEdge(V1_V1, V1, V1);
- return RC;
- }
-
- /**
- * v1 v2 Two Vertices, No Edges
- */
- public UndirectedGraph makeDoubleVertex()
- throws GraphException
- {
- UndirectedGraphImpl RC = new UndirectedGraphImpl();
- RC.addVertex(V1);
- RC.addVertex(V2);
- return RC;
- }
-
- /**
- * Description of the Method
- */
- public DirectedGraph makeDirDoubleVertex()
- throws GraphException
- {
- DirectedGraphImpl RC = new DirectedGraphImpl();
- RC.addVertex(V1);
- RC.addVertex(V2);
- return RC;
- }
-
- /**
- * v1-v2 Two Vertices, One edge
- */
- public UndirectedGraph makeSingleEdge()
- throws GraphException
- {
- UndirectedGraphImpl RC = new UndirectedGraphImpl();
-
- RC.addVertex(V1);
- RC.addVertex(V2);
-
- RC.addEdge(V1_V2, V1_V2.getVertices());
-
- return RC;
- }
-
- /**
- * v1 -> v2 Directed Edge
- */
- public DirectedGraph makeDirectedEdge()
- throws GraphException
- {
- DirectedGraphImpl RC = new DirectedGraphImpl();
-
- RC.addVertex(V1);
- RC.addVertex(V2);
-
- RC.addEdge(V1_V2,
- V1, V2);
-
- return RC;
- }
-
- /**
- * /-\ v1 v2 Two Vertices, Two Edges (Parallel Edges) \-/
- */
- public UndirectedGraph makeParallelEdges()
- throws GraphException
- {
- UndirectedGraphImpl RC = new UndirectedGraphImpl();
-
- RC.addVertex(V1);
- RC.addVertex(V2);
-
- RC.addEdge(V1_V2, V1_V2.getVertices());
- RC.addEdge(V1_V2_, V1_V2_.getVertices());
-
- return RC;
- }
-
- /**
- * /--->\ @ @ \--->/
- */
- public DirectedGraph makeDirParallelEdges()
- throws GraphException
- {
- DirectedGraphImpl RC = new DirectedGraphImpl();
-
- RC.addVertex(V1);
- RC.addVertex(V2);
-
- RC.addEdge(V1_V2, V1, V2);
- // Second edge must be distinct. . .
- RC.addEdge(V1_V2_, V1, V2);
-
- return RC;
- }
-
- /**
- * v1 / \ Three Vertices, Three Edges (Cycle) v2---v3
- */
- public UndirectedGraph makeCycle()
- throws GraphException
- {
- UndirectedGraphImpl RC = new UndirectedGraphImpl();
-
- RC.addVertex(V1);
- RC.addVertex(V2);
- RC.addVertex(V3);
-
- RC.addEdge(V1_V2, V1_V2.getVertices());
- RC.addEdge(V2_V3, V2_V3.getVertices());
- RC.addEdge(V3_V1, V3_V1.getVertices());
-
- return RC;
- }
-
- /**
- * /--->\ v1 v2 \<---/
- */
- public DirectedGraph makeTwoCycle()
- throws GraphException
- {
- DirectedGraphImpl RC = new DirectedGraphImpl();
-
- RC.addVertex(V1);
- RC.addVertex(V2);
-
- RC.addEdge(V1_V2, V1, V2);
- RC.addEdge(V2_V1, V2, V1);
-
- return RC;
- }
-
- /**
- * v1 / ^ v \ v2 ---> v3
- */
- public DirectedGraph makeDirectedCycle()
- throws GraphException
- {
- DirectedGraphImpl RC = new DirectedGraphImpl();
-
- RC.addVertex(V1);
- RC.addVertex(V2);
- RC.addVertex(V3);
-
- RC.addEdge(V1_V2, V1, V2);
- RC.addEdge(V2_V3, V2, V3);
- RC.addEdge(V3_V1, V3, V1);
-
- return RC;
- }
-
- /**
- * v1--v2--v3 Three Vertices, Two Edges (No Cycle)
- */
- public UndirectedGraph makeNoCycle()
- throws GraphException
- {
- UndirectedGraphImpl RC = new UndirectedGraphImpl();
-
- RC.addVertex(V1);
- RC.addVertex(V2);
- RC.addVertex(V3);
-
- RC.addEdge(V1_V2, V1_V2.getVertices());
- RC.addEdge(V2_V3, V2_V3.getVertices());
-
- return RC;
- }
-
- /**
- * v1 --> v2 --> v3
- */
- public DirectedGraph makePipe()
- throws GraphException
- {
- DirectedGraphImpl RC = new DirectedGraphImpl();
-
- RC.addVertex(V1);
- RC.addVertex(V2);
- RC.addVertex(V3);
-
- RC.addEdge(V1_V2, V1, V2);
- RC.addEdge(V2_V3, V2, V3);
-
- return RC;
- }
-
- /**
- * v1 / \ v v v2 v3 \ / v v v4
- */
- public DirectedGraph makeDiamond()
- throws GraphException
- {
- DirectedGraphImpl RC = new DirectedGraphImpl();
-
- RC.addVertex(V1);
- RC.addVertex(V2);
- RC.addVertex(V3);
- RC.addVertex(V4);
-
- RC.addEdge(V1_V2, V1, V2);
- RC.addEdge(V1_V3, V1, V3);
- RC.addEdge(V2_V4, V2, V4);
- RC.addEdge(V3_V4, V3, V4);
-
- return RC;
- }
-
- /**
- * v1 / \ v v v2 v3 ^ ^ \ / v4
- */
- public DirectedGraph makePipelessCycle()
- throws GraphException
- {
- DirectedGraphImpl RC = new DirectedGraphImpl();
-
- RC.addVertex(V1);
- RC.addVertex(V2);
- RC.addVertex(V3);
- RC.addVertex(V4);
-
- RC.addEdge(V1_V2, V1, V2);
- RC.addEdge(V1_V3, V1, V3);
- RC.addEdge(V4_V2, V4, V2);
- RC.addEdge(V4_V3, V4, V3);
-
- return RC;
- }
-
- /**
- * v1 / \ v2 v3 5 Vertices, 4 Edges (Tree) / \ v4 v5
- */
- public UndirectedGraph makeTree()
- throws GraphException
- {
- UndirectedGraphImpl RC = new UndirectedGraphImpl();
-
- RC.addVertex(V1);
- RC.addVertex(V2);
- RC.addVertex(V3);
- RC.addVertex(V4);
- RC.addVertex(V5);
-
- RC.addEdge(V1_V2, V1_V2.getVertices());
- RC.addEdge(V1_V3, V1_V3.getVertices());
- RC.addEdge(V3_V4, V3_V4.getVertices());
- RC.addEdge(V3_V5, V3_V5.getVertices());
-
- return RC;
- }
-
- /**
- * Description of the Method
- */
- public DirectedGraph makeParentTree()
- throws GraphException
- {
- DirectedGraphImpl RC = new DirectedGraphImpl();
-
- RC.addVertex(V1);
- RC.addVertex(V2);
- RC.addVertex(V3);
- RC.addVertex(V4);
- RC.addVertex(V5);
-
- RC.addEdge(V2_V1, V2, V1);
- RC.addEdge(V3_V1, V3, V1);
- RC.addEdge(V4_V3, V4, V3);
- RC.addEdge(V5_V3, V5, V3);
-
- return RC;
- }
-
- /**
- * Description of the Method
- */
- public DirectedGraph makeChildTree()
- throws GraphException
- {
- DirectedGraphImpl RC = new DirectedGraphImpl();
-
- RC.addVertex(V1);
- RC.addVertex(V2);
- RC.addVertex(V3);
- RC.addVertex(V4);
- RC.addVertex(V5);
-
- RC.addEdge(V1_V2, V1, V2);
- RC.addEdge(V1_V3, V1, V3);
- RC.addEdge(V3_V4, V3, V4);
- RC.addEdge(V3_V5, V3, V5);
-
- return RC;
- }
-
- /**
- * v1-v2 v3-v4 4 Vertices, 2 Edges (Disconnected)
- */
- public UndirectedGraph makeDisconnected()
- throws GraphException
- {
- UndirectedGraphImpl RC = new UndirectedGraphImpl();
-
- RC.addVertex(V1);
- RC.addVertex(V2);
- RC.addVertex(V3);
- RC.addVertex(V4);
-
- RC.addEdge(V1_V2, V1_V2.getVertices());
- RC.addEdge(V3_V4, V3_V4.getVertices());
-
- return RC;
- }
-
- /**
- * A unit test for JUnit
- */
- public void testNothing()
- throws Throwable { }
-
- /**
- * Description of the Method
- */
- public void verifyVertexEdgeCount(Graph IUT,
- Vertex v,
- int numEdge)
- throws Throwable
- {
- assertEquals(v.toString() + " has wrong number of adjacent edges.",
- IUT.getEdges(v).size(), numEdge);
- }
-
- /**
- * Gets the outboundVertices attribute of the GraphTest object
- */
- private Set getOutboundVertices(DirectedGraph IUT,
- Vertex v)
- {
- Set RC = new HashSet();
- Iterator edges = IUT.getOutbound(v).iterator();
-
- while (edges.hasNext())
- {
- Edge e = (Edge) edges.next();
- RC.add(IUT.getTarget(e));
- }
-
- return RC;
- }
-
- /**
- * Gets the inboundVertices attribute of the GraphTest object
- */
- private Set getInboundVertices(DirectedGraph IUT,
- Vertex v)
- {
- Set RC = new HashSet();
- Iterator edges = IUT.getInbound(v).iterator();
-
- while (edges.hasNext())
- {
- Edge e = (Edge) edges.next();
- RC.add(IUT.getSource(e));
- }
-
- return RC;
- }
-
-
- /**
- * Gets the adjVertices attribute of the GraphTest object
- */
- private Set getAdjVertices(Graph IUT,
- Vertex v)
- {
- Set RC = new HashSet();
- Iterator edges = IUT.getEdges(v).iterator();
-
- while (edges.hasNext())
- {
- Edge e = (Edge) edges.next();
-
- Set verts = IUT.getVertices(e);
- RC.addAll(verts);
- }
-
- return RC;
- }
-
- /**
- * Description of the Method
- */
- public Set makeSet()
- {
- return new HashSet();
- }
-
- /**
- * Description of the Method
- */
- public Set makeSet(Vertex v)
- {
- Set RC = new HashSet();
- RC.add(v);
- return RC;
- }
-
- /**
- * Description of the Method
- */
- public Set makeSet(Vertex v1,
- Vertex v2)
- {
- Set RC = makeSet(v1);
- RC.add(v2);
- return RC;
- }
-
- /**
- * Description of the Method
- */
- public Set makeSet(Set s1,
- Set s2)
- {
- Set RC = new HashSet();
- RC.addAll(s1);
- RC.addAll(s2);
- return RC;
- }
-
- /**
- * Description of the Method
- */
- public Set makeSet(Vertex v1,
- Vertex v2,
- Vertex v3)
- {
- return makeSet(makeSet(v1, v2),
- makeSet(v3));
- }
-
- /**
- * Description of the Method
- */
- public Set makeSet(Vertex v1,
- Vertex v2,
- Vertex v3,
- Vertex v4)
- {
- return makeSet(makeSet(v1, v2),
- makeSet(v3, v4));
- }
-
-
- /**
- * Description of the Method
- */
- public void verifyAdjVertices(DirectedGraph IUT,
- Vertex v,
- Set inExpect,
- Set outExpect)
- {
- Set inbound = getInboundVertices(IUT, v);
- Set outbound = getOutboundVertices(IUT, v);
-
- Iterator verts;
-
- // inbound is a subset of inExpect
- verts = inbound.iterator();
-
- while (verts.hasNext())
- {
- Vertex curr = (Vertex) verts.next();
-
- assertTrue(curr.toString() + " is not supposed to be " +
- "next to " + v.toString(),
- inExpect.contains(curr));
- }
-
- // inExpect is a subset of inbound
- verts = inExpect.iterator();
-
- while (verts.hasNext())
- {
- Vertex curr = (Vertex) verts.next();
- assertTrue(curr.toString() + " is supposed to be next to " +
- v.toString(),
- inbound.contains(curr));
- }
-
- // outbound is a subset of outExpect
- verts = outbound.iterator();
-
- while (verts.hasNext())
- {
- Vertex curr = (Vertex) verts.next();
-
- assertTrue(curr.toString() + " is not supposed to be " +
- "next to " + v.toString(),
- outExpect.contains(curr));
- }
-
- // outExpect is a subset of outbound
- verts = outExpect.iterator();
-
- while (verts.hasNext())
- {
- Vertex curr = (Vertex) verts.next();
- assertTrue(curr.toString() + " is supposed to be next to " +
- v.toString(),
- outbound.contains(curr));
- }
-
- }
-
- /**
- * Description of the Method
- */
- public void verifyAdjVertices(Graph IUT,
- Vertex v,
- Set expected)
- throws Throwable
- {
- Set adjacent = getAdjVertices(IUT, v);
- Iterator adjV = adjacent.iterator();
-
- while (adjV.hasNext())
- {
- Vertex curr = (Vertex) adjV.next();
- assertTrue(curr.toString() + " is not supposed to be " +
- "next to " + v.toString(),
- expected.contains(curr));
- }
-
- Iterator expect = expected.iterator();
-
- while (expect.hasNext())
- {
- Vertex curr = (Vertex) expect.next();
- assertTrue(curr.toString() + " is supposed to be next to " +
- v.toString(),
- adjacent.contains(curr));
- }
- }
-
- /**
- * Description of the Method
- */
- public void verifyGraph(Graph g, int numVertex, int numEdge)
- throws Throwable
- {
- assertEquals("Incorrect Number of Vertices.",
- numVertex, g.getVertices().size());
- assertEquals("Incorrect Number of Edges.",
- numEdge, g.getEdges().size());
- }
-
- /**
- * Description of the Method
- */
- public void printGraph(Throwable t,
- DirectedGraph IUT)
- {
- System.err.println(testName + ": " + t.toString());
- System.err.println("VERTICES: " + IUT.getVertices());
- System.err.println("EDGES: " + IUT.getEdges());
-
- Iterator verts = IUT.getVertices().iterator();
- while (verts.hasNext())
- {
- Vertex vert = (Vertex) verts.next();
- System.err.println("[ " + vert + " ]");
-
- Iterator inbounds = IUT.getInbound(vert).iterator();
- while (inbounds.hasNext())
- {
- Edge inbound = (Edge) inbounds.next();
- System.err.println("\tI [" + inbound + "]");
- }
-
- Iterator outbounds = IUT.getOutbound(vert).iterator();
- while (outbounds.hasNext())
- {
- Edge outbound = (Edge) outbounds.next();
- System.err.println("\tO [" + outbound + "]");
- }
- }
- }
-
-}
+package org.apache.commons.graph;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Commons" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Commons", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+/**
+ * GraphTest This is a superclass of other tests to provide some utilities in
+ * verifying graphs. This test will provide Undirected and Directed Graphs as
+ * well. We will implement the following graphs. Undirected Graphs
+ * ------------------- () No Vertex, No Edges @ One Vertex, No Edges @ @ Two
+ * Vertices, No Edges @-@ Two Vertices, One edge /-\ @ @ Two Vertices, Two Edges
+ * (Parallel Edges) \-/ @ / \ Three Vertices, Three Edges (Cycle) @---@ @--@--@
+ * Three Vertices, Two Edges (No Cycle) @ / \ @ @ 5 Vertices, 4 Edges (Tree) / \
+ * @ @ @-@ @-@ 4 Vertices, 2 Edges (Disconnected)
+ */
+
+import java.util.Set;
+import java.util.Map;
+import java.util.HashSet;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import junit.framework.*;
+
+import org.apache.commons.graph.domain.basic.*;
+import org.apache.commons.graph.exception.*;
+
+/**
+ * Description of the Class
+ */
+public class GraphTest extends TestCase
+{
+ /**
+ * Description of the Class
+ */
+ public class VertexImpl
+ implements Vertex
+ {
+ private String name = null;
+
+ /**
+ * Constructor for the VertexImpl object
+ *
+ * @param name
+ */
+ public VertexImpl(String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Description of the Method
+ */
+ public String toString()
+ {
+ return name;
+ }
+ }
+
+ /**
+ * Description of the Class
+ */
+ public class EdgeImpl
+ implements Edge
+ {
+ private Vertex start;
+ private Vertex end;
+
+ /**
+ * Constructor for the EdgeImpl object
+ *
+ * @param start
+ * @param end
+ */
+ public EdgeImpl(Vertex start,
+ Vertex end)
+ {
+ this.start = start;
+ this.end = end;
+ }
+
+ /**
+ * Gets the otherVertex attribute of the EdgeImpl object
+ */
+ public Vertex getOtherVertex(Vertex v)
+ {
+ if (v == start)
+ {
+ return end;
+ }
+ if (v == end)
+ {
+ return start;
+ }
+ return null;
+ }
+
+ /**
+ * Gets the vertices attribute of the EdgeImpl object
+ */
+ public Set getVertices()
+ {
+ Set RC = new HashSet();
+ RC.add(start);
+ RC.add(end);
+ return RC;
+ }
+
+ /**
+ * Gets the source attribute of the EdgeImpl object
+ */
+ public Vertex getSource()
+ {
+ return start;
+ }
+
+ /**
+ * Gets the target attribute of the EdgeImpl object
+ */
+ public Vertex getTarget()
+ {
+ return end;
+ }
+
+ /**
+ * Description of the Method
+ */
+ public String toString()
+ {
+ return start.toString() + " <-> " + end.toString();
+ }
+ }
+
+ /**
+ * Description of the Field
+ */
+ public Vertex V1 = new VertexImpl("V1");
+ /**
+ * Description of the Field
+ */
+ public Vertex V2 = new VertexImpl("V2");
+ /**
+ * Description of the Field
+ */
+ public Vertex V3 = new VertexImpl("V3");
+ /**
+ * Description of the Field
+ */
+ public Vertex V4 = new VertexImpl("V4");
+ /**
+ * Description of the Field
+ */
+ public Vertex V5 = new VertexImpl("V5");
+
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V1_V1 = new EdgeImpl(V1, V1);// For Self-Loops.
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V1_V2 = new EdgeImpl(V1, V2);
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V1_V2_ = new EdgeImpl(V1, V2);// For Parallel
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V1_V2__ = new EdgeImpl(V1, V2);// For Parallel #2
+
+ public EdgeImpl V1_V2_V3 = new EdgeImpl(V1, V2); // HyperEdge. . .
+
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V1_V3 = new EdgeImpl(V1, V3);
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V1_V4 = new EdgeImpl(V1, V4);
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V1_V5 = new EdgeImpl(V1, V5);
+
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V2_V1 = new EdgeImpl(V2, V1);
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V2_V3 = new EdgeImpl(V2, V3);
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V2_V4 = new EdgeImpl(V2, V4);
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V2_V5 = new EdgeImpl(V2, V5);
+
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V3_V1 = new EdgeImpl(V3, V1);
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V3_V2 = new EdgeImpl(V3, V2);
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V3_V4 = new EdgeImpl(V3, V4);
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V3_V5 = new EdgeImpl(V3, V5);
+
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V4_V1 = new EdgeImpl(V4, V1);
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V4_V2 = new EdgeImpl(V4, V2);
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V4_V3 = new EdgeImpl(V4, V3);
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V4_V5 = new EdgeImpl(V4, V5);
+
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V5_V1 = new EdgeImpl(V5, V1);
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V5_V2 = new EdgeImpl(V5, V2);
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V5_V3 = new EdgeImpl(V5, V3);
+ /**
+ * Description of the Field
+ */
+ public EdgeImpl V5_V4 = new EdgeImpl(V5, V4);
+
+ /**
+ * Constructor for the GraphTest object
+ *
+ * @param name
+ */
+ public GraphTest(String name)
+ {
+ super(name);
+ this.testName = name;
+ }
+
+ private String testName = null;
+
+ /**
+ * Return this graph: ()
+ */
+ public UndirectedGraph makeNullGraph()
+ throws GraphException
+ {
+ return new UndirectedGraphImpl();
+ }
+
+ /**
+ * Description of the Method
+ */
+ public DirectedGraph makeDirNullGraph()
+ throws GraphException
+ {
+ return new DirectedGraphImpl();
+ }
+
+ /**
+ * Return this graph: v1
+ */
+ public UndirectedGraph makeSingleVertex()
+ throws GraphException
+ {
+ UndirectedGraphImpl RC = new UndirectedGraphImpl();
+ RC.addVertex(V1);
+ return RC;
+ }
+
+ /**
+ * Description of the Method
+ */
+ public DirectedGraph makeDirSingleVertex()
+ throws GraphException
+ {
+ DirectedGraphImpl RC = new DirectedGraphImpl();
+ RC.addVertex(V1);
+ return RC;
+ }
+
+ /**
+ * /--\ v1 | ^--/
+ */
+ public DirectedGraph makeSelfLoop()
+ throws GraphException
+ {
+ DirectedGraphImpl RC = new DirectedGraphImpl();
+ RC.addVertex(V1);
+ RC.addEdge(V1_V1, V1, V1);
+ return RC;
+ }
+
+ /**
+ * v1 v2 Two Vertices, No Edges
+ */
+ public UndirectedGraph makeDoubleVertex()
+ throws GraphException
+ {
+ UndirectedGraphImpl RC = new UndirectedGraphImpl();
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+ return RC;
+ }
+
+ /**
+ * Description of the Method
+ */
+ public DirectedGraph makeDirDoubleVertex()
+ throws GraphException
+ {
+ DirectedGraphImpl RC = new DirectedGraphImpl();
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+ return RC;
+ }
+
+ /**
+ * v1-v2 Two Vertices, One edge
+ */
+ public UndirectedGraph makeSingleEdge()
+ throws GraphException
+ {
+ UndirectedGraphImpl RC = new UndirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+
+ RC.addEdge(V1_V2, V1_V2.getVertices());
+
+ return RC;
+ }
+
+ /**
+ * v1 -> v2 Directed Edge
+ */
+ public DirectedGraph makeDirectedEdge()
+ throws GraphException
+ {
+ DirectedGraphImpl RC = new DirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+
+ RC.addEdge(V1_V2,
+ V1, V2);
+
+ return RC;
+ }
+
+ /**
+ * /-\ v1 v2 Two Vertices, Two Edges (Parallel Edges) \-/
+ */
+ public UndirectedGraph makeParallelEdges()
+ throws GraphException
+ {
+ UndirectedGraphImpl RC = new UndirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+
+ RC.addEdge(V1_V2, V1_V2.getVertices());
+ RC.addEdge(V1_V2_, V1_V2_.getVertices());
+
+ return RC;
+ }
+
+ /**
+ * /--->\ @ @ \--->/
+ */
+ public DirectedGraph makeDirParallelEdges()
+ throws GraphException
+ {
+ DirectedGraphImpl RC = new DirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+
+ RC.addEdge(V1_V2, V1, V2);
+ // Second edge must be distinct. . .
+ RC.addEdge(V1_V2_, V1, V2);
+
+ return RC;
+ }
+
+ /**
+ * v1 / \ Three Vertices, Three Edges (Cycle) v2---v3
+ */
+ public UndirectedGraph makeCycle()
+ throws GraphException
+ {
+ UndirectedGraphImpl RC = new UndirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+ RC.addVertex(V3);
+
+ RC.addEdge(V1_V2, V1_V2.getVertices());
+ RC.addEdge(V2_V3, V2_V3.getVertices());
+ RC.addEdge(V3_V1, V3_V1.getVertices());
+
+ return RC;
+ }
+
+ /**
+ * /--->\ v1 v2 \<---/
+ */
+ public DirectedGraph makeTwoCycle()
+ throws GraphException
+ {
+ DirectedGraphImpl RC = new DirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+
+ RC.addEdge(V1_V2, V1, V2);
+ RC.addEdge(V2_V1, V2, V1);
+
+ return RC;
+ }
+
+ /**
+ * v1 / ^ v \ v2 ---> v3
+ */
+ public DirectedGraph makeDirectedCycle()
+ throws GraphException
+ {
+ DirectedGraphImpl RC = new DirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+ RC.addVertex(V3);
+
+ RC.addEdge(V1_V2, V1, V2);
+ RC.addEdge(V2_V3, V2, V3);
+ RC.addEdge(V3_V1, V3, V1);
+
+ return RC;
+ }
+
+ /**
+ * v1 / ^ v \ v2 ---> v3
+ */
+ public DirectedGraph makeDirected4Cycle()
+ throws GraphException
+ {
+ DirectedGraphImpl RC = new DirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+ RC.addVertex(V3);
+ RC.addVertex(V4);
+
+ RC.addEdge(V1_V2, V1, V2);
+ RC.addEdge(V2_V3, V2, V3);
+ RC.addEdge(V3_V4, V3, V4);
+ RC.addEdge(V4_V1, V4, V1);
+
+ return RC;
+ }
+
+ /**
+ * v1--v2--v3 Three Vertices, Two Edges (No Cycle)
+ */
+ public UndirectedGraph makeNoCycle()
+ throws GraphException
+ {
+ UndirectedGraphImpl RC = new UndirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+ RC.addVertex(V3);
+
+ RC.addEdge(V1_V2, V1_V2.getVertices());
+ RC.addEdge(V2_V3, V2_V3.getVertices());
+
+ return RC;
+ }
+
+ /**
+ * v1 --> v2 --> v3
+ */
+ public DirectedGraph makePipe()
+ throws GraphException
+ {
+ DirectedGraphImpl RC = new DirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+ RC.addVertex(V3);
+
+ RC.addEdge(V1_V2, V1, V2);
+ RC.addEdge(V2_V3, V2, V3);
+
+ return RC;
+ }
+
+ /**
+ * v1 / \ v v v2 v3 \ / v v v4
+ */
+ public DirectedGraph makeDiamond()
+ throws GraphException
+ {
+ DirectedGraphImpl RC = new DirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+ RC.addVertex(V3);
+ RC.addVertex(V4);
+
+ RC.addEdge(V1_V2, V1, V2);
+ RC.addEdge(V1_V3, V1, V3);
+ RC.addEdge(V2_V4, V2, V4);
+ RC.addEdge(V3_V4, V3, V4);
+
+ return RC;
+ }
+
+ /**
+ * v1 / \ v v v2 v3 ^ ^ \ / v4
+ */
+ public DirectedGraph makePipelessCycle()
+ throws GraphException
+ {
+ DirectedGraphImpl RC = new DirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+ RC.addVertex(V3);
+ RC.addVertex(V4);
+
+ RC.addEdge(V1_V2, V1, V2);
+ RC.addEdge(V1_V3, V1, V3);
+ RC.addEdge(V4_V2, V4, V2);
+ RC.addEdge(V4_V3, V4, V3);
+
+ return RC;
+ }
+
+ /**
+ * v1 / \ v2 v3 5 Vertices, 4 Edges (Tree) / \ v4 v5
+ */
+ public UndirectedGraph makeTree()
+ throws GraphException
+ {
+ UndirectedGraphImpl RC = new UndirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+ RC.addVertex(V3);
+ RC.addVertex(V4);
+ RC.addVertex(V5);
+
+ RC.addEdge(V1_V2, V1_V2.getVertices());
+ RC.addEdge(V1_V3, V1_V3.getVertices());
+ RC.addEdge(V3_V4, V3_V4.getVertices());
+ RC.addEdge(V3_V5, V3_V5.getVertices());
+
+ return RC;
+ }
+
+ /**
+ * Description of the Method
+ */
+ public DirectedGraph makeParentTree()
+ throws GraphException
+ {
+ DirectedGraphImpl RC = new DirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+ RC.addVertex(V3);
+ RC.addVertex(V4);
+ RC.addVertex(V5);
+
+ RC.addEdge(V2_V1, V2, V1);
+ RC.addEdge(V3_V1, V3, V1);
+ RC.addEdge(V4_V3, V4, V3);
+ RC.addEdge(V5_V3, V5, V3);
+
+ return RC;
+ }
+
+ /**
+ * Description of the Method
+ */
+ public DirectedGraph makeChildTree()
+ throws GraphException
+ {
+ DirectedGraphImpl RC = new DirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+ RC.addVertex(V3);
+ RC.addVertex(V4);
+ RC.addVertex(V5);
+
+ RC.addEdge(V1_V2, V1, V2);
+ RC.addEdge(V1_V3, V1, V3);
+ RC.addEdge(V3_V4, V3, V4);
+ RC.addEdge(V3_V5, V3, V5);
+
+ return RC;
+ }
+
+ /**
+ * v1-v2 v3-v4 4 Vertices, 2 Edges (Disconnected)
+ */
+ public UndirectedGraph makeDisconnected()
+ throws GraphException
+ {
+ UndirectedGraphImpl RC = new UndirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+ RC.addVertex(V3);
+ RC.addVertex(V4);
+
+ RC.addEdge(V1_V2, V1_V2.getVertices());
+ RC.addEdge(V3_V4, V3_V4.getVertices());
+
+ return RC;
+ }
+
+ /**
+ * makeHyperEdgeGraph
+ *
+ * This makes a graph which has more than one Vertex on an Edge.
+ *
+ * V1
+ * |
+ * *
+ * / \
+ * V2 V3
+ *
+ */
+ public Graph makeHyperGraph() {
+ UndirectedGraphImpl RC = new UndirectedGraphImpl();
+
+ RC.addVertex( V1 );
+ RC.addVertex( V2 );
+ RC.addVertex( V3 );
+
+ RC.addEdge( V1_V2_V3 );
+ RC.connect( V1_V2_V3, V1 );
+ RC.connect( V1_V2_V3, V2 );
+ RC.connect( V1_V2_V3, V3 );
+
+ return RC;
+ }
+
+
+ /**
+ *
+ * V1 --> V2 --> V3 <--> V4
+ */
+ public DirectedGraph makeCycleNoReturn()
+ throws GraphException
+ {
+ DirectedGraphImpl RC = new DirectedGraphImpl();
+
+ RC.addVertex(V1);
+ RC.addVertex(V2);
+ RC.addVertex(V3);
+ RC.addVertex(V4);
+
+ RC.addEdge(V1_V2, V1, V2);
+ RC.addEdge(V2_V3, V2, V3);
+ RC.addEdge(V3_V4, V3, V4);
+ RC.addEdge(V4_V3, V4, V3);
+
+ return RC;
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testNothing()
+ throws Throwable { }
+
+ /**
+ * Description of the Method
+ */
+ public void verifyVertexEdgeCount(Graph IUT,
+ Vertex v,
+ int numEdge)
+ throws Throwable
+ {
+ assertEquals(v.toString() + " has wrong number of adjacent edges.",
+ IUT.getEdges(v).size(), numEdge);
+ }
+
+ /**
+ * Gets the outboundVertices attribute of the GraphTest object
+ */
+ private Set getOutboundVertices(DirectedGraph IUT,
+ Vertex v)
+ {
+ Set RC = new HashSet();
+ Iterator edges = IUT.getOutbound(v).iterator();
+
+ while (edges.hasNext())
+ {
+ Edge e = (Edge) edges.next();
+ RC.add(IUT.getTarget(e));
+ }
+
+ return RC;
+ }
+
+ /**
+ * Gets the inboundVertices attribute of the GraphTest object
+ */
+ private Set getInboundVertices(DirectedGraph IUT,
+ Vertex v)
+ {
+ Set RC = new HashSet();
+ Iterator edges = IUT.getInbound(v).iterator();
+
+ while (edges.hasNext())
+ {
+ Edge e = (Edge) edges.next();
+ RC.add(IUT.getSource(e));
+ }
+
+ return RC;
+ }
+
+
+ /**
+ * Gets the adjVertices attribute of the GraphTest object
+ */
+ private Set getAdjVertices(Graph IUT,
+ Vertex v)
+ {
+ Set RC = new HashSet();
+ Iterator edges = IUT.getEdges(v).iterator();
+
+ while (edges.hasNext())
+ {
+ Edge e = (Edge) edges.next();
+
+ Set verts = IUT.getVertices(e);
+ RC.addAll(verts);
+ }
+
+ return RC;
+ }
+
+ /**
+ * Description of the Method
+ */
+ public Set makeSet()
+ {
+ return new HashSet();
+ }
+
+
+ /**
+ * Description of the Method
+ */
+ public Set makeSet(Object v)
+ {
+ Set RC = new HashSet();
+ RC.add(v);
+ return RC;
+ }
+
+ /**
+ * Description of the Method
+ */
+ public Set makeSet(Object v1,
+ Object v2)
+ {
+ Set RC = makeSet(v1);
+ RC.add(v2);
+ return RC;
+ }
+
+ /**
+ * Description of the Method
+ */
+ public Set makeSet(Set s1,
+ Set s2)
+ {
+ Set RC = new HashSet();
+ RC.addAll(s1);
+ RC.addAll(s2);
+ return RC;
+ }
+
+ /**
+ * Description of the Method
+ */
+ public Set makeSet(Object v1,
+ Object v2,
+ Object v3)
+ {
+ return makeSet(makeSet(v1, v2),
+ makeSet(v3));
+ }
+
+ /**
+ * Description of the Method
+ */
+ public Set makeSet(Object v1,
+ Object v2,
+ Object v3,
+ Object v4)
+ {
+ return makeSet(makeSet(v1, v2),
+ makeSet(v3, v4));
+ }
+
+ /**
+ * Description of the Method
+ */
+ public void verifyAdjVertices(DirectedGraph IUT,
+ Vertex v,
+ Set inExpect,
+ Set outExpect)
+ {
+ Set inbound = getInboundVertices(IUT, v);
+ Set outbound = getOutboundVertices(IUT, v);
+
+ Iterator verts;
+
+ // inbound is a subset of inExpect
+ verts = inbound.iterator();
+
+ while (verts.hasNext())
+ {
+ Vertex curr = (Vertex) verts.next();
+
+ assertTrue(curr.toString() + " is not supposed to be " +
+ "next to " + v.toString(),
+ inExpect.contains(curr));
+ }
+
+ // inExpect is a subset of inbound
+ verts = inExpect.iterator();
+
+ while (verts.hasNext())
+ {
+ Vertex curr = (Vertex) verts.next();
+ assertTrue(curr.toString() + " is supposed to be next to " +
+ v.toString(),
+ inbound.contains(curr));
+ }
+
+ // outbound is a subset of outExpect
+ verts = outbound.iterator();
+
+ while (verts.hasNext())
+ {
+ Vertex curr = (Vertex) verts.next();
+
+ assertTrue(curr.toString() + " is not supposed to be " +
+ "next to " + v.toString(),
+ outExpect.contains(curr));
+ }
+
+ // outExpect is a subset of outbound
+ verts = outExpect.iterator();
+
+ while (verts.hasNext())
+ {
+ Vertex curr = (Vertex) verts.next();
+ assertTrue(curr.toString() + " is supposed to be next to " +
+ v.toString(),
+ outbound.contains(curr));
+ }
+
+ }
+
+ /**
+ * Description of the Method
+ */
+ public void verifyAdjVertices(Graph IUT,
+ Vertex v,
+ Set expected)
+ throws Throwable
+ {
+ Set adjacent = getAdjVertices(IUT, v);
+ Iterator adjV = adjacent.iterator();
+
+ while (adjV.hasNext())
+ {
+ Vertex curr = (Vertex) adjV.next();
+ assertTrue(curr.toString() + " is not supposed to be " +
+ "next to " + v.toString(),
+ expected.contains(curr));
+ }
+
+ Iterator expect = expected.iterator();
+
+ while (expect.hasNext())
+ {
+ Vertex curr = (Vertex) expect.next();
+ assertTrue(curr.toString() + " is supposed to be next to " +
+ v.toString(),
+ adjacent.contains(curr));
+ }
+ }
+
+ /**
+ * Description of the Method
+ */
+ public void verifyGraph(Graph g, int numVertex, int numEdge)
+ throws Throwable
+ {
+ assertEquals("Incorrect Number of Vertices.",
+ numVertex, g.getVertices().size());
+ assertEquals("Incorrect Number of Edges.",
+ numEdge, g.getEdges().size());
+ }
+
+ /**
+ * Description of the Method
+ */
+ public void printGraph(Throwable t,
+ DirectedGraph IUT)
+ {
+ System.err.println(testName + ": " + t.toString());
+ System.err.println("VERTICES: " + IUT.getVertices());
+ System.err.println("EDGES: " + IUT.getEdges());
+
+ Iterator verts = IUT.getVertices().iterator();
+ while (verts.hasNext())
+ {
+ Vertex vert = (Vertex) verts.next();
+ System.err.println("[ " + vert + " ]");
+
+ Iterator inbounds = IUT.getInbound(vert).iterator();
+ while (inbounds.hasNext())
+ {
+ Edge inbound = (Edge) inbounds.next();
+ System.err.println("\tI [" + inbound + "]");
+ }
+
+ Iterator outbounds = IUT.getOutbound(vert).iterator();
+ while (outbounds.hasNext())
+ {
+ Edge outbound = (Edge) outbounds.next();
+ System.err.println("\tO [" + outbound + "]");
+ }
+ }
+ }
+
+}
1.2 +379 -379 jakarta-commons-sandbox/graph2/src/test/org/apache/commons/graph/UndirGraphTest.java
Index: UndirGraphTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/graph2/src/test/org/apache/commons/graph/UndirGraphTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UndirGraphTest.java 17 Mar 2002 16:28:18 -0000 1.1
+++ UndirGraphTest.java 8 May 2002 18:24:47 -0000 1.2
@@ -1,379 +1,379 @@
-package org.apache.commons.graph;
-
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Commons" must not be used to endorse or promote products
- * derived from this software without prior written permission. For
- * written permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * "Commons", nor may "Apache" appear in their name, without
- * prior written permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-/**
- * GraphTest This test will ensure that we can indeed represent a graph. We will
- * implement the following graphs. () No Vertex, No Edges @ One Vertex, No Edges
- * @ @ Two Vertices, No Edges @-@ Two Vertices, One edge /-\ @ @ Two Vertices,
- * Two Edges (Parallel Edges) \-/ @ / \ Three Vertices, Three Edges (Cycle)
- * @---@ @--@--@ Three Vertices, Two Edges (No Cycle) @ / \ @ @ 5 Vertices, 4
- * Edges (Tree) / \ @ @ @-@ @-@ 4 Vertices, 2 Edges (Disconnected)
- */
-
-import java.util.Set;
-import java.util.Map;
-import java.util.HashSet;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import junit.framework.*;
-
-/**
- * Description of the Class
- */
-public class UndirGraphTest extends GraphTest
-{
- /**
- * Constructor for the UndirGraphTest object
- *
- * @param name
- */
- public UndirGraphTest(String name)
- {
- super(name);
- }
-
- /**
- * Test the NULL Graph.
- */
- public void testNullGraph()
- throws Throwable
- {
- verifyGraph(makeNullGraph(), 0, 0);
- }
-
-
- /**
- * Test the Single Vertex.
- */
- public void testSingleVertex()
- throws Throwable
- {
- verifyGraph(makeSingleVertex(), 1, 0);
- }
-
- /**
- * Tests Double Vertex graph.
- */
- public void testDoubleVertex()
- throws Throwable
- {
- verifyGraph(makeDoubleVertex(), 2, 0);
- }
-
- /**
- * Test Single Edge Graph.
- */
- public void testSingleEdge()
- throws Throwable
- {
- Graph IUT = makeSingleEdge();
-
- verifyGraph(IUT, 2, 1);
-
- // Verify Edge from Vertex Count
- verifyVertexEdgeCount(IUT, V1, 1);
- verifyVertexEdgeCount(IUT, V2, 1);
-
- Set expectV1 = new HashSet();
- expectV1.add(V2);
-
- verifyAdjVertices(IUT, V1, expectV1);
-
- Set expectV2 = new HashSet();
- expectV2.add(V1);
-
- verifyAdjVertices(IUT, V2, expectV2);
- }
-
- /**
- * Test Parallel Edges, make sure the representation is right.
- */
- public void testParallelEdges()
- throws Throwable
- {
- Graph IUT = makeParallelEdges();
-
- verifyGraph(IUT, 2, 2);
-
- // Verify Edge from Vertex Count
- verifyVertexEdgeCount(IUT, V1, 2);
- verifyVertexEdgeCount(IUT, V2, 2);
-
- // Verify Adjacent Vertex
- Set expectV1 = new HashSet();
- Set expectV2 = new HashSet();
-
- expectV1.add(V2);
- expectV2.add(V1);
-
- verifyAdjVertices(IUT, V1, expectV1);
- verifyAdjVertices(IUT, V2, expectV2);
-
- }
-
- /**
- * Test the Cycle Graph.
- */
- public void testCycle()
- throws Throwable
- {
- Graph IUT = makeCycle();
-
- verifyGraph(IUT, 3, 3);
-
- // Verify Edge from Vertex Count
- verifyVertexEdgeCount(IUT, V1, 2);
- verifyVertexEdgeCount(IUT, V2, 2);
- verifyVertexEdgeCount(IUT, V3, 2);
-
- // Verify Adjacent Vertex
- Set expectV1 = new HashSet();
- Set expectV2 = new HashSet();
- Set expectV3 = new HashSet();
-
- expectV1.add(V2);
- expectV1.add(V3);
- expectV2.add(V1);
- expectV2.add(V3);
- expectV3.add(V1);
- expectV3.add(V2);
-
- verifyAdjVertices(IUT, V1, expectV1);
- verifyAdjVertices(IUT, V2, expectV2);
- verifyAdjVertices(IUT, V3, expectV3);
- }
-
- /**
- * Test the No Cycle Graph.
- */
- public void testNoCycle()
- throws Throwable
- {
- Graph IUT = makeNoCycle();
-
- verifyGraph(IUT, 3, 2);
-
- // Verify Edge from Vertex Count
- verifyVertexEdgeCount(IUT, V1, 1);
- verifyVertexEdgeCount(IUT, V2, 2);
- verifyVertexEdgeCount(IUT, V3, 1);
-
- // Verify Adjacent Vertex
- Set expectV1 = new HashSet();
- Set expectV2 = new HashSet();
- Set expectV3 = new HashSet();
-
- expectV1.add(V2);
- expectV2.add(V1);
- expectV2.add(V3);
- expectV3.add(V2);
-
- verifyAdjVertices(IUT, V1, expectV1);
- verifyAdjVertices(IUT, V2, expectV2);
- verifyAdjVertices(IUT, V3, expectV3);
- }
-
- /**
- * Test the Tree Graph.
- */
- public void testTree()
- throws Throwable
- {
- Graph IUT = makeTree();
-
- verifyGraph(IUT, 5, 4);
-
- // Verify Edge from Vertex Count
- verifyVertexEdgeCount(IUT, V1, 2);
- verifyVertexEdgeCount(IUT, V2, 1);
- verifyVertexEdgeCount(IUT, V3, 3);
- verifyVertexEdgeCount(IUT, V4, 1);
- verifyVertexEdgeCount(IUT, V5, 1);
-
- // Verify Adjacent Vertex
- Set expectV1 = new HashSet();
- Set expectV2 = new HashSet();
- Set expectV3 = new HashSet();
- Set expectV4 = new HashSet();
- Set expectV5 = new HashSet();
-
- expectV1.add(V2);
- expectV1.add(V3);
- expectV2.add(V1);
- expectV3.add(V1);
- expectV3.add(V4);
- expectV3.add(V5);
- expectV4.add(V3);
- expectV5.add(V3);
-
- verifyAdjVertices(IUT, V1, expectV1);
- verifyAdjVertices(IUT, V2, expectV2);
- verifyAdjVertices(IUT, V3, expectV3);
- verifyAdjVertices(IUT, V4, expectV4);
- verifyAdjVertices(IUT, V5, expectV5);
- }
-
- /**
- * Test the Disconnected Graph.
- */
- public void testDisconnected()
- throws Throwable
- {
- Graph IUT = makeDisconnected();
-
- verifyGraph(IUT, 4, 2);
-
- // Verify Edge from Vertex Count
- verifyVertexEdgeCount(IUT, V1, 1);
- verifyVertexEdgeCount(IUT, V2, 1);
- verifyVertexEdgeCount(IUT, V3, 1);
- verifyVertexEdgeCount(IUT, V4, 1);
-
- // Verify Adjacent Vertex
- Set expectV1 = new HashSet();
- Set expectV2 = new HashSet();
- Set expectV3 = new HashSet();
- Set expectV4 = new HashSet();
-
- expectV1.add(V2);
- expectV2.add(V1);
- expectV3.add(V4);
- expectV4.add(V3);
-
- verifyAdjVertices(IUT, V1, expectV1);
- verifyAdjVertices(IUT, V2, expectV2);
- verifyAdjVertices(IUT, V3, expectV3);
- verifyAdjVertices(IUT, V4, expectV4);
- }
-
-
- /**
- * Description of the Method
- */
- public void verifyVertexEdgeCount(Graph IUT,
- Vertex v,
- int numEdge)
- throws Throwable
- {
- assertEquals(v.toString() + " has wrong number of adjacent edges.",
- IUT.getEdges(v).size(), numEdge);
- }
-
- /**
- * Gets the adjVertices attribute of the UndirGraphTest object
- */
- private Set getAdjVertices(Graph IUT,
- Vertex v)
- {
- Set RC = new HashSet();
- Iterator edges = IUT.getEdges(v).iterator();
-
- while (edges.hasNext())
- {
- Edge e = (Edge) edges.next();
-
- Set verts = IUT.getVertices(e);
- verts.remove(v);
- RC.addAll(verts);
- }
-
- return RC;
- }
-
- /**
- * Description of the Method
- */
- public void verifyAdjVertices(Graph IUT,
- Vertex v,
- Set expected)
- throws Throwable
- {
- Set adjacent = getAdjVertices(IUT, v);
- Iterator adjV = adjacent.iterator();
-
- while (adjV.hasNext())
- {
- Vertex curr = (Vertex) adjV.next();
-
- assertTrue(curr.toString() + " is not supposed to be " +
- "next to " + v.toString(),
- expected.contains(curr));
- }
-
- Iterator expect = expected.iterator();
-
- while (expect.hasNext())
- {
- Vertex curr = (Vertex) expect.next();
-
- assertTrue(curr.toString() + " is supposed to be next to " +
- v.toString(),
- adjacent.contains(curr));
- }
- }
-
- /**
- * Description of the Method
- */
- public void verifyGraph(Graph g, int numVertex, int numEdge)
- throws Throwable
- {
- assertEquals("Incorrect Number of Vertices.",
- g.getVertices().size(), numVertex);
- assertEquals("Incorrect Number of Edges.",
- g.getEdges().size(), numEdge);
- }
-}
+package org.apache.commons.graph;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Commons" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Commons", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+/**
+ * GraphTest This test will ensure that we can indeed represent a graph. We will
+ * implement the following graphs. () No Vertex, No Edges @ One Vertex, No Edges
+ * @ @ Two Vertices, No Edges @-@ Two Vertices, One edge /-\ @ @ Two Vertices,
+ * Two Edges (Parallel Edges) \-/ @ / \ Three Vertices, Three Edges (Cycle)
+ * @---@ @--@--@ Three Vertices, Two Edges (No Cycle) @ / \ @ @ 5 Vertices, 4
+ * Edges (Tree) / \ @ @ @-@ @-@ 4 Vertices, 2 Edges (Disconnected)
+ */
+
+import java.util.Set;
+import java.util.Map;
+import java.util.HashSet;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import junit.framework.*;
+
+/**
+ * Description of the Class
+ */
+public class UndirGraphTest extends GraphTest
+{
+ /**
+ * Constructor for the UndirGraphTest object
+ *
+ * @param name
+ */
+ public UndirGraphTest(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Test the NULL Graph.
+ */
+ public void testNullGraph()
+ throws Throwable
+ {
+ verifyGraph(makeNullGraph(), 0, 0);
+ }
+
+
+ /**
+ * Test the Single Vertex.
+ */
+ public void testSingleVertex()
+ throws Throwable
+ {
+ verifyGraph(makeSingleVertex(), 1, 0);
+ }
+
+ /**
+ * Tests Double Vertex graph.
+ */
+ public void testDoubleVertex()
+ throws Throwable
+ {
+ verifyGraph(makeDoubleVertex(), 2, 0);
+ }
+
+ /**
+ * Test Single Edge Graph.
+ */
+ public void testSingleEdge()
+ throws Throwable
+ {
+ Graph IUT = makeSingleEdge();
+
+ verifyGraph(IUT, 2, 1);
+
+ // Verify Edge from Vertex Count
+ verifyVertexEdgeCount(IUT, V1, 1);
+ verifyVertexEdgeCount(IUT, V2, 1);
+
+ Set expectV1 = new HashSet();
+ expectV1.add(V2);
+
+ verifyAdjVertices(IUT, V1, expectV1);
+
+ Set expectV2 = new HashSet();
+ expectV2.add(V1);
+
+ verifyAdjVertices(IUT, V2, expectV2);
+ }
+
+ /**
+ * Test Parallel Edges, make sure the representation is right.
+ */
+ public void testParallelEdges()
+ throws Throwable
+ {
+ Graph IUT = makeParallelEdges();
+
+ verifyGraph(IUT, 2, 2);
+
+ // Verify Edge from Vertex Count
+ verifyVertexEdgeCount(IUT, V1, 2);
+ verifyVertexEdgeCount(IUT, V2, 2);
+
+ // Verify Adjacent Vertex
+ Set expectV1 = new HashSet();
+ Set expectV2 = new HashSet();
+
+ expectV1.add(V2);
+ expectV2.add(V1);
+
+ verifyAdjVertices(IUT, V1, expectV1);
+ verifyAdjVertices(IUT, V2, expectV2);
+
+ }
+
+ /**
+ * Test the Cycle Graph.
+ */
+ public void testCycle()
+ throws Throwable
+ {
+ Graph IUT = makeCycle();
+
+ verifyGraph(IUT, 3, 3);
+
+ // Verify Edge from Vertex Count
+ verifyVertexEdgeCount(IUT, V1, 2);
+ verifyVertexEdgeCount(IUT, V2, 2);
+ verifyVertexEdgeCount(IUT, V3, 2);
+
+ // Verify Adjacent Vertex
+ Set expectV1 = new HashSet();
+ Set expectV2 = new HashSet();
+ Set expectV3 = new HashSet();
+
+ expectV1.add(V2);
+ expectV1.add(V3);
+ expectV2.add(V1);
+ expectV2.add(V3);
+ expectV3.add(V1);
+ expectV3.add(V2);
+
+ verifyAdjVertices(IUT, V1, expectV1);
+ verifyAdjVertices(IUT, V2, expectV2);
+ verifyAdjVertices(IUT, V3, expectV3);
+ }
+
+ /**
+ * Test the No Cycle Graph.
+ */
+ public void testNoCycle()
+ throws Throwable
+ {
+ Graph IUT = makeNoCycle();
+
+ verifyGraph(IUT, 3, 2);
+
+ // Verify Edge from Vertex Count
+ verifyVertexEdgeCount(IUT, V1, 1);
+ verifyVertexEdgeCount(IUT, V2, 2);
+ verifyVertexEdgeCount(IUT, V3, 1);
+
+ // Verify Adjacent Vertex
+ Set expectV1 = new HashSet();
+ Set expectV2 = new HashSet();
+ Set expectV3 = new HashSet();
+
+ expectV1.add(V2);
+ expectV2.add(V1);
+ expectV2.add(V3);
+ expectV3.add(V2);
+
+ verifyAdjVertices(IUT, V1, expectV1);
+ verifyAdjVertices(IUT, V2, expectV2);
+ verifyAdjVertices(IUT, V3, expectV3);
+ }
+
+ /**
+ * Test the Tree Graph.
+ */
+ public void testTree()
+ throws Throwable
+ {
+ Graph IUT = makeTree();
+
+ verifyGraph(IUT, 5, 4);
+
+ // Verify Edge from Vertex Count
+ verifyVertexEdgeCount(IUT, V1, 2);
+ verifyVertexEdgeCount(IUT, V2, 1);
+ verifyVertexEdgeCount(IUT, V3, 3);
+ verifyVertexEdgeCount(IUT, V4, 1);
+ verifyVertexEdgeCount(IUT, V5, 1);
+
+ // Verify Adjacent Vertex
+ Set expectV1 = new HashSet();
+ Set expectV2 = new HashSet();
+ Set expectV3 = new HashSet();
+ Set expectV4 = new HashSet();
+ Set expectV5 = new HashSet();
+
+ expectV1.add(V2);
+ expectV1.add(V3);
+ expectV2.add(V1);
+ expectV3.add(V1);
+ expectV3.add(V4);
+ expectV3.add(V5);
+ expectV4.add(V3);
+ expectV5.add(V3);
+
+ verifyAdjVertices(IUT, V1, expectV1);
+ verifyAdjVertices(IUT, V2, expectV2);
+ verifyAdjVertices(IUT, V3, expectV3);
+ verifyAdjVertices(IUT, V4, expectV4);
+ verifyAdjVertices(IUT, V5, expectV5);
+ }
+
+ /**
+ * Test the Disconnected Graph.
+ */
+ public void testDisconnected()
+ throws Throwable
+ {
+ Graph IUT = makeDisconnected();
+
+ verifyGraph(IUT, 4, 2);
+
+ // Verify Edge from Vertex Count
+ verifyVertexEdgeCount(IUT, V1, 1);
+ verifyVertexEdgeCount(IUT, V2, 1);
+ verifyVertexEdgeCount(IUT, V3, 1);
+ verifyVertexEdgeCount(IUT, V4, 1);
+
+ // Verify Adjacent Vertex
+ Set expectV1 = new HashSet();
+ Set expectV2 = new HashSet();
+ Set expectV3 = new HashSet();
+ Set expectV4 = new HashSet();
+
+ expectV1.add(V2);
+ expectV2.add(V1);
+ expectV3.add(V4);
+ expectV4.add(V3);
+
+ verifyAdjVertices(IUT, V1, expectV1);
+ verifyAdjVertices(IUT, V2, expectV2);
+ verifyAdjVertices(IUT, V3, expectV3);
+ verifyAdjVertices(IUT, V4, expectV4);
+ }
+
+
+ /**
+ * Description of the Method
+ */
+ public void verifyVertexEdgeCount(Graph IUT,
+ Vertex v,
+ int numEdge)
+ throws Throwable
+ {
+ assertEquals(v.toString() + " has wrong number of adjacent edges.",
+ IUT.getEdges(v).size(), numEdge);
+ }
+
+ /**
+ * Gets the adjVertices attribute of the UndirGraphTest object
+ */
+ private Set getAdjVertices(Graph IUT,
+ Vertex v)
+ {
+ Set RC = new HashSet();
+ Iterator edges = IUT.getEdges(v).iterator();
+
+ while (edges.hasNext())
+ {
+ Edge e = (Edge) edges.next();
+
+ Set verts = IUT.getVertices(e);
+ verts.remove(v);
+ RC.addAll(verts);
+ }
+
+ return RC;
+ }
+
+ /**
+ * Description of the Method
+ */
+ public void verifyAdjVertices(Graph IUT,
+ Vertex v,
+ Set expected)
+ throws Throwable
+ {
+ Set adjacent = getAdjVertices(IUT, v);
+ Iterator adjV = adjacent.iterator();
+
+ while (adjV.hasNext())
+ {
+ Vertex curr = (Vertex) adjV.next();
+
+ assertTrue(curr.toString() + " is not supposed to be " +
+ "next to " + v.toString(),
+ expected.contains(curr));
+ }
+
+ Iterator expect = expected.iterator();
+
+ while (expect.hasNext())
+ {
+ Vertex curr = (Vertex) expect.next();
+
+ assertTrue(curr.toString() + " is supposed to be next to " +
+ v.toString(),
+ adjacent.contains(curr));
+ }
+ }
+
+ /**
+ * Description of the Method
+ */
+ public void verifyGraph(Graph g, int numVertex, int numEdge)
+ throws Throwable
+ {
+ assertEquals("Incorrect Number of Vertices.",
+ g.getVertices().size(), numVertex);
+ assertEquals("Incorrect Number of Edges.",
+ g.getEdges().size(), numEdge);
+ }
+}
1.2 +573 -567 jakarta-commons-sandbox/graph2/src/test/org/apache/commons/graph/WeightedGraphTest.java
Index: WeightedGraphTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/graph2/src/test/org/apache/commons/graph/WeightedGraphTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WeightedGraphTest.java 17 Mar 2002 16:28:18 -0000 1.1
+++ WeightedGraphTest.java 8 May 2002 18:24:48 -0000 1.2
@@ -1,567 +1,573 @@
-package org.apache.commons.graph;
-
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Commons" must not be used to endorse or promote products
- * derived from this software without prior written permission. For
- * written permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * "Commons", nor may "Apache" appear in their name, without
- * prior written permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-/**
- * WeightedGraphTest This class will test Weighted Graphs, and make sure they
- * are possible.
- */
-
-import org.apache.commons.graph.impl.*;
-import org.apache.commons.graph.exception.*;
-
-/**
- * Description of the Class
- */
-public class WeightedGraphTest
- extends DirGraphTest
-{
- /**
- * Constructor for the WeightedGraphTest object
- *
- * @param name
- */
- public WeightedGraphTest(String name)
- {
- super(name);
- }
-
- /**
- * 5.0
- *
- * @---------> @
- */
- public DirectedGraphImpl makeWDirectedEdge()
- throws GraphException
- {
- DirectedGraphImpl RC =
- (DirectedGraphImpl) makeDirectedEdge();
- RC.setWeight(V1_V2, 5.0);
- return RC;
- }
-
- /**
- * A unit test for JUnit
- */
- public void testWDirectedEdge()
- throws Throwable
- {
- DirectedGraphImpl IUT = makeWDirectedEdge();
-
- verifyGraph(IUT, 2, 1);
- assertEquals("Wrong Weight on V1->V2",
- 5.0, IUT.getWeight(V1_V2), 0.00001);
- }
-
- /**
- * /----\ / 5.0 \ @ | \ / \----/
- */
- public DirectedGraphImpl makeWSelfLoop()
- throws GraphException
- {
- DirectedGraphImpl RC =
- (DirectedGraphImpl) makeSelfLoop();
- RC.setWeight(V1_V1, 5.0);
- return RC;
- }
-
- /**
- * A unit test for JUnit
- */
- public void testWSelfLoop()
- throws Throwable
- {
- DirectedGraphImpl IUT = makeWSelfLoop();
-
- verifyGraph(IUT, 1, 1);
- assertEquals("Wrong Weight on V1->V1",
- 5.0, IUT.getWeight(V1_V1), 0.00001);
- }
-
- /**
- * v1 / ^ 2.0 / \ 1.5 v \ v2------->v3 4.0
- */
- public DirectedGraphImpl makePositiveCycle()
- throws GraphException
- {
- DirectedGraphImpl RC =
- (DirectedGraphImpl) makeDirectedCycle();
-
- RC.setWeight(V1_V2, 2.0);
- RC.setWeight(V2_V3, 4.0);
- RC.setWeight(V3_V1, 1.5);
-
- return RC;
- }
-
- /**
- * A unit test for JUnit
- */
- public void testPositiveCycle()
- throws Throwable
- {
- DirectedGraphImpl IUT = makePositiveCycle();
- verifyGraph(IUT, 3, 3);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V1_V2), 2.0, 0.00001);
-
- assertEquals("Wrong Weight on V2->V3",
- IUT.getWeight(V2_V3), 4.0, 0.00001);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V3_V1), 1.5, 0.00001);
- }
-
- /**
- * v1 / ^ 2.0 / \ - 1.5 v \ v2------->v3 4.0
- */
- public DirectedGraphImpl makePositivePartNegCycle()
- throws GraphException
- {
- DirectedGraphImpl RC =
- (DirectedGraphImpl) makeDirectedCycle();
-
- RC.setWeight(V1_V2, 2.0);
- RC.setWeight(V2_V3, 4.0);
- RC.setWeight(V3_V1, -1.5);
-
- return RC;
- }
-
- /**
- * A unit test for JUnit
- */
- public void testPositivePartNegCycle()
- throws Throwable
- {
- DirectedGraphImpl IUT = makePositivePartNegCycle();
- verifyGraph(IUT, 3, 3);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V1_V2), 2.0, 0.00001);
-
- assertEquals("Wrong Weight on V2->V3",
- IUT.getWeight(V2_V3), 4.0, 0.00001);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V3_V1), -1.5, 0.00001);
- }
-
- /**
- * v1 / ^ - 2.0 / \ - 1.5 v \ v2------->v3 - 4.0
- */
- public DirectedGraphImpl makeNegativeCycle()
- throws GraphException
- {
- DirectedGraphImpl RC =
- (DirectedGraphImpl) makeDirectedCycle();
-
- RC.setWeight(V1_V2, -2.0);
- RC.setWeight(V2_V3, -4.0);
- RC.setWeight(V3_V1, -1.5);
-
- return RC;
- }
-
- /**
- * A unit test for JUnit
- */
- public void testNegativeCycle()
- throws Throwable
- {
- DirectedGraphImpl IUT = makeNegativeCycle();
- verifyGraph(IUT, 3, 3);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V1_V2), -2.0, 0.00001);
-
- assertEquals("Wrong Weight on V2->V3",
- IUT.getWeight(V2_V3), -4.0, 0.00001);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V3_V1), -1.5, 0.00001);
- }
-
- /**
- * v1 / ^ - 2.0 / \ 1.5 v \ v2------->v3 - 4.0
- */
- public DirectedGraphImpl makeNegativePartPosCycle()
- throws GraphException
- {
- DirectedGraphImpl RC =
- (DirectedGraphImpl) makeDirectedCycle();
-
- RC.setWeight(V1_V2, -2.0);
- RC.setWeight(V2_V3, -4.0);
- RC.setWeight(V3_V1, 1.5);
-
- return RC;
- }
-
- /**
- * A unit test for JUnit
- */
- public void testNegativePartPosCycle()
- throws Throwable
- {
- DirectedGraphImpl IUT = makeNegativePartPosCycle();
- verifyGraph(IUT, 3, 3);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V1_V2), -2.0, 0.00001);
-
- assertEquals("Wrong Weight on V2->V3",
- IUT.getWeight(V2_V3), -4.0, 0.00001);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V3_V1), 1.5, 0.00001);
- }
-
- /**
- * 1.5 3.5 v1 ---> v2 --->v3
- */
- public DirectedGraphImpl makePositivePipe()
- throws GraphException
- {
- DirectedGraphImpl RC =
- (DirectedGraphImpl) makePipe();
-
- RC.setWeight(V1_V2, 1.5);
- RC.setWeight(V2_V3, 3.5);
-
- return RC;
- }
-
- /**
- * A unit test for JUnit
- */
- public void testPositivePipe()
- throws Throwable
- {
- DirectedGraphImpl IUT = makePositivePipe();
- verifyGraph(IUT, 3, 2);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V1_V2), 1.5, 0.00001);
-
- assertEquals("Wrong Weight on V2->V3",
- IUT.getWeight(V2_V3), 3.5, 0.00001);
- }
-
- /**
- * -1.5 3.5 v1 ---> v2 --->v3
- */
- public DirectedGraphImpl makePositivePartNegPipe()
- throws GraphException
- {
- DirectedGraphImpl RC =
- (DirectedGraphImpl) makePipe();
-
- RC.setWeight(V1_V2, -1.5);
- RC.setWeight(V2_V3, 3.5);
-
- return RC;
- }
-
- /**
- * A unit test for JUnit
- */
- public void testPositivePartNegPipe()
- throws Throwable
- {
- DirectedGraphImpl IUT = makePositivePartNegPipe();
- verifyGraph(IUT, 3, 2);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V1_V2), -1.5, 0.00001);
-
- assertEquals("Wrong Weight on V2->V3",
- IUT.getWeight(V2_V3), 3.5, 0.00001);
- }
-
-
- /**
- * -1.5 -3.5 v1 ---> v2 --->v3
- */
- public DirectedGraphImpl makeNegativePipe()
- throws GraphException
- {
- DirectedGraphImpl RC =
- (DirectedGraphImpl) makePipe();
-
- RC.setWeight(V1_V2, -1.5);
- RC.setWeight(V2_V3, -3.5);
-
- return RC;
- }
-
- /**
- * A unit test for JUnit
- */
- public void testNegativePipe()
- throws Throwable
- {
- DirectedGraphImpl IUT = makeNegativePipe();
- verifyGraph(IUT, 3, 2);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V1_V2), -1.5, 0.0001);
-
- assertEquals("Wrong Weight on V2->V3",
- IUT.getWeight(V2_V3), -3.5, 0.0001);
- }
-
- /**
- * 1.5 -3.5 v1 ---> v2 --->v3
- */
- public DirectedGraphImpl makeNegativePartPosPipe()
- throws GraphException
- {
- DirectedGraphImpl RC =
- (DirectedGraphImpl) makePipe();
-
- RC.setWeight(V1_V2, 1.5);
- RC.setWeight(V2_V3, -3.5);
-
- return RC;
- }
-
- /**
- * A unit test for JUnit
- */
- public void testNegativePartPosPipe()
- throws Throwable
- {
- DirectedGraphImpl IUT = makeNegativePartPosPipe();
- verifyGraph(IUT, 3, 2);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V1_V2), 1.5, 0.0001);
-
- assertEquals("Wrong Weight on V2->V3",
- IUT.getWeight(V2_V3), -3.5, 0.0001);
- }
-
-
- /**
- * v1 1.5 / \ 2.5 v v v2 v3 1.5 \ / 2.5 vv v4
- */
-
- public DirectedGraphImpl makeMultiplePathL()
- throws GraphException
- {
- DirectedGraphImpl RC =
- (DirectedGraphImpl) makeDiamond();
-
- RC.setWeight(V1_V2, 1.5);
- RC.setWeight(V2_V4, 1.5);
-
- RC.setWeight(V1_V3, 2.5);
- RC.setWeight(V3_V4, 2.5);
-
- return RC;
- }
-
- /**
- * A unit test for JUnit
- */
- public void testMultiplePathL()
- throws Throwable
- {
- DirectedGraphImpl IUT = makeMultiplePathL();
- verifyGraph(IUT, 4, 4);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V1_V2), 1.5, 0.0001);
-
- assertEquals("Wrong Weight on V2->V4",
- IUT.getWeight(V2_V4), 1.5, 0.0001);
-
- assertEquals("Wrong Weight on V1->V3",
- IUT.getWeight(V1_V3), 2.5, 0.0001);
-
- assertEquals("Wrong Weight on V3->V4",
- IUT.getWeight(V3_V4), 2.5, 0.0001);
- }
-
-
- /**
- * v1 2.5 / \ 1.5 v v v2 v3 2.5 \ / 1.5 vv v4
- */
-
- public DirectedGraphImpl makeMultiplePathR()
- throws GraphException
- {
- DirectedGraphImpl RC =
- (DirectedGraphImpl) makeDiamond();
-
- RC.setWeight(V1_V2, 2.5);
- RC.setWeight(V2_V4, 2.5);
-
- RC.setWeight(V1_V3, 1.5);
- RC.setWeight(V3_V4, 1.5);
-
- return RC;
- }
-
- /**
- * A unit test for JUnit
- */
- public void testMultiplePathR()
- throws Throwable
- {
- DirectedGraphImpl IUT = makeMultiplePathR();
- verifyGraph(IUT, 4, 4);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V1_V2), 2.5, 0.0001);
-
- assertEquals("Wrong Weight on V2->V4",
- IUT.getWeight(V2_V4), 2.5, 0.0001);
-
- assertEquals("Wrong Weight on V1->V3",
- IUT.getWeight(V1_V3), 1.5, 0.0001);
-
- assertEquals("Wrong Weight on V3->V4",
- IUT.getWeight(V3_V4), 1.5, 0.0001);
- }
-
-
- /**
- * v1 10.0 / \ 0.5 v v v2 v3 10.0 \ / 10.5 vv v4
- */
-
- public DirectedGraphImpl makeMultiplePathEarlyLow()
- throws GraphException
- {
- DirectedGraphImpl RC =
- (DirectedGraphImpl) makeDiamond();
-
- RC.setWeight(V1_V2, 10.0);
- RC.setWeight(V2_V4, 10.0);
-
- RC.setWeight(V1_V3, 0.5);
- RC.setWeight(V3_V4, 10.5);
-
- return RC;
- }
-
- /**
- * A unit test for JUnit
- */
- public void testMultiplePathEarlyLow()
- throws Throwable
- {
- DirectedGraphImpl IUT = makeMultiplePathEarlyLow();
- verifyGraph(IUT, 4, 4);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V1_V2), 10.0, 0.0001);
-
- assertEquals("Wrong Weight on V2->V4",
- IUT.getWeight(V2_V4), 10.0, 0.0001);
-
- assertEquals("Wrong Weight on V1->V3",
- IUT.getWeight(V1_V3), 0.5, 0.0001);
-
- assertEquals("Wrong Weight on V3->V4",
- IUT.getWeight(V3_V4), 10.5, 0.0001);
- }
-
-
- /**
- * v1 10.0 / \ 10.5 v v v2 v3 10.0 \ / 0.5 vv v4
- */
-
- public DirectedGraphImpl makeMultiplePathEarlyHigh()
- throws GraphException
- {
- DirectedGraphImpl RC =
- (DirectedGraphImpl) makeDiamond();
-
- RC.setWeight(V1_V2, 10.0);
- RC.setWeight(V2_V4, 10.0);
-
- RC.setWeight(V1_V3, 10.5);
- RC.setWeight(V3_V4, 0.5);
-
- return RC;
- }
-
-
- /**
- * A unit test for JUnit
- */
- public void testMultiplePathEarlyHigh()
- throws Throwable
- {
- DirectedGraphImpl IUT = makeMultiplePathEarlyHigh();
- verifyGraph(IUT, 4, 4);
-
- assertEquals("Wrong Weight on V1->V2",
- IUT.getWeight(V1_V2), 10.0, 0.0001);
-
- assertEquals("Wrong Weight on V2->V4",
- IUT.getWeight(V2_V4), 10.0, 0.0001);
-
- assertEquals("Wrong Weight on V1->V3",
- IUT.getWeight(V1_V3), 10.5, 0.0001);
-
- assertEquals("Wrong Weight on V3->V4",
- IUT.getWeight(V3_V4), 0.5, 0.0001);
- }
-
-}
+package org.apache.commons.graph;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Commons" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Commons", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+/**
+ * WeightedGraphTest This class will test Weighted Graphs, and make sure they
+ * are possible.
+ */
+
+import org.apache.commons.graph.domain.basic.*;
+import org.apache.commons.graph.exception.*;
+
+/**
+ * Description of the Class
+ */
+public class WeightedGraphTest
+ extends DirGraphTest
+{
+ /**
+ * Constructor for the WeightedGraphTest object
+ *
+ * @param name
+ */
+ public WeightedGraphTest(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * 5.0
+ *
+ * @---------> @
+ */
+ public DirectedGraphImpl makeWDirectedEdge()
+ throws GraphException
+ {
+ DirectedGraphImpl RC =
+ (DirectedGraphImpl) makeDirectedEdge();
+ RC.setWeight(V1_V2, 5.0);
+ return RC;
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testWDirectedEdge()
+ throws Throwable
+ {
+ DirectedGraphImpl IUT = makeWDirectedEdge();
+
+ verifyGraph(IUT, 2, 1);
+ assertEquals("Wrong Weight on V1->V2",
+ 5.0, IUT.getWeight(V1_V2), 0.00001);
+ }
+
+ /**
+ * /----\ / 5.0 \ @ | \ / \----/
+ */
+ public DirectedGraphImpl makeWSelfLoop()
+ throws GraphException
+ {
+ DirectedGraphImpl RC =
+ (DirectedGraphImpl) makeSelfLoop();
+ RC.setWeight(V1_V1, 5.0);
+ return RC;
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testWSelfLoop()
+ throws Throwable
+ {
+ DirectedGraphImpl IUT = makeWSelfLoop();
+
+ verifyGraph(IUT, 1, 1);
+ assertEquals("Wrong Weight on V1->V1",
+ 5.0, IUT.getWeight(V1_V1), 0.00001);
+ }
+
+ /**
+ * v1 / ^ 2.0 / \ 1.5 v \ v2------->v3 4.0
+ */
+ public DirectedGraphImpl makePositiveCycle()
+ throws GraphException
+ {
+ DirectedGraphImpl RC =
+ (DirectedGraphImpl) makeDirectedCycle();
+
+ RC.setWeight(V1_V2, 2.0);
+ RC.setWeight(V2_V3, 4.0);
+ RC.setWeight(V3_V1, 1.5);
+
+ return RC;
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testPositiveCycle()
+ throws Throwable
+ {
+ DirectedGraphImpl IUT = makePositiveCycle();
+ verifyGraph(IUT, 3, 3);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V1_V2), 2.0, 0.00001);
+
+ assertEquals("Wrong Weight on V2->V3",
+ IUT.getWeight(V2_V3), 4.0, 0.00001);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V3_V1), 1.5, 0.00001);
+ }
+
+ /**
+ * v1 / ^ 2.0 / \ - 1.5 v \ v2------->v3 4.0
+ */
+ public DirectedGraphImpl makePositivePartNegCycle()
+ throws GraphException
+ {
+ DirectedGraphImpl RC =
+ (DirectedGraphImpl) makeDirectedCycle();
+
+ RC.setWeight(V1_V2, 2.0);
+ RC.setWeight(V2_V3, 4.0);
+ RC.setWeight(V3_V1, -1.5);
+
+ return RC;
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testPositivePartNegCycle()
+ throws Throwable
+ {
+ DirectedGraphImpl IUT = makePositivePartNegCycle();
+ verifyGraph(IUT, 3, 3);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V1_V2), 2.0, 0.00001);
+
+ assertEquals("Wrong Weight on V2->V3",
+ IUT.getWeight(V2_V3), 4.0, 0.00001);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V3_V1), -1.5, 0.00001);
+ }
+
+ /**
+ * v1 / ^ - 2.0 / \ - 1.5 v \ v2------->v3 - 4.0
+ */
+ public DirectedGraphImpl makeNegativeCycle()
+ throws GraphException
+ {
+ DirectedGraphImpl RC =
+ (DirectedGraphImpl) makeDirectedCycle();
+
+ RC.setWeight(V1_V2, -2.0);
+ RC.setWeight(V2_V3, -4.0);
+ RC.setWeight(V3_V1, -1.5);
+
+ return RC;
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testNegativeCycle()
+ throws Throwable
+ {
+ DirectedGraphImpl IUT = makeNegativeCycle();
+ verifyGraph(IUT, 3, 3);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V1_V2), -2.0, 0.00001);
+
+ assertEquals("Wrong Weight on V2->V3",
+ IUT.getWeight(V2_V3), -4.0, 0.00001);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V3_V1), -1.5, 0.00001);
+ }
+
+ /**
+ * v1 / ^ - 2.0 / \ 1.5 v \ v2------->v3 - 4.0
+ */
+ public DirectedGraphImpl makeNegativePartPosCycle()
+ throws GraphException
+ {
+ DirectedGraphImpl RC =
+ (DirectedGraphImpl) makeDirectedCycle();
+
+ RC.setWeight(V1_V2, -2.0);
+ RC.setWeight(V2_V3, -4.0);
+ RC.setWeight(V3_V1, 1.5);
+
+ return RC;
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testNegativePartPosCycle()
+ throws Throwable
+ {
+ DirectedGraphImpl IUT = makeNegativePartPosCycle();
+ verifyGraph(IUT, 3, 3);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V1_V2), -2.0, 0.00001);
+
+ assertEquals("Wrong Weight on V2->V3",
+ IUT.getWeight(V2_V3), -4.0, 0.00001);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V3_V1), 1.5, 0.00001);
+ }
+
+ /**
+ * 1.5 3.5 v1 ---> v2 --->v3
+ */
+ public DirectedGraphImpl makePositivePipe()
+ throws GraphException
+ {
+ DirectedGraphImpl RC =
+ (DirectedGraphImpl) makePipe();
+
+ RC.setWeight(V1_V2, 1.5);
+ RC.setWeight(V2_V3, 3.5);
+
+ return RC;
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testPositivePipe()
+ throws Throwable
+ {
+ DirectedGraphImpl IUT = makePositivePipe();
+ verifyGraph(IUT, 3, 2);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V1_V2), 1.5, 0.00001);
+
+ assertEquals("Wrong Weight on V2->V3",
+ IUT.getWeight(V2_V3), 3.5, 0.00001);
+ }
+
+ /**
+ * -1.5 3.5 v1 ---> v2 --->v3
+ */
+ public DirectedGraphImpl makePositivePartNegPipe()
+ throws GraphException
+ {
+ DirectedGraphImpl RC =
+ (DirectedGraphImpl) makePipe();
+
+ RC.setWeight(V1_V2, -1.5);
+ RC.setWeight(V2_V3, 3.5);
+
+ return RC;
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testPositivePartNegPipe()
+ throws Throwable
+ {
+ DirectedGraphImpl IUT = makePositivePartNegPipe();
+ verifyGraph(IUT, 3, 2);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V1_V2), -1.5, 0.00001);
+
+ assertEquals("Wrong Weight on V2->V3",
+ IUT.getWeight(V2_V3), 3.5, 0.00001);
+ }
+
+
+ /**
+ * -1.5 -3.5 v1 ---> v2 --->v3
+ */
+ public DirectedGraphImpl makeNegativePipe()
+ throws GraphException
+ {
+ DirectedGraphImpl RC =
+ (DirectedGraphImpl) makePipe();
+
+ RC.setWeight(V1_V2, -1.5);
+ RC.setWeight(V2_V3, -3.5);
+
+ return RC;
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testNegativePipe()
+ throws Throwable
+ {
+ DirectedGraphImpl IUT = makeNegativePipe();
+ verifyGraph(IUT, 3, 2);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V1_V2), -1.5, 0.0001);
+
+ assertEquals("Wrong Weight on V2->V3",
+ IUT.getWeight(V2_V3), -3.5, 0.0001);
+ }
+
+ /**
+ * 1.5 -3.5 v1 ---> v2 --->v3
+ */
+ public DirectedGraphImpl makeNegativePartPosPipe()
+ throws GraphException
+ {
+ DirectedGraphImpl RC =
+ (DirectedGraphImpl) makePipe();
+
+ RC.setWeight(V1_V2, 1.5);
+ RC.setWeight(V2_V3, -3.5);
+
+ return RC;
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testNegativePartPosPipe()
+ throws Throwable
+ {
+ DirectedGraphImpl IUT = makeNegativePartPosPipe();
+ verifyGraph(IUT, 3, 2);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V1_V2), 1.5, 0.0001);
+
+ assertEquals("Wrong Weight on V2->V3",
+ IUT.getWeight(V2_V3), -3.5, 0.0001);
+ }
+
+
+ /**
+ * v1 1.5 / \ 2.5 v v v2 v3 1.5 \ / 2.5 vv v4
+ */
+
+ public DirectedGraphImpl makeMultiplePathL()
+ throws GraphException
+ {
+ DirectedGraphImpl RC =
+ (DirectedGraphImpl) makeDiamond();
+
+ RC.setWeight(V1_V2, 1.5);
+ RC.setWeight(V2_V4, 1.5);
+
+ RC.setWeight(V1_V3, 2.5);
+ RC.setWeight(V3_V4, 3.5);
+
+ return RC;
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testMultiplePathL()
+ throws Throwable
+ {
+ DirectedGraphImpl IUT = makeMultiplePathL();
+ verifyGraph(IUT, 4, 4);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V1_V2), 1.5, 0.0001);
+
+ assertEquals("Wrong Weight on V2->V4",
+ IUT.getWeight(V2_V4), 1.5, 0.0001);
+
+ assertEquals("Wrong Weight on V1->V3",
+ IUT.getWeight(V1_V3), 2.5, 0.0001);
+
+ assertEquals("Wrong Weight on V3->V4",
+ IUT.getWeight(V3_V4), 3.5, 0.0001);
+ }
+
+
+ /**
+ * v1 2.5 / \ 1.5 v v v2 v3 2.5 \ / 1.5 vv v4
+ */
+
+ public DirectedGraphImpl makeMultiplePathR()
+ throws GraphException
+ {
+ DirectedGraphImpl RC =
+ (DirectedGraphImpl) makeDiamond();
+
+ RC.setWeight(V1_V2, 3.5);
+ RC.setWeight(V2_V4, 2.5);
+
+ RC.setWeight(V1_V3, 1.5);
+ RC.setWeight(V3_V4, 1.5);
+
+ return RC;
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testMultiplePathR()
+ throws Throwable
+ {
+ DirectedGraphImpl IUT = makeMultiplePathR();
+ verifyGraph(IUT, 4, 4);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V1_V2), 3.5, 0.0001);
+
+ assertEquals("Wrong Weight on V2->V4",
+ IUT.getWeight(V2_V4), 2.5, 0.0001);
+
+ assertEquals("Wrong Weight on V1->V3",
+ IUT.getWeight(V1_V3), 1.5, 0.0001);
+
+ assertEquals("Wrong Weight on V3->V4",
+ IUT.getWeight(V3_V4), 1.5, 0.0001);
+ }
+
+
+ /**
+ * v1 10.0 / \ 0.5 v v v2 v3 10.0 \ / 10.5 vv v4
+ */
+
+ public DirectedGraphImpl makeMultiplePathEarlyLow()
+ throws GraphException
+ {
+ DirectedGraphImpl RC =
+ (DirectedGraphImpl) makeDiamond();
+
+ RC.setWeight(V1_V2, 10.0);
+ RC.setWeight(V2_V4, 10.0);
+
+ RC.setWeight(V1_V3, 0.5);
+ RC.setWeight(V3_V4, 10.5);
+
+ return RC;
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testMultiplePathEarlyLow()
+ throws Throwable
+ {
+ DirectedGraphImpl IUT = makeMultiplePathEarlyLow();
+ verifyGraph(IUT, 4, 4);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V1_V2), 10.0, 0.0001);
+
+ assertEquals("Wrong Weight on V2->V4",
+ IUT.getWeight(V2_V4), 10.0, 0.0001);
+
+ assertEquals("Wrong Weight on V1->V3",
+ IUT.getWeight(V1_V3), 0.5, 0.0001);
+
+ assertEquals("Wrong Weight on V3->V4",
+ IUT.getWeight(V3_V4), 10.5, 0.0001);
+ }
+
+
+ /**
+ * v1 10.0 / \ 10.5 v v v2 v3 10.0 \ / 0.5 vv v4
+ */
+
+ public DirectedGraphImpl makeMultiplePathEarlyHigh()
+ throws GraphException
+ {
+ DirectedGraphImpl RC =
+ (DirectedGraphImpl) makeDiamond();
+
+ RC.setWeight(V1_V2, 10.0);
+ RC.setWeight(V2_V4, 10.0);
+
+ RC.setWeight(V1_V3, 10.5);
+ RC.setWeight(V3_V4, 0.5);
+
+ return RC;
+ }
+
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testMultiplePathEarlyHigh()
+ throws Throwable
+ {
+ DirectedGraphImpl IUT = makeMultiplePathEarlyHigh();
+ verifyGraph(IUT, 4, 4);
+
+ assertEquals("Wrong Weight on V1->V2",
+ IUT.getWeight(V1_V2), 10.0, 0.0001);
+
+ assertEquals("Wrong Weight on V2->V4",
+ IUT.getWeight(V2_V4), 10.0, 0.0001);
+
+ assertEquals("Wrong Weight on V1->V3",
+ IUT.getWeight(V1_V3), 10.5, 0.0001);
+
+ assertEquals("Wrong Weight on V3->V4",
+ IUT.getWeight(V3_V4), 0.5, 0.0001);
+ }
+
+}
+
+
+
+
+
+
1.2 +461 -461 jakarta-commons-sandbox/graph2/src/test/org/apache/commons/graph/contract/AcyclicContractTest.java
Index: AcyclicContractTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/graph2/src/test/org/apache/commons/graph/contract/AcyclicContractTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AcyclicContractTest.java 17 Mar 2002 16:28:19 -0000 1.1
+++ AcyclicContractTest.java 8 May 2002 18:24:48 -0000 1.2
@@ -1,461 +1,461 @@
-package org.apache.commons.graph.contract;
-
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Commons" must not be used to endorse or promote products
- * derived from this software without prior written permission. For
- * written permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * "Commons", nor may "Apache" appear in their name, without
- * prior written permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-import org.apache.commons.graph.*;
-import org.apache.commons.graph.exception.*;
-
-/**
- * Description of the Class
- */
-public class AcyclicContractTest
- extends GraphTest
-{
- /**
- * Constructor for the AcyclicContractTest object
- *
- * @param name
- */
- public AcyclicContractTest(String name)
- {
- super(name);
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDirNullGraph()
- throws Throwable
- {
- AcyclicContract IUT =
- new AcyclicContract();
- IUT.setImpl(makeDirNullGraph());
-
- IUT.verify();
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDirSingleVertex()
- throws Throwable
- {
- AcyclicContract IUT =
- new AcyclicContract();
- IUT.setImpl(makeDirSingleVertex());
- IUT.verify();
-
- try
- {
- IUT.addEdge(V1_V1, V1, V1);
- fail("No GraphException thrown when Self-Cycle introduced.");
- }
- catch (CycleException ex)
- {}
- }
-
- /**
- * A unit test for JUnit
- */
- public void testSelfLoop()
- throws Throwable
- {
- AcyclicContract IUT =
- new AcyclicContract();
- IUT.setImpl(makeSelfLoop());
-
- try
- {
- IUT.verify();
- fail("No CycleException thrown on Verification.");
- }
- catch (CycleException ex)
- {}
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDirDoubleVertex()
- throws Throwable
- {
- AcyclicContract IUT =
- new AcyclicContract();
- IUT.setImpl(makeDirDoubleVertex());
- IUT.verify();
-
- try
- {
- IUT.addEdge(V1_V1, V1, V1);
- fail("No GraphException thrown when Self-Cycle introduced.");
- }
- catch (CycleException ex)
- {}
-
- try
- {
- IUT.addEdge(V1_V2, V1, V2);
- }
- catch (GraphException ex)
- {
- fail("Contract prevented adding of valid edge. V1->V2");
- }
- }
-
-
- /**
- * A unit test for JUnit
- */
- public void testDirectedEdge()
- throws Throwable
- {
- AcyclicContract IUT =
- new AcyclicContract();
- IUT.setImpl(makeDirectedEdge());
- IUT.verify();
-
- try
- {
- IUT.addEdge(V1_V1, V1, V1);
- fail("No GraphException thrown when Self-Cycle introduced.");
- }
- catch (CycleException ex)
- {}
-
- try
- {
- IUT.addEdge(V1_V2_, V1, V2);
- }
- catch (GraphException ex)
- {
- fail("Contract prevented adding of valid edge. V1->V2'");
- }
-
- try
- {
- IUT.addEdge(V2_V1, V2, V1);
- fail("Contract allowed cycle to be introduced.");
- }
- catch (CycleException ex)
- {}
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDirParallelEdges()
- throws Throwable
- {
- AcyclicContract IUT =
- new AcyclicContract();
- IUT.setImpl(makeDirParallelEdges());
- IUT.verify();
-
- try
- {
- IUT.addEdge(V1_V1, V1, V1);
- fail("No GraphException thrown when Self-Cycle introduced.");
- }
- catch (CycleException ex)
- {}
-
- try
- {
- IUT.addEdge(V1_V2__, V1, V2);
- }
- catch (GraphException ex)
- {
- fail("Contract prevented adding of valid edge. V1->V2'");
- }
-
- try
- {
- IUT.addEdge(V2_V1, V2, V1);
- fail("Contract allowed cycle to be introduced.");
- }
- catch (CycleException ex)
- {}
- }
-
-
- /**
- * A unit test for JUnit
- */
- public void testTwoCycle()
- throws Throwable
- {
- AcyclicContract IUT =
- new AcyclicContract();
- IUT.setImpl(makeTwoCycle());
-
- try
- {
- IUT.verify();
- fail("No CycleException thrown on Verification.");
- }
- catch (CycleException ex)
- {}
- }
-
-
- /**
- * A unit test for JUnit
- */
- public void testDirectedCycle()
- throws Throwable
- {
- AcyclicContract IUT =
- new AcyclicContract();
- IUT.setImpl(makeDirectedCycle());
-
- try
- {
- IUT.verify();
- fail("No CycleException thrown on Verification.");
- }
- catch (CycleException ex)
- {}
- }
-
- /**
- * A unit test for JUnit
- */
- public void testPipe()
- throws Throwable
- {
- AcyclicContract IUT =
- new AcyclicContract();
- IUT.setImpl(makePipe());
- IUT.verify();
-
- try
- {
- IUT.addEdge(V1_V1, V1, V1);
- fail("No GraphException thrown when Self-Cycle introduced.");
- }
- catch (CycleException ex)
- {}
-
- try
- {
- IUT.addEdge(V1_V2_, V1, V2);
- }
- catch (GraphException ex)
- {
- fail("Contract prevented adding of valid edge. V1->V2'");
- }
-
- try
- {
- IUT.addEdge(V3_V1, V3, V1);
- fail("Contract allowed cycle to be introduced.");
- }
- catch (CycleException ex)
- {}
-
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDiamond()
- throws Throwable
- {
- AcyclicContract IUT =
- new AcyclicContract();
- IUT.setImpl(makeDiamond());
- IUT.verify();
-
- try
- {
- IUT.addEdge(V1_V1, V1, V1);
- fail("No GraphException thrown when Self-Cycle introduced.");
- }
- catch (CycleException ex)
- {}
-
- try
- {
- IUT.addEdge(V2_V3, V2, V3);
- }
- catch (GraphException ex)
- {
- fail("Contract prevented adding of valid edge. V2->V3");
- }
-
- try
- {
- IUT.addEdge(V4_V1, V4, V1);
- fail("Contract allowed cycle to be introduced.");
- }
- catch (CycleException ex)
- {}
- }
-
- /**
- * A unit test for JUnit
- */
- public void testPipelessCycle()
- throws Throwable
- {
- AcyclicContract IUT =
- new AcyclicContract();
- IUT.setImpl(makePipelessCycle());
- IUT.verify();
-
- try
- {
- IUT.addEdge(V1_V1, V1, V1);
- fail("No GraphException thrown when Self-Cycle introduced.");
- }
- catch (CycleException ex)
- {}
-
- try
- {
- IUT.addEdge(V2_V3, V2, V3);
- }
- catch (GraphException ex)
- {
- fail("Contract prevented adding of valid edge. V2->V3");
- }
-
- try
- {
- IUT.addEdge(V3_V4, V3, V4);
- fail("Contract allowed cycle to be introduced.");
- }
- catch (CycleException ex)
- {}
-
- }
-
-
- /**
- * A unit test for JUnit
- */
- public void testParentTree()
- throws Throwable
- {
- System.err.println("---- PARENT TREE ----");
- AcyclicContract IUT =
- new AcyclicContract();
- IUT.setImpl(makeParentTree());
- IUT.verify();
-
- try
- {
- IUT.addEdge(V1_V1, V1, V1);
- fail("No GraphException thrown when Self-Cycle introduced.");
- }
- catch (CycleException ex)
- {}
-
- try
- {
- IUT.addEdge(V2_V3, V2, V3);
- }
- catch (GraphException ex)
- {
- fail("Contract prevented adding of valid edge. V2->V3");
- }
-
- try
- {
- IUT.addEdge(V1_V5, V1, V5);
- fail("Contract allowed cycle to be introduced.");
- }
- catch (CycleException ex)
- {}
- }
-
-
- /**
- * A unit test for JUnit
- */
- public void testChildTree()
- throws Throwable
- {
- AcyclicContract IUT =
- new AcyclicContract();
- IUT.setImpl(makeChildTree());
- IUT.verify();
-
- try
- {
- IUT.addEdge(V1_V1, V1, V1);
- fail("No GraphException thrown when Self-Cycle introduced.");
- }
- catch (CycleException ex)
- {}
-
- try
- {
- IUT.addEdge(V2_V3, V2, V3);
- }
- catch (GraphException ex)
- {
- fail("Contract prevented adding of valid edge. V2->V3");
- }
-
- try
- {
- IUT.addEdge(V5_V1, V5, V1);
- fail("Contract allowed cycle to be introduced.");
- }
- catch (CycleException ex)
- {}
-
- }
-}
+package org.apache.commons.graph.contract;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Commons" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Commons", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+import org.apache.commons.graph.*;
+import org.apache.commons.graph.exception.*;
+
+/**
+ * Description of the Class
+ */
+public class AcyclicContractTest
+ extends GraphTest
+{
+ /**
+ * Constructor for the AcyclicContractTest object
+ *
+ * @param name
+ */
+ public AcyclicContractTest(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDirNullGraph()
+ throws Throwable
+ {
+ AcyclicContract IUT =
+ new AcyclicContract();
+ IUT.setImpl(makeDirNullGraph());
+
+ IUT.verify();
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDirSingleVertex()
+ throws Throwable
+ {
+ AcyclicContract IUT =
+ new AcyclicContract();
+ IUT.setImpl(makeDirSingleVertex());
+ IUT.verify();
+
+ try
+ {
+ IUT.addEdge(V1_V1, V1, V1);
+ fail("No GraphException thrown when Self-Cycle introduced.");
+ }
+ catch (CycleException ex)
+ {}
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testSelfLoop()
+ throws Throwable
+ {
+ AcyclicContract IUT =
+ new AcyclicContract();
+ IUT.setImpl(makeSelfLoop());
+
+ try
+ {
+ IUT.verify();
+ fail("No CycleException thrown on Verification.");
+ }
+ catch (CycleException ex)
+ {}
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDirDoubleVertex()
+ throws Throwable
+ {
+ AcyclicContract IUT =
+ new AcyclicContract();
+ IUT.setImpl(makeDirDoubleVertex());
+ IUT.verify();
+
+ try
+ {
+ IUT.addEdge(V1_V1, V1, V1);
+ fail("No GraphException thrown when Self-Cycle introduced.");
+ }
+ catch (CycleException ex)
+ {}
+
+ try
+ {
+ IUT.addEdge(V1_V2, V1, V2);
+ }
+ catch (GraphException ex)
+ {
+ fail("Contract prevented adding of valid edge. V1->V2");
+ }
+ }
+
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDirectedEdge()
+ throws Throwable
+ {
+ AcyclicContract IUT =
+ new AcyclicContract();
+ IUT.setImpl(makeDirectedEdge());
+ IUT.verify();
+
+ try
+ {
+ IUT.addEdge(V1_V1, V1, V1);
+ fail("No GraphException thrown when Self-Cycle introduced.");
+ }
+ catch (CycleException ex)
+ {}
+
+ try
+ {
+ IUT.addEdge(V1_V2_, V1, V2);
+ }
+ catch (GraphException ex)
+ {
+ fail("Contract prevented adding of valid edge. V1->V2'");
+ }
+
+ try
+ {
+ IUT.addEdge(V2_V1, V2, V1);
+ fail("Contract allowed cycle to be introduced.");
+ }
+ catch (CycleException ex)
+ {}
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDirParallelEdges()
+ throws Throwable
+ {
+ AcyclicContract IUT =
+ new AcyclicContract();
+ IUT.setImpl(makeDirParallelEdges());
+ IUT.verify();
+
+ try
+ {
+ IUT.addEdge(V1_V1, V1, V1);
+ fail("No GraphException thrown when Self-Cycle introduced.");
+ }
+ catch (CycleException ex)
+ {}
+
+ try
+ {
+ IUT.addEdge(V1_V2__, V1, V2);
+ }
+ catch (GraphException ex)
+ {
+ fail("Contract prevented adding of valid edge. V1->V2'");
+ }
+
+ try
+ {
+ IUT.addEdge(V2_V1, V2, V1);
+ fail("Contract allowed cycle to be introduced.");
+ }
+ catch (CycleException ex)
+ {}
+ }
+
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testTwoCycle()
+ throws Throwable
+ {
+ AcyclicContract IUT =
+ new AcyclicContract();
+ IUT.setImpl(makeTwoCycle());
+
+ try
+ {
+ IUT.verify();
+ fail("No CycleException thrown on Verification.");
+ }
+ catch (CycleException ex)
+ {}
+ }
+
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDirectedCycle()
+ throws Throwable
+ {
+ AcyclicContract IUT =
+ new AcyclicContract();
+ IUT.setImpl(makeDirectedCycle());
+
+ try
+ {
+ IUT.verify();
+ fail("No CycleException thrown on Verification.");
+ }
+ catch (CycleException ex)
+ {}
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testPipe()
+ throws Throwable
+ {
+ AcyclicContract IUT =
+ new AcyclicContract();
+ IUT.setImpl(makePipe());
+ IUT.verify();
+
+ try
+ {
+ IUT.addEdge(V1_V1, V1, V1);
+ fail("No GraphException thrown when Self-Cycle introduced.");
+ }
+ catch (CycleException ex)
+ {}
+
+ try
+ {
+ IUT.addEdge(V1_V2_, V1, V2);
+ }
+ catch (GraphException ex)
+ {
+ fail("Contract prevented adding of valid edge. V1->V2'");
+ }
+
+ try
+ {
+ IUT.addEdge(V3_V1, V3, V1);
+ fail("Contract allowed cycle to be introduced.");
+ }
+ catch (CycleException ex)
+ {}
+
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDiamond()
+ throws Throwable
+ {
+ AcyclicContract IUT =
+ new AcyclicContract();
+ IUT.setImpl(makeDiamond());
+ IUT.verify();
+
+ try
+ {
+ IUT.addEdge(V1_V1, V1, V1);
+ fail("No GraphException thrown when Self-Cycle introduced.");
+ }
+ catch (CycleException ex)
+ {}
+
+ try
+ {
+ IUT.addEdge(V2_V3, V2, V3);
+ }
+ catch (GraphException ex)
+ {
+ fail("Contract prevented adding of valid edge. V2->V3");
+ }
+
+ try
+ {
+ IUT.addEdge(V4_V1, V4, V1);
+ fail("Contract allowed cycle to be introduced.");
+ }
+ catch (CycleException ex)
+ {}
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testPipelessCycle()
+ throws Throwable
+ {
+ AcyclicContract IUT =
+ new AcyclicContract();
+ IUT.setImpl(makePipelessCycle());
+ IUT.verify();
+
+ try
+ {
+ IUT.addEdge(V1_V1, V1, V1);
+ fail("No GraphException thrown when Self-Cycle introduced.");
+ }
+ catch (CycleException ex)
+ {}
+
+ try
+ {
+ IUT.addEdge(V2_V3, V2, V3);
+ }
+ catch (GraphException ex)
+ {
+ fail("Contract prevented adding of valid edge. V2->V3");
+ }
+
+ try
+ {
+ IUT.addEdge(V3_V4, V3, V4);
+ fail("Contract allowed cycle to be introduced.");
+ }
+ catch (CycleException ex)
+ {}
+
+ }
+
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testParentTree()
+ throws Throwable
+ {
+ System.err.println("---- PARENT TREE ----");
+ AcyclicContract IUT =
+ new AcyclicContract();
+ IUT.setImpl(makeParentTree());
+ IUT.verify();
+
+ try
+ {
+ IUT.addEdge(V1_V1, V1, V1);
+ fail("No GraphException thrown when Self-Cycle introduced.");
+ }
+ catch (CycleException ex)
+ {}
+
+ try
+ {
+ IUT.addEdge(V2_V3, V2, V3);
+ }
+ catch (GraphException ex)
+ {
+ fail("Contract prevented adding of valid edge. V2->V3");
+ }
+
+ try
+ {
+ IUT.addEdge(V1_V5, V1, V5);
+ fail("Contract allowed cycle to be introduced.");
+ }
+ catch (CycleException ex)
+ {}
+ }
+
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testChildTree()
+ throws Throwable
+ {
+ AcyclicContract IUT =
+ new AcyclicContract();
+ IUT.setImpl(makeChildTree());
+ IUT.verify();
+
+ try
+ {
+ IUT.addEdge(V1_V1, V1, V1);
+ fail("No GraphException thrown when Self-Cycle introduced.");
+ }
+ catch (CycleException ex)
+ {}
+
+ try
+ {
+ IUT.addEdge(V2_V3, V2, V3);
+ }
+ catch (GraphException ex)
+ {
+ fail("Contract prevented adding of valid edge. V2->V3");
+ }
+
+ try
+ {
+ IUT.addEdge(V5_V1, V5, V1);
+ fail("Contract allowed cycle to be introduced.");
+ }
+ catch (CycleException ex)
+ {}
+
+ }
+}
1.2 +275 -275 jakarta-commons-sandbox/graph2/src/test/org/apache/commons/graph/contract/DAGTest.java
Index: DAGTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/graph2/src/test/org/apache/commons/graph/contract/DAGTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DAGTest.java 17 Mar 2002 16:28:19 -0000 1.1
+++ DAGTest.java 8 May 2002 18:24:48 -0000 1.2
@@ -1,275 +1,275 @@
-package org.apache.commons.graph.contract;
-
-/**
- * DAGTest This test looks to verify that yes indeed contracts are being called
- * when created through the GraphFactory.
- */
-
-import org.apache.commons.graph.*;
-import org.apache.commons.graph.impl.*;
-import org.apache.commons.graph.contract.*;
-import org.apache.commons.graph.exception.*;
-
-/**
- * Description of the Class
- */
-public class DAGTest
- extends GraphTest
-{
- private Contract[] dagContracts = new Contract[1];
- private GraphFactory factory = new GraphFactory();
- private String testName = null;
-
- /**
- * Constructor for the DAGTest object
- *
- * @param name
- */
- public DAGTest(String name)
- {
- super(name);
- this.testName = name;
- }
-
- /**
- * The JUnit setup method
- */
- public void setUp()
- {
- dagContracts[0] = new AcyclicContract();
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDAGSelfLoop()
- throws Throwable
- {
- DirectedGraph dg = null;
- try
- {
- try
- {
- dg = factory.makeDirectedGraph(dagContracts,
- true,
- makeSelfLoop());
- fail("Should not have created DAG.");
- }
- catch (CycleException ex)
- {}
- }
- catch (Throwable ex)
- {
- printGraph(ex, dg);
- throw ex;
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDAGTwoLoop()
- throws Throwable
- {
- DirectedGraph dg = null;
- try
- {
- try
- {
- dg = factory.makeDirectedGraph(dagContracts,
- true,
- makeTwoCycle());
- fail("Should not have created DAG.");
- }
- catch (CycleException ex)
- {}
- }
- catch (Throwable ex)
- {
- printGraph(ex, dg);
- throw ex;
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testMakeDAGDirCycle()
- throws Throwable
- {
- MutableDirectedGraph mdg = null;
- try
- {
- mdg = factory.makeMutableDirectedGraph(dagContracts,
- true,
- null);
- mdg.addVertex(V1);
- mdg.addVertex(V2);
- mdg.addEdge(V1_V2, V1, V2);
-
- mdg.addVertex(V3);
- mdg.addEdge(V2_V3, V2, V3);
-
- try
- {
- mdg.addEdge(V3_V1, V3, V1);
- fail("No CycleException thrown on introduction of cycle.");
- }
- catch (CycleException ex)
- {}
- }
- catch (Throwable t)
- {
- printGraph(t, mdg);
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDAGDirCycle()
- throws Throwable
- {
- DirectedGraph dg = null;
- try
- {
- try
- {
- dg = factory.makeDirectedGraph(dagContracts,
- true,
- makeDirectedCycle());
- fail("Should not have created DAG.");
- }
- catch (CycleException ex)
- {}
- }
- catch (Throwable ex)
- {
- printGraph(ex, dg);
- throw ex;
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDAGAddCycleToPipe()
- throws Throwable
- {
- MutableDirectedGraph mdg = null;
- try
- {
- try
- {
- mdg = factory.makeMutableDirectedGraph(dagContracts,
- true,
- makePipe());
- mdg.addEdge(V3_V1, V3, V1);
- fail("No Exception thrown on adding of invalid edge.");
- }
- catch (CycleException e)
- {}
- }
- catch (Throwable ex)
- {
- printGraph(ex, mdg);
- throw ex;
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDAGAddCycleToDirEdge()
- throws Throwable
- {
- MutableDirectedGraph mdg = null;
- try
- {
- try
- {
- mdg = factory.makeMutableDirectedGraph(dagContracts,
- true,
- makeDirectedEdge());
- mdg.addEdge(V2_V1, V2, V1);
- fail("Failed to throw exception on introducing Cycle.");
- }
- catch (CycleException ex)
- {}
- }
- catch (Throwable ex)
- {
- printGraph(ex, mdg);
- throw ex;
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDAGAddSelfLoop()
- throws Throwable
- {
- MutableDirectedGraph mdg = null;
- try
- {
- try
- {
- mdg = factory.makeMutableDirectedGraph(dagContracts,
- true,
- makeDirSingleVertex());
- mdg.addEdge(V1_V1, V1, V1);
- fail("Failed to throw exception on introducing Self Loop.");
- }
- catch (CycleException ex)
- {}
- }
- catch (Throwable ex)
- {
- printGraph(ex, mdg);
- throw ex;
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDAGValidEdge()
- throws Throwable
- {
- MutableDirectedGraph mdg = null;
- try
- {
- mdg = factory.makeMutableDirectedGraph(dagContracts,
- true,
- makeParentTree());
- mdg.addEdge(V2_V3, V2, V3);
- }
- catch (Throwable ex)
- {
- printGraph(ex, mdg);
- throw ex;
- }
- }
-
- /**
- * A unit test for JUnit
- */
- public void testDAGValidEdge2()
- throws Throwable
- {
- MutableDirectedGraph mdg = null;
- try
- {
- mdg = factory.makeMutableDirectedGraph(dagContracts,
- true,
- makeDirDoubleVertex());
- mdg.addEdge(V1_V2, V1, V2);
- }
- catch (Throwable ex)
- {
- printGraph(ex, mdg);
- throw ex;
- }
- }
-}
+package org.apache.commons.graph.contract;
+
+/**
+ * DAGTest This test looks to verify that yes indeed contracts are being called
+ * when created through the GraphFactory.
+ */
+
+import org.apache.commons.graph.*;
+import org.apache.commons.graph.contract.*;
+import org.apache.commons.graph.exception.*;
+import org.apache.commons.graph.factory.*;
+
+/**
+ * Description of the Class
+ */
+public class DAGTest
+ extends GraphTest
+{
+ private Contract[] dagContracts = new Contract[1];
+ private GraphFactory factory = new GraphFactory();
+ private String testName = null;
+
+ /**
+ * Constructor for the DAGTest object
+ *
+ * @param name
+ */
+ public DAGTest(String name)
+ {
+ super(name);
+ this.testName = name;
+ }
+
+ /**
+ * The JUnit setup method
+ */
+ public void setUp()
+ {
+ dagContracts[0] = new AcyclicContract();
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDAGSelfLoop()
+ throws Throwable
+ {
+ DirectedGraph dg = null;
+ try
+ {
+ try
+ {
+ dg = factory.makeDirectedGraph(dagContracts,
+ true,
+ makeSelfLoop());
+ fail("Should not have created DAG.");
+ }
+ catch (CycleException ex)
+ {}
+ }
+ catch (Throwable ex)
+ {
+ printGraph(ex, dg);
+ throw ex;
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDAGTwoLoop()
+ throws Throwable
+ {
+ DirectedGraph dg = null;
+ try
+ {
+ try
+ {
+ dg = factory.makeDirectedGraph(dagContracts,
+ true,
+ makeTwoCycle());
+ fail("Should not have created DAG.");
+ }
+ catch (CycleException ex)
+ {}
+ }
+ catch (Throwable ex)
+ {
+ printGraph(ex, dg);
+ throw ex;
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testMakeDAGDirCycle()
+ throws Throwable
+ {
+ MutableDirectedGraph mdg = null;
+ try
+ {
+ mdg = factory.makeMutableDirectedGraph(dagContracts,
+ true,
+ null);
+ mdg.addVertex(V1);
+ mdg.addVertex(V2);
+ mdg.addEdge(V1_V2, V1, V2);
+
+ mdg.addVertex(V3);
+ mdg.addEdge(V2_V3, V2, V3);
+
+ try
+ {
+ mdg.addEdge(V3_V1, V3, V1);
+ fail("No CycleException thrown on introduction of cycle.");
+ }
+ catch (CycleException ex)
+ {}
+ }
+ catch (Throwable t)
+ {
+ printGraph(t, mdg);
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDAGDirCycle()
+ throws Throwable
+ {
+ DirectedGraph dg = null;
+ try
+ {
+ try
+ {
+ dg = factory.makeDirectedGraph(dagContracts,
+ true,
+ makeDirectedCycle());
+ fail("Should not have created DAG.");
+ }
+ catch (CycleException ex)
+ {}
+ }
+ catch (Throwable ex)
+ {
+ printGraph(ex, dg);
+ throw ex;
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDAGAddCycleToPipe()
+ throws Throwable
+ {
+ MutableDirectedGraph mdg = null;
+ try
+ {
+ try
+ {
+ mdg = factory.makeMutableDirectedGraph(dagContracts,
+ true,
+ makePipe());
+ mdg.addEdge(V3_V1, V3, V1);
+ fail("No Exception thrown on adding of invalid edge.");
+ }
+ catch (CycleException e)
+ {}
+ }
+ catch (Throwable ex)
+ {
+ printGraph(ex, mdg);
+ throw ex;
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDAGAddCycleToDirEdge()
+ throws Throwable
+ {
+ MutableDirectedGraph mdg = null;
+ try
+ {
+ try
+ {
+ mdg = factory.makeMutableDirectedGraph(dagContracts,
+ true,
+ makeDirectedEdge());
+ mdg.addEdge(V2_V1, V2, V1);
+ fail("Failed to throw exception on introducing Cycle.");
+ }
+ catch (CycleException ex)
+ {}
+ }
+ catch (Throwable ex)
+ {
+ printGraph(ex, mdg);
+ throw ex;
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDAGAddSelfLoop()
+ throws Throwable
+ {
+ MutableDirectedGraph mdg = null;
+ try
+ {
+ try
+ {
+ mdg = factory.makeMutableDirectedGraph(dagContracts,
+ true,
+ makeDirSingleVertex());
+ mdg.addEdge(V1_V1, V1, V1);
+ fail("Failed to throw exception on introducing Self Loop.");
+ }
+ catch (CycleException ex)
+ {}
+ }
+ catch (Throwable ex)
+ {
+ printGraph(ex, mdg);
+ throw ex;
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDAGValidEdge()
+ throws Throwable
+ {
+ MutableDirectedGraph mdg = null;
+ try
+ {
+ mdg = factory.makeMutableDirectedGraph(dagContracts,
+ true,
+ makeParentTree());
+ mdg.addEdge(V2_V3, V2, V3);
+ }
+ catch (Throwable ex)
+ {
+ printGraph(ex, mdg);
+ throw ex;
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ */
+ public void testDAGValidEdge2()
+ throws Throwable
+ {
+ MutableDirectedGraph mdg = null;
+ try
+ {
+ mdg = factory.makeMutableDirectedGraph(dagContracts,
+ true,
+ makeDirDoubleVertex());
+ mdg.addEdge(V1_V2, V1, V2);
+ }
+ catch (Throwable ex)
+ {
+ printGraph(ex, mdg);
+ throw ex;
+ }
+ }
+}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>