/* * ************************************************************************************* * Copyright (C) 2008 EsperTech, Inc. All rights reserved. * * http://esper.codehaus.org * * http://www.espertech.com * * ---------------------------------------------------------------------------------- * * The software in this package is published under the terms of the GPL license * * a copy of which has been included with this distribution in the license.txt file. * * ************************************************************************************* */ package com.espertech.esper.epl.expression; import com.espertech.esper.epl.agg.aggregator.AggregationMethod; import com.espertech.esper.epl.agg.service.AggregationMethodFactory; import com.espertech.esper.support.epl.SupportExprNode; import com.espertech.esper.support.epl.SupportExprNodeFactory; public class TestExprAvedevNode extends TestExprAggregateNodeAdapter { public void setUp() throws Exception { super.validatedNodeToTest = makeNode(5, Integer.class); } public void testGetType() throws Exception { assertEquals(Double.class, validatedNodeToTest.getType()); } public void testToExpressionString() throws Exception { assertEquals("avedev(5)", validatedNodeToTest.toExpressionString()); } public void testEqualsNode() throws Exception { assertTrue(validatedNodeToTest.equalsNode(validatedNodeToTest)); assertFalse(validatedNodeToTest.equalsNode(new ExprStddevNode(false, false))); } public void testAggregateFunction() { AggregationMethodFactory aggFactory = validatedNodeToTest.getFactory(); AggregationMethod agg = aggFactory.make(SupportExprNodeFactory.getMethodResService(), -1, 1, 1); assertEquals(Double.class, agg.getValueType()); assertNull(agg.getValue()); agg.enter(82); assertEquals(0D, agg.getValue()); agg.enter(78); assertEquals(2D, agg.getValue()); agg.enter(70); double result = (Double)agg.getValue(); assertEquals("4.4444", Double.toString(result).substring(0, 6)); agg.enter(58); assertEquals(8D, agg.getValue()); agg.enter(42); assertEquals(12.8D, agg.getValue()); agg.leave(82); assertEquals(12D, agg.getValue()); agg.leave(58); result = (Double)agg.getValue(); assertEquals("14.2222", Double.toString(result).substring(0, 7)); } private ExprAvedevNode makeNode(Object value, Class type) throws Exception { ExprAvedevNode avedevNode = new ExprAvedevNode(false, false); avedevNode.addChildNode(new SupportExprNode(value, type)); SupportExprNodeFactory.validate3Stream(avedevNode); return avedevNode; } }