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.logging.Logger;
019:
020: import org.geotools.feature.Feature;
021: import org.geotools.feature.FeatureIterator;
022: import org.geotools.filter.Expression;
023: import org.geotools.filter.FilterFactoryFinder;
024: import org.geotools.filter.FunctionExpression;
025: import org.geotools.filter.parser.ParseException;
026:
027: /**
028: *
029: * @author Cory Horner, Refractions Research
030: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/test/java/org/geotools/filter/function/StandardDeviationFunctionTest.java $
031: */
032: public class StandardDeviationFunctionTest extends FunctionTestSupport {
033: private static final Logger LOGGER = org.geotools.util.logging.Logging
034: .getLogger("org.geotools.filter");
035:
036: public StandardDeviationFunctionTest(String testName) {
037: super (testName);
038: }
039:
040: protected void tearDown() throws java.lang.Exception {
041: }
042:
043: public static junit.framework.Test suite() {
044: junit.framework.TestSuite suite = new junit.framework.TestSuite(
045: StandardDeviationFunctionTest.class);
046:
047: return suite;
048: }
049:
050: public void testInstance() {
051: FunctionExpression stdDev = FilterFactoryFinder
052: .createFilterFactory().createFunctionExpression(
053: "StandardDeviation");
054: assertNotNull(stdDev);
055: }
056:
057: public void testGetName() {
058: FunctionExpression equInt = FilterFactoryFinder
059: .createFilterFactory().createFunctionExpression(
060: "StandardDeviation");
061: LOGGER.finer("testGetName");
062: assertEquals("StandardDeviation", equInt.getName());
063: }
064:
065: public void testSetNumberOfClasses() throws Exception {
066: LOGGER.finer("testSetNumberOfClasses");
067:
068: Expression classes = (Expression) builder.parser(dataType, "3");
069: Expression exp = (Expression) builder.parser(dataType, "foo");
070: StandardDeviationFunction func = (StandardDeviationFunction) fac
071: .createFunctionExpression("StandardDeviation");
072: func.setArgs(new Expression[] { exp, classes });
073: assertEquals(3, func.getClasses());
074: classes = (Expression) builder.parser(dataType, "12");
075: func.setArgs(new Expression[] { exp, classes });
076: assertEquals(12, func.getClasses());
077: }
078:
079: public void XtestGetValue() throws Exception {
080: //doesn't work yet?
081: LOGGER.finer("testGetValue");
082: Expression classes = (Expression) builder.parse(dataType, "5");
083: Expression exp = (Expression) builder.parse(dataType, "foo");
084: FunctionExpression func = fac
085: .createFunctionExpression("StandardDeviation");
086: func.setArgs(new Expression[] { exp, classes });
087:
088: FeatureIterator list = featureCollection.features();
089: //feature 1
090: Feature f = list.next();
091: int slot = ((Number) func.getValue(f)).intValue();
092: assertEquals(1, slot);
093: //feature 2
094: f = list.next();
095: slot = ((Number) func.getValue(f)).intValue();
096: assertEquals(4, slot);
097: //feature 3
098: f = list.next();
099: slot = ((Number) func.getValue(f)).intValue();
100: assertEquals(2, slot);
101: //feature 4
102: f = list.next();
103: slot = ((Number) func.getValue(f)).intValue();
104: assertEquals(2, slot);
105: //feature 5
106: f = list.next();
107: slot = ((Number) func.getValue(f)).intValue();
108: assertEquals(2, slot);
109: //feature 6
110: f = list.next();
111: slot = ((Number) func.getValue(f)).intValue();
112: assertEquals(3, slot);
113: //feature 7
114: f = list.next();
115: slot = ((Number) func.getValue(f)).intValue();
116: assertEquals(1, slot);
117: //feature 8
118: f = list.next();
119: slot = ((Number) func.getValue(f)).intValue();
120: assertEquals(1, slot);
121: }
122:
123: }
|