KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgrapht > graph > CloneTest


1 /* ==========================================
2  * JGraphT : a free Java graph-theory library
3  * ==========================================
4  *
5  * Project Info: http://jgrapht.sourceforge.net/
6  * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
7  *
8  * (C) Copyright 2003-2006, by Barak Naveh and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this library; if not, write to the Free Software Foundation,
22  * Inc.,
23  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
24  */

25 /* --------------
26  * CloneTest.java
27  * --------------
28  * (C) Copyright 2003-2006, by John V. Sichi and Contributors.
29  *
30  * Original Author: John V. Sichi
31  * Contributor(s): -
32  *
33  * $Id: CloneTest.java 504 2006-07-03 02:37:26Z perfecthash $
34  *
35  * Changes
36  * -------
37  * 06-Oct-2003 : Initial revision (JVS);
38  *
39  */

40 package org.jgrapht.graph;
41
42 import org.jgrapht.*;
43
44
45 /**
46  * A unit test for a cloning bug, adapted from a forum entry from Linda Buisman.
47  *
48  * @author John V. Sichi
49  * @since Oct 6, 2003
50  */

51 public class CloneTest
52     extends EnhancedTestCase
53 {
54
55     //~ Constructors ----------------------------------------------------------
56

57     /**
58      * @see junit.framework.TestCase#TestCase(java.lang.String)
59      */

60     public CloneTest(String JavaDoc name)
61     {
62         super(name);
63     }
64
65     //~ Methods ---------------------------------------------------------------
66

67     /**
68      * Test graph cloning.
69      */

70     @SuppressWarnings JavaDoc("unchecked")
71     public void testCloneSpecificsBug()
72     {
73         SimpleGraph<String JavaDoc, DefaultEdge> g1 =
74             new SimpleGraph<String JavaDoc, DefaultEdge>(DefaultEdge.class);
75         String JavaDoc one = "1";
76         String JavaDoc two = "2";
77         String JavaDoc three = "3";
78         g1.addVertex(one);
79         g1.addVertex(two);
80         g1.addVertex(three);
81         g1.addEdge(one, two);
82         g1.addEdge(two, three);
83
84         SimpleGraph<String JavaDoc, DefaultEdge> g2 =
85             (SimpleGraph<String JavaDoc, DefaultEdge>) g1.clone(); // Type-safty
86
// warning OK with
87
// clone
88
assertEquals(2, g2.edgeSet().size());
89         assertNotNull(g2.getEdge(one, two));
90         assertTrue(g2.removeEdge(g2.getEdge(one, two)));
91         assertNotNull(g2.removeEdge("2", "3"));
92         assertTrue(g2.edgeSet().isEmpty());
93     }
94 }
95
Popular Tags