01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
05: * (C) 2001, Institut de Recherche pour le Développement
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: */
17: package org.geotools.util;
18:
19: // J2SE dependencies
20: import java.util.Arrays;
21: import java.util.Collections;
22: import java.util.HashSet;
23:
24: import junit.framework.Test;
25: import junit.framework.TestCase;
26: import junit.framework.TestSuite;
27:
28: /**
29: * Test the {@link DisjointSet} class.
30: *
31: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/test/java/org/geotools/util/DisjointSetTest.java $
32: * @version $Id: DisjointSetTest.java 27848 2007-11-12 13:10:32Z desruisseaux $
33: * @author Martin Desruisseaux
34: */
35: public final class DisjointSetTest extends TestCase {
36: /**
37: * Run the suit from the command line.
38: */
39: public static void main(final String[] args) {
40: org.geotools.util.logging.Logging.GEOTOOLS
41: .forceMonolineConsoleOutput();
42: junit.textui.TestRunner.run(suite());
43: }
44:
45: /**
46: * Returns the test suite.
47: */
48: public static Test suite() {
49: return new TestSuite(DisjointSetTest.class);
50: }
51:
52: /**
53: * Constructs a test case with the given name.
54: */
55: public DisjointSetTest(final String name) {
56: super (name);
57: }
58:
59: /**
60: * Test the set.
61: */
62: public void testDisjointSet() {
63: DisjointSet t1 = new DisjointSet(true);
64: DisjointSet t2 = new DisjointSet(t1);
65: DisjointSet t3 = new DisjointSet(t2);
66:
67: assertNotNull(t1.getTrash());
68: assertSame(t1.getTrash(), t2.getTrash());
69: assertSame(t2.getTrash(), t3.getTrash());
70:
71: assertTrue(t1.add("alpha"));
72: assertTrue(t2.add("bęta"));
73: assertTrue(t3.add("gamma"));
74: assertTrue(t2.add("delta"));
75: assertTrue(t1.add("epsilon"));
76: assertTrue(t2.add("alpha"));
77: assertTrue(t2.remove("bęta"));
78:
79: assertEquals(Collections.singleton("epsilon"), t1);
80: assertEquals(new HashSet(Arrays.asList(new String[] { "alpha",
81: "delta" })), t2);
82: assertEquals(Collections.singleton("gamma"), t3);
83: assertEquals(Collections.singleton("bęta"), t1.getTrash());
84: }
85: }
|