001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-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.filter.function;
017:
018: import java.util.Arrays;
019: import org.geotools.filter.Expression;
020: import org.geotools.filter.FilterFactoryFinder;
021: import org.geotools.filter.FunctionExpression;
022:
023: /**
024: * Tests UniqueIntervalFunction
025: *
026: * @author Cory Horner
027: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/test/java/org/geotools/filter/function/UniqueIntervalFunctionTest.java $
028: */
029: public class UniqueIntervalFunctionTest extends FunctionTestSupport {
030: public UniqueIntervalFunctionTest(String testName) {
031: super (testName);
032: }
033:
034: protected void tearDown() throws java.lang.Exception {
035: }
036:
037: public static junit.framework.Test suite() {
038: junit.framework.TestSuite suite = new junit.framework.TestSuite(
039: UniqueIntervalFunctionTest.class);
040:
041: return suite;
042: }
043:
044: /**
045: * Test of getName method, of class
046: * org.geotools.filter.functions.UniqueIntervalFunction.
047: */
048: public void testInstance() {
049: FunctionExpression equInt = FilterFactoryFinder
050: .createFilterFactory().createFunctionExpression(
051: "UniqueInterval");
052: assertNotNull(equInt);
053: }
054:
055: /**
056: * Test of getName method, of class
057: * org.geotools.filter.functions.UniqueIntervalFunction.
058: */
059: public void testGetName() {
060: FunctionExpression equInt = FilterFactoryFinder
061: .createFilterFactory().createFunctionExpression(
062: "UniqueInterval");
063: assertEquals("UniqueInterval", equInt.getName());
064: }
065:
066: /**
067: * Test of setNumberOfClasses method, of class
068: * org.geotools.filter.function.UniqueIntervalFunction.
069: */
070: public void testSetClasses() throws Exception {
071: Expression classes = (Expression) builder.parser(dataType, "3");
072: Expression exp = (Expression) builder.parser(dataType, "foo");
073: UniqueIntervalFunction func = (UniqueIntervalFunction) fac
074: .createFunctionExpression("UniqueInterval");
075: func.setArgs(new Expression[] { exp, classes });
076: assertEquals(3, func.getClasses());
077: func.setClasses(12);
078: assertEquals(12, func.getClasses());
079: }
080:
081: /**
082: * Test of getValue method, of class
083: * org.geotools.filter.function.UniqueIntervalFunction.
084: */
085: public void testEvaluate() throws Exception {
086: Expression classes = (Expression) builder.parser(dataType, "2");
087: Expression exp = (Expression) builder.parser(dataType, "foo");
088: FunctionExpression func = fac
089: .createFunctionExpression("UniqueInterval");
090: func.setArgs(new Expression[] { exp, classes });
091:
092: Object result = func.evaluate(featureCollection);
093: assertTrue(result instanceof ExplicitClassifier);
094: ExplicitClassifier classifier = (ExplicitClassifier) result;
095: assertEquals(2, classifier.getSize());
096: assertEquals(classifier.values[0].size(), classifier.values[1]
097: .size());
098: assertFalse(classifier.values[0]
099: .removeAll(classifier.values[1]));
100:
101: }
102: }
|