### Question:
CategorizeFunction implements Function { public Object evaluate(Object object) { return evaluate(object, Object.class); } CategorizeFunction();  CategorizeFunction(List<Expression> parameters, Literal fallback); String getName(); List<Expression> getParameters(); Object accept(ExpressionVisitor visitor, Object extraData); Object evaluate(Object object); T evaluate(Object object, Class<T> context); Literal getFallbackValue(); static final String SUCCEEDING; static final String PRECEDING; static final String RASTER_DATA; static final FunctionName NAME; }### Answer:
@Test public void testFindCategorizeFunction() throws Exception { System.out.println(" testFindCategorizeFunction"); Literal fallback = ff2.literal("NOT_FOUND"); parameters.add(ff2.property("value")); parameters.add(ff2.literal(0)); Function fn = finder.findFunction("categorize", parameters, fallback); Object result = fn.evaluate(feature(0)); assertFalse("Could not locate 'categorize' function", result.equals(fallback.getValue())); }
@Test public void testNoThresholds() throws Exception { System.out.println(" testNoThresholds"); final int categoryValue = 42; parameters.add(ff2.property("value")); parameters.add(ff2.literal(categoryValue)); Function fn = finder.findFunction("categorize", parameters); Integer result = fn.evaluate(feature(0), Integer.class); assertEquals(categoryValue, result.intValue()); }
@Test public void testSucceedingThresholds() throws Exception { System.out.println(" testSucceedingThresholds"); final String[] categories = {"low", "mid", "high", "super"}; final Double[] thresholds = {0.0, 50.0, 100.0}; setupParameters(categories, thresholds); Function fn = finder.findFunction("categorize", parameters); String result; int i; for (i = 0 ;i < thresholds.length; i++) { result = fn.evaluate(feature(thresholds[i].intValue() - 1), String.class); assertEquals(categories[i], result); result = fn.evaluate(feature(thresholds[i].intValue()), String.class); assertEquals(categories[i+1], result); } result = fn.evaluate(feature(thresholds[thresholds.length - 1].intValue() + 1), String.class); assertEquals(categories[categories.length - 1], result); }
@Test public void testPrecedingThresholds() throws Exception { System.out.println(" testPrecedingThresholds"); final String[] categories = {"low", "mid", "high", "super"}; final Double[] thresholds = {0.0, 50.0, 100.0}; setupParameters(categories, thresholds); parameters.add(ff2.literal("preceding")); Function fn = finder.findFunction("categorize", parameters); String result; int i; for (i = 0 ;i < thresholds.length; i++) { result = fn.evaluate(feature(thresholds[i].intValue() - 1), String.class); assertEquals(categories[i], result); result = fn.evaluate(feature(thresholds[i].intValue()), String.class); assertEquals(categories[i], result); } result = fn.evaluate(feature(thresholds[thresholds.length - 1].intValue() + 1), String.class); assertEquals(categories[categories.length - 1], result); }