001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.util;
017:
018: // JUnit dependencies
019: import junit.framework.Test;
020: import junit.framework.TestCase;
021: import junit.framework.TestSuite;
022:
023: /**
024: * Test the {@link RangeSet} implementation.
025: *
026: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/test/java/org/geotools/util/RangeSetTest.java $
027: * @version $Id: RangeSetTest.java 27848 2007-11-12 13:10:32Z desruisseaux $
028: * @author Andrea Aime
029: */
030: public final class RangeSetTest extends TestCase {
031: /**
032: * Run the suit from the command line.
033: */
034: public static void main(final String[] args) {
035: org.geotools.util.logging.Logging.GEOTOOLS
036: .forceMonolineConsoleOutput();
037: junit.textui.TestRunner.run(suite());
038: }
039:
040: /**
041: * Returns the test suite.
042: */
043: public static Test suite() {
044: return new TestSuite(RangeSetTest.class);
045: }
046:
047: /**
048: * Constructs a test case with the given name.
049: */
050: public RangeSetTest(final String name) {
051: super (name);
052: }
053:
054: /**
055: * Test {@link RangeSet#remove}.
056: */
057: public void testRangeRemoval() {
058: RangeSet rs = new RangeSet(Double.class);
059: rs.add(10.0, 22.0);
060: rs.remove(8.0, 12.0);
061: RangeSet rsResult = new RangeSet(Double.class);
062: rsResult.add(12.0, 22.0);
063: assertEquals("Lower removal:", rs, rsResult);
064:
065: rs.remove(20.0, 30.0);
066: rsResult = new RangeSet(Double.class);
067: rsResult.add(12.0, 20.0);
068: assertEquals("Upper removal:", rs, rsResult);
069:
070: rs.remove(8.0, 10.0);
071: assertEquals("Inferior null removal:", rs, rsResult);
072: rs.remove(8.0, 12.0);
073: assertEquals("Inferior touch removal:", rs, rsResult);
074:
075: rs.remove(22.0, 40.0);
076: assertEquals("Upper null removal:", rs, rsResult);
077: rs.remove(20.0, 40.0);
078: assertEquals("Upper touch removal:", rs, rsResult);
079:
080: rs.remove(14.0, 16.0);
081: rsResult = new RangeSet(Double.class);
082: rsResult.add(12.0, 14.0);
083: rsResult.add(16.0, 20.0);
084: assertEquals("Central removal:", rs, rsResult);
085:
086: rs.remove(15.0, 15.5);
087: assertEquals("Central null removal:", rs, rsResult);
088:
089: rs.remove(14.0, 16.0);
090: assertEquals("Central touch null removal:", rs, rsResult);
091:
092: rs.remove(15.0, 17.0);
093: rsResult = new RangeSet(Double.class);
094: rsResult.add(12.0, 14.0);
095: rsResult.add(17.0, 20.0);
096: assertEquals("Central right removal:", rs, rsResult);
097:
098: rs.remove(13.0, 15.0);
099: rsResult = new RangeSet(Double.class);
100: rsResult.add(12.0, 13.0);
101: rsResult.add(17.0, 20.0);
102: assertEquals("Central left removal:", rs, rsResult);
103:
104: rs.remove(12.5, 18.0);
105: rsResult = new RangeSet(Double.class);
106: rsResult.add(12.0, 12.5);
107: rsResult.add(18.0, 20.0);
108: assertEquals("Central both removal:", rs, rsResult);
109:
110: rs.remove(18.5, 19.0);
111: rsResult = new RangeSet(Double.class);
112: rsResult.add(12.0, 12.5);
113: rsResult.add(18.0, 18.5);
114: rsResult.add(19.0, 20.0);
115: assertEquals("Central removal 2:", rs, rsResult);
116:
117: rs.remove(17.0, 19.0);
118: rsResult = new RangeSet(Double.class);
119: rsResult.add(12.0, 12.5);
120: rsResult.add(19.0, 20.0);
121: assertEquals("Central wipeout:", rs, rsResult);
122:
123: rs.remove(0.0, 25.0);
124: assertEquals("Full wipeout:", 0, rs.size());
125: }
126: }
|