You are viewing a plain text version of this content. The canonical link for it is here.
Posted to imperius-commits@incubator.apache.org by ke...@apache.org on 2008/01/11 18:57:14 UTC
svn commit: r611261 [40/43] - in /incubator/imperius/trunk: ./
imperius-javaspl/ imperius-javaspl/src/main/java/org/apache/imperius/javaspl/
imperius-splcore/
imperius-splcore/src/main/antlr/org/apache/imperius/spl/parser/compiler/
imperius-splcore/src...
Modified: incubator/imperius/trunk/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/NumericExpressionTest.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/NumericExpressionTest.java?rev=611261&r1=611260&r2=611261&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/NumericExpressionTest.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/NumericExpressionTest.java Fri Jan 11 10:56:30 2008
@@ -1,2466 +1,2466 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-//
-
-/**
- * @author Prashant Baliga <pr...@in.ibm.com>
- *
- */
-
-
-package org.apache.imperius.spl.tests;
-
-
-import java.util.Vector;
-
-import org.apache.imperius.spl.external.Expression;
-import org.apache.imperius.spl.parser.exceptions.SPLException;
-import org.apache.imperius.spl.parser.expressions.impl.*;
-
-import junit.extensions.TestSetup;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-
-
-
-
-public class NumericExpressionTest extends TestCase {
-
- static final String CMVC_ID_NumericExpressionTest = "$Header: /cvsroot/cimsplpegasus/trunk/modules/imperius-splcore/src/com/ibm/ac/spl/tests/NumericExpressionTest.java,v 1.2 2007/12/20 13:07:37 prabalig Exp $";
- static final String VERSION_NumericExpressionTest = "File version $Revision: 1.2 $, last changed $Date: 2007/12/20 13:07:37 $";
-
-// private static Logger logger = SPLLogger.getCIMSPLLogger().getLogger();
-
-
- static Expression propertySensor1 =null;
- //new ConstantExpression("propertySensor1");
-static Expression propertySensor2 =null;
- //new PropertySensor("propertySensor2");
-static Expression propertySensor3 =null;
- //new PropertySensor("propertySensor3");
-static Expression propertySensor4 =null;
- //new PropertySensor("propertySensor4");
-static Expression propertySensor5 =null;
- //new PropertySensor("propertySensor5");
-static Expression propertySensor6 =null;
- //new PropertySensor("propertySensor6");
-static Expression propertySensor7 =null;
- //new PropertySensor("propertySensor7");
-static Expression propertySensor8 =null;
- //new PropertySensor("propertySensor8");
-static Expression propertySensor9 =null;
- //new PropertySensor("propertySensor9");
-static Expression propertySensor10 =null;
- //new PropertySensor("propertySensor10");
- public NumericExpressionTest(String arg0) {
- super(arg0);
- }
-
- public static Test suite() {
- TestSuite suite = new TestSuite(NumericExpressionTest.class);
- TestSetup wrapper = new TestSetup(suite) {
-
- protected void setUp() throws Exception {
- oneTimeSetUp();
- }
-
- protected void tearDown() throws Exception {
- oneTimeTearDown();
- }
- };
- return wrapper;
- }
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(suite());
- }
-
- protected static void oneTimeSetUp() throws Exception {
- }
-
- protected static void oneTimeTearDown() throws Exception {
-
- }
-
- /* public void testToUINT8() {
- Byte sn1 = new Byte((byte)8);
- Byte sn2 = new Byte((byte)9);
- String s1 = "\""+sn1.toString()+"\"";
- String s2 = "\""+sn2.toString()+"\"";
-
- //HashMap map = new HashMap();
- propertySensor1=new StringConstant(s1.toString());
- propertySensor2=new StringConstant(s2.toString());
- propertySensor3=new ByteConstant(sn1.byteValue());
- propertySensor4=new ByteConstant(sn2.byteValue());
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new StringConstant(s1));
- Expression es1 = new ToUINT8(v,true);
-
- v.clear();
- v.add(new StringConstant(s2));
- Expression es2 = new ToUINT8(v,true);
-
- v.clear();
- v.add(new ByteConstant(sn1.byteValue()));
- Expression esn1 = new ToUINT8(v,true);
-
- v.clear();
- v.add(new ByteConstant(sn2.byteValue()));
- Expression esn2 = new ToUINT8(v,true);
-
-
- UnsignedInt8 x=(UnsignedInt8)es1.evaluate();
- assertTrue(x.byteValue()==(byte)8);
- x=(UnsignedInt8)es2.evaluate();
- assertTrue(x.byteValue()==(byte)9);
- x=(UnsignedInt8)esn1.evaluate();
- assertTrue(x.byteValue()==(byte)8);
- x=(UnsignedInt8)esn2.evaluate();
- assertTrue(x.byteValue()==(byte)9);
-
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- public void testToUINT16() {
- Byte sn1 = new Byte((byte)8);
- Byte sn2 = new Byte((byte)9);
- String s1 = "\""+sn1.toString()+"\"";
- String s2 = "\""+sn2.toString()+"\"";
-
- //HashMap map = new HashMap();
- propertySensor1=new StringConstant(s1.toString());
- propertySensor2=new StringConstant(s2.toString());
- propertySensor3=new ByteConstant(sn1.byteValue());
- propertySensor4=new ByteConstant(sn2.byteValue());
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new StringConstant(s1));
- Expression es1 = new ToUINT16(v,true);
-
- v.clear();
- v.add(new StringConstant(s2));
- Expression es2 = new ToUINT16(v,true);
-
- v.clear();
- v.add(new ByteConstant(sn1.byteValue()));
- Expression esn1 = new ToUINT16(v,true);
-
- v.clear();
- v.add(new ByteConstant(sn2.byteValue()));
- Expression esn2 = new ToUINT16(v,true);
-
-
- UnsignedInt16 x=(UnsignedInt16)es1.evaluate();
- assertTrue(x.shortValue()==(short)8);
- x=(UnsignedInt16)es2.evaluate();
- assertTrue(x.shortValue()==(short)9);
- x=(UnsignedInt16)esn1.evaluate();
- assertTrue(x.shortValue()==(short)8);
- x=(UnsignedInt16)esn2.evaluate();
- assertTrue(x.shortValue()==(short)9);
-
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- public void testToUINT32() {
- Byte sn1 = new Byte((byte)8);
- Byte sn2 = new Byte((byte)9);
- String s1 = "\""+sn1.toString()+"\"";
- String s2 = "\""+sn2.toString()+"\"";
-
- //HashMap map = new HashMap();
- propertySensor1=new StringConstant(s1.toString());
- propertySensor2=new StringConstant(s2.toString());
- propertySensor3=new ByteConstant(sn1.byteValue());
- propertySensor4=new ByteConstant(sn2.byteValue());
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new StringConstant(s1));
- Expression es1 = new ToUINT32(v,true);
-
- v.clear();
- v.add(new StringConstant(s2));
- Expression es2 = new ToUINT32(v,true);
-
- v.clear();
- v.add(new ByteConstant(sn1.byteValue()));
- Expression esn1 = new ToUINT32(v,true);
-
- v.clear();
- v.add(new ByteConstant(sn2.byteValue()));
- Expression esn2 = new ToUINT32(v,true);
-
-
- UnsignedInt32 x=(UnsignedInt32)es1.evaluate();
- assertTrue(x.intValue()==(int)8);
- x=(UnsignedInt32)es2.evaluate();
- assertTrue(x.intValue()==(int)9);
- x=(UnsignedInt32)esn1.evaluate();
- assertTrue(x.intValue()==(int)8);
- x=(UnsignedInt32)esn2.evaluate();
- assertTrue(x.intValue()==(int)9);
-
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- public void testToUINT64() {
- Byte sn1 = new Byte((byte)8);
- Byte sn2 = new Byte((byte)9);
- String s1 = "\""+sn1.toString()+"\"";
- String s2 = "\""+sn2.toString()+"\"";
-
- //HashMap map = new HashMap();
- propertySensor1=new StringConstant(s1.toString());
- propertySensor2=new StringConstant(s2.toString());
- propertySensor3=new ByteConstant(sn1.byteValue());
- propertySensor4=new ByteConstant(sn2.byteValue());
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new StringConstant(s1));
- Expression es1 = new ToUINT64(v,true);
-
- v.clear();
- v.add(new StringConstant(s2));
- Expression es2 = new ToUINT64(v,true);
-
- v.clear();
- v.add(new ByteConstant(sn1.byteValue()));
- Expression esn1 = new ToUINT64(v,true);
-
- v.clear();
- v.add(new ByteConstant(sn2.byteValue()));
- Expression esn2 = new ToUINT64(v,true);
-
-
- UnsignedInt64 x=(UnsignedInt64)es1.evaluate();
- assertTrue(x.longValue()==(long)8);
- x=(UnsignedInt64)es2.evaluate();
- assertTrue(x.longValue()==(long)9);
- x=(UnsignedInt64)esn1.evaluate();
- assertTrue(x.longValue()==(long)8);
- x=(UnsignedInt64)esn2.evaluate();
- assertTrue(x.longValue()==(long)9);
-
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }*/
-
- public void testToSINT8() {
- Byte sn1 = new Byte(Byte.MAX_VALUE);
- Byte sn2 = new Byte(Byte.MIN_VALUE);
- String s1 = "\""+sn1.toString()+"\"";
- String s2 = "\""+sn2.toString()+"\"";
-
- //HashMap map = new HashMap();
- propertySensor1=new StringConstant(s1.toString());
- propertySensor2=new StringConstant(s2.toString());
- propertySensor3=new ByteConstant(sn1.byteValue());
- propertySensor4=new ByteConstant(sn2.byteValue());
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new StringConstant(s1));
- Expression es1 = new ToSINT8(v,true);
-
- v.clear();
- v.add(new StringConstant(s2));
- Expression es2 = new ToSINT8(v,true);
-
- v.clear();
- v.add(new ByteConstant(sn1.byteValue()));
- Expression esn1 = new ToSINT8(v,true);
-
- v.clear();
- v.add(new ByteConstant(sn2.byteValue()));
- Expression esn2 = new ToSINT8(v,true);
-
- v.clear();
- v.add(propertySensor1);
- Expression eps1 = new ToSINT8(v,true);
-
- v.clear();
- v.add(propertySensor2);
- Expression eps2 = new ToSINT8(v,true);
-
- v.clear();
- v.add(propertySensor3);
- Expression eps3 = new ToSINT8(v,true);
-
- v.clear();
- v.add(propertySensor4);
- Expression eps4 = new ToSINT8(v,true);
-
- assertTrue(((Byte) es1.evaluate()).equals(sn1));
- assertTrue(((Byte) es2.evaluate()).equals(sn2));
- assertFalse(((Byte) es1.evaluate()).equals(sn2));
- assertTrue(((Byte) esn1.evaluate()).equals(sn1));
- assertTrue(((Byte) esn2.evaluate()).equals(sn2));
- assertFalse(((Byte) esn1.evaluate()).equals(sn2));
- s1 = s1.substring(1, s1.length()-1);
- assertTrue(((Byte) eps1.evaluate()).equals(new Byte(s1)));
- s2 = s2.substring(1, s2.length()-1);
- assertTrue(((Byte) eps2.evaluate()).equals(new Byte(s2)));
- assertTrue(((Byte) eps3.evaluate()).equals(sn1));
- assertTrue(((Byte) eps4.evaluate()).equals(sn2));
-
- assertSame(sn1.getClass(), (es1.evaluate()).getClass());
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test ToShort Expression
- */
- public void testToSINT16() {
- Short sn1 = new Short(Short.MAX_VALUE);
- Short sn2 = new Short(Short.MIN_VALUE);
- String s1 = "\""+sn1.toString()+"\"";
- String s2 = "\""+sn2.toString()+"\"";
-
- //HashMap map = new HashMap();
- propertySensor1=new StringConstant(s1.toString());
- propertySensor2=new StringConstant(s2.toString());
- propertySensor3=new ShortConstant(sn1.shortValue());
- propertySensor4=new ShortConstant(sn2.shortValue());
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new StringConstant(s1));
- Expression es1 = new ToSINT16(v,true);
-
- v.clear();
- v.add(new StringConstant(s2));
- Expression es2 = new ToSINT16(v,true);
-
- v.clear();
- v.add(new ShortConstant(sn1.shortValue()));
- Expression esn1 = new ToSINT16(v,true);
-
- v.clear();
- v.add(new ShortConstant(sn2.shortValue()));
- Expression esn2 = new ToSINT16(v,true);
-
- v.clear();
- v.add(propertySensor1);
- Expression eps1 = new ToSINT16(v,true);
-
- v.clear();
- v.add(propertySensor2);
- Expression eps2 = new ToSINT16(v,true);
-
- v.clear();
- v.add(propertySensor3);
- Expression eps3 = new ToSINT16(v,true);
-
- v.clear();
- v.add(propertySensor4);
- Expression eps4 = new ToSINT16(v,true);
-
- assertTrue(((Short) es1.evaluate()).equals(sn1));
- assertTrue(((Short) es2.evaluate()).equals(sn2));
- assertFalse(((Short) es1.evaluate()).equals(sn2));
- assertTrue(((Short) esn1.evaluate()).equals(sn1));
- assertTrue(((Short) esn2.evaluate()).equals(sn2));
- assertFalse(((Short) esn1.evaluate()).equals(sn2));
- s1 = s1.substring(1, s1.length()-1);
- assertTrue(((Short) eps1.evaluate()).equals(new Short(s1)));
- s2 = s2.substring(1, s2.length()-1);
- assertTrue(((Short) eps2.evaluate()).equals(new Short(s2)));
- assertTrue(((Short) eps3.evaluate()).equals(sn1));
- assertTrue(((Short) eps4.evaluate()).equals(sn2));
-
- assertSame(sn1.getClass(), (es1.evaluate()).getClass());
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test ToInt Expression
- */
- public void testToSINT32() {
- Integer in1 = new Integer(Integer.MAX_VALUE);
- Integer in2 = new Integer(Integer.MIN_VALUE);
- String s1 = "\""+in1.toString()+"\"";
- String s2 = "\""+in2.toString()+"\"";
-
- //HashMap map = new HashMap();
- propertySensor1=new StringConstant(s1.toString());
- propertySensor2=new StringConstant(s2.toString());
- propertySensor3=new IntegerConstant(in1.intValue());
- propertySensor4=new IntegerConstant(in2.intValue());
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new StringConstant(s1));
- Expression es1 = new ToSINT32(v,true);
-
- v.clear();
- v.add(new StringConstant(s2));
- Expression es2 = new ToSINT32(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1.intValue()));
- Expression ein1 = new ToSINT32(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in2.intValue()));
- Expression ein2 = new ToSINT32(v,true);
-
- v.clear();
- v.add(propertySensor1);
- Expression esp1 = new ToSINT32(v,true);
-
- v.clear();
- v.add(propertySensor2);
- Expression esp2 = new ToSINT32(v,true);
-
- v.clear();
- v.add(propertySensor3);
- Expression esp3 = new ToSINT32(v,true);
-
- v.clear();
- v.add(propertySensor4);
- Expression esp4 = new ToSINT32(v,true);
-
- assertTrue(((Integer) es1.evaluate()).equals(in1));
- assertTrue(((Integer) es2.evaluate()).equals(in2));
- assertFalse(((Integer) es1.evaluate()).equals(in2));
- assertTrue(((Integer) ein1.evaluate()).equals(in1));
- assertTrue(((Integer) ein2.evaluate()).equals(in2));
- assertFalse(((Integer) ein1.evaluate()).equals(in2));
- s1 = s1.substring(1, s1.length()-1);
- assertTrue(
- ((Integer) esp1.evaluate()).equals(new Integer(s1)));
- s2 = s2.substring(1, s2.length()-1);
- assertTrue(
- ((Integer) esp2.evaluate()).equals(new Integer(s2)));
- assertTrue(((Integer) esp3.evaluate()).equals(in1));
- assertTrue(((Integer) esp4.evaluate()).equals(in2));
-
- assertSame(in1.getClass(), (ein1.evaluate()).getClass());
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test ToSINT64 Expression
- */
- public void testToSINT64Expression() {
- Long ln1 = new Long(Long.MAX_VALUE);
- Long ln2 = new Long(Long.MIN_VALUE);
- String s1 = "\""+ln1.toString()+"\"";
- String s2 = "\""+ln2.toString()+"\"";
-
- //HashMap map = new HashMap();
- propertySensor1=new StringConstant(s1.toString());
- propertySensor2=new StringConstant(s2.toString());
- propertySensor3=new LongConstant(ln1.longValue());
- propertySensor4=new LongConstant(ln2.longValue());
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new StringConstant(s1));
- Expression es1 = new ToSINT64(v,true);
-
- v.clear();
- v.add(new StringConstant(s2));
- Expression es2 = new ToSINT64(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1.longValue()));
- Expression eln1 = new ToSINT64(v,true);
-
- v.clear();
- v.add(new LongConstant(ln2.longValue()));
- Expression eln2 = new ToSINT64(v,true);
-
- v.clear();
- v.add(propertySensor1);
- Expression eps1 = new ToSINT64(v,true);
-
- v.clear();
- v.add(propertySensor2);
- Expression eps2 = new ToSINT64(v,true);
-
- v.clear();
- v.add(propertySensor3);
- Expression eps3 = new ToSINT64(v,true);
-
- v.clear();
- v.add(propertySensor4);
- Expression eps4 = new ToSINT64(v,true);
-
- assertTrue(((Long) es1.evaluate()).equals(ln1));
- assertTrue(((Long) es2.evaluate()).equals(ln2));
- assertFalse(((Long) es1.evaluate()).equals(ln2));
- assertTrue(((Long) eln1.evaluate()).equals(ln1));
- assertTrue(((Long) eln2.evaluate()).equals(ln2));
- assertFalse(((Long) eln1.evaluate()).equals(ln2));
- s1 = s1.substring(1, s1.length()-1);
- assertTrue(((Long) eps1.evaluate()).equals(new Long(s1)));
- s2 = s2.substring(1, s2.length()-1);
- assertTrue(((Long) eps2.evaluate()).equals(new Long(s2)));
- assertTrue(((Long) eps3.evaluate()).equals(ln1));
- assertTrue(((Long) eps4.evaluate()).equals(ln2));
-
- //assertSame(ln1.getClass(), (eln1.evaluate()).getClass());
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test ToREAL32 Expression
- */
- public void testToREAL32Expression() {
- Float fn1 = new Float(Float.MAX_VALUE);
- Float fn2 = new Float(Float.MIN_VALUE);
- String s1 = "\""+fn1.toString()+"\"";
- String s2 = "\""+fn2.toString()+"\"";
-
- //HashMap map = new HashMap();
- propertySensor1=new StringConstant(s1.toString());
- propertySensor2=new StringConstant(s2.toString());
- propertySensor3=new FloatConstant(fn1.floatValue());
- propertySensor4=new FloatConstant(fn2.floatValue());
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new StringConstant(s1));
- Expression es1 = new ToREAL32(v,true);
-
- v.clear();
- v.add(new StringConstant(s2));
- Expression es2 = new ToREAL32(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1.floatValue()));
- Expression efn1 = new ToREAL32(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn2.floatValue()));
- Expression efn2 = new ToREAL32(v,true);
-
- v.clear();
- v.add(propertySensor1);
- Expression eps1 = new ToREAL32(v,true);
-
- v.clear();
- v.add(propertySensor2);
- Expression eps2 = new ToREAL32(v,true);
-
- v.clear();
- v.add(propertySensor3);
- Expression eps3 = new ToREAL32(v,true);
-
- v.clear();
- v.add(propertySensor4);
- Expression eps4 = new ToREAL32(v,true);
-
- assertTrue(((Float) es1.evaluate()).equals(fn1));
- assertTrue(((Float) es2.evaluate()).equals(fn2));
- assertFalse(((Float) es1.evaluate()).equals(fn2));
- assertTrue(((Float) efn1.evaluate()).equals(fn1));
- assertTrue(((Float) efn2.evaluate()).equals(fn2));
- assertFalse(((Float) efn1.evaluate()).equals(fn2));
- s1 = s1.substring(1, s1.length()-1);
- assertTrue(((Float) eps1.evaluate()).equals(new Float(s1)));
- s2 = s2.substring(1, s2.length()-1);
- assertTrue(((Float) eps2.evaluate()).equals(new Float(s2)));
- assertTrue(((Float) eps3.evaluate()).equals(fn1));
- assertTrue(((Float) eps4.evaluate()).equals(fn2));
-
- //assertSame(fn1.getClass(), (efn1.evaluate()).getClass());
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test ToREAL64 Expression
- */
- public void testToREAL64Expression() {
- Double dn1 = new Double(Double.MAX_VALUE);
- Double dn2 = new Double(Double.MIN_VALUE);
- String s1 = "\""+dn1.toString()+"\"";
- String s2 = "\""+dn2.toString()+"\"";
-
- //HashMap map = new HashMap();
- propertySensor1=new StringConstant(s1.toString());
- propertySensor2=new StringConstant(s2.toString());
- propertySensor3=new DoubleConstant(dn1.doubleValue());
- propertySensor4=new DoubleConstant(dn2.doubleValue());
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new StringConstant(s1));
- Expression es1 = new ToREAL64(v,true);
-
- v.clear();
- v.add(new StringConstant(s2));
- Expression es2 = new ToREAL64(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn1.doubleValue()));
- Expression edn1 = new ToREAL64(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn2.doubleValue()));
- Expression edn2 = new ToREAL64(v,true);
-
- v.clear();
- v.add(propertySensor1);
- Expression eps1 = new ToREAL64(v,true);
-
- v.clear();
- v.add(propertySensor2);
- Expression eps2 = new ToREAL64(v,true);
-
- v.clear();
- v.add(propertySensor3);
- Expression eps3 = new ToREAL64(v,true);
-
- v.clear();
- v.add(propertySensor4);
- Expression eps4 = new ToREAL64(v,true);
-
- assertTrue(((Double) es1.evaluate()).equals(dn1));
- assertTrue(((Double) es2.evaluate()).equals(dn2));
- assertFalse(((Double) es1.evaluate()).equals(dn2));
- assertTrue(((Double) edn1.evaluate()).equals(dn1));
- assertTrue(((Double) edn2.evaluate()).equals(dn2));
- assertFalse(((Double) edn1.evaluate()).equals(dn2));
- s1 = s1.substring(1, s1.length()-1);
- assertTrue(((Double) eps1.evaluate()).equals(new Double(s1)));
- s2 = s2.substring(1, s2.length()-1);
- assertTrue(((Double) eps2.evaluate()).equals(new Double(s2)));
- assertTrue(((Double) eps3.evaluate()).equals(dn1));
- assertTrue(((Double) eps4.evaluate()).equals(dn2));
-
- assertSame(dn1.getClass(), (edn1.evaluate()).getClass());
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test Addition Expression
- */
- public void testAdditionExpression() {
- short sn1 = 300, sn2 = 500, sn3 = -100;
- int in1 = 1000, in2 = -200, in3 = 300;
- long ln1 = 2000L, ln2 = 5000L, ln3 = -10000L;
- float fn1 = 505.1F, fn2 = 5.5F, fn3 = -1.1F;
- double dn1 = 2.3, dn2 = -100.4, dn3 = 3.1415926;
-
- //HashMap map = new HashMap();
- propertySensor1=new ShortConstant(sn1);
- propertySensor2=new ShortConstant(sn2);
- propertySensor3=new IntegerConstant(in1);
- propertySensor4=new IntegerConstant(in2);
- propertySensor5=new LongConstant(ln1);
- propertySensor6=new LongConstant(ln2);
- propertySensor7=new FloatConstant(fn1);
- propertySensor8=new FloatConstant(fn2);
- propertySensor9=new DoubleConstant(dn1);
- propertySensor10=new DoubleConstant(dn2);
-
-
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new ShortConstant(sn1));
- v.add(new ShortConstant(sn2));
-
- Expression es = new Addition(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- v.add(new IntegerConstant(in2));
-
- Expression ei = new Addition(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- v.add(new LongConstant(ln2));
-
- Expression el = new Addition(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- v.add(new FloatConstant(fn2));
-
- Expression ef = new Addition(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn1));
- v.add(new DoubleConstant(dn2));
-
- Expression ed = new Addition(v,true);
-
- v.clear();
- v.add(new ShortConstant(sn1));
- v.add(new IntegerConstant(in1));
-
- Expression emix1 = new Addition(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- v.add(new FloatConstant(fn1));
- Expression emix2 = new Addition(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- v.add(new DoubleConstant(dn1));
- Expression emix3 = new Addition(v,true);
-
-
- v.clear();
-
- v.add(propertySensor2);
- v.add(new ShortConstant(sn3));
- Expression eps1 = new Addition(v,true);
-
- v.clear();
- v.add(propertySensor4);
- v.add(new IntegerConstant(in3));
- Expression eps2 = new Addition(v,true);
-
- v.clear();
-
- v.add(propertySensor6);
- v.add(new LongConstant(ln3));
- Expression eps3 = new Addition(v,true);
-
- v.clear();
-
- v.add(propertySensor8);
- v.add(new FloatConstant(fn3));
- Expression eps4 = new Addition(v,true);
-
- v.clear();
-
- v.add(propertySensor10);
- v.add(new DoubleConstant(dn3));
- Expression eps5 = new Addition(v,true);
-
- assertTrue(
- ((sn1 + sn2)
- - ((Number) es.evaluate()).shortValue())
- == 0);
- assertTrue(
- ((in1 + in2) - ((Number) ei.evaluate()).intValue())
- == 0);
- assertTrue(
- ((ln1 + ln2)
- - ((Number) el.evaluate()).longValue())
- == 0);
- assertTrue(
- ((fn1 + fn2)
- - ((Number) ef.evaluate()).floatValue())
- == 0);
- assertTrue(
- ((dn1 + dn2)
- - ((Number) ed.evaluate()).doubleValue())
- == 0);
- assertTrue(
- ((sn1+in1)
- - ((Number) emix1.evaluate()).doubleValue())
- == 0);
- assertTrue(
- (( ln1+fn1)
- - ((Number) emix2.evaluate()).doubleValue())
- == 0);
- assertTrue(
- ((fn1+dn1)
- - ((Number) emix3.evaluate()).doubleValue())
- == 0);
-
- assertTrue(
- ((sn2 + sn3)
- - ((Number) eps1.evaluate()).shortValue())
- == 0);
- assertTrue(
- ((in2 + in3)
- - ((Number) eps2.evaluate()).intValue())
- == 0);
- assertTrue(
- ((ln2 + ln3)
- - ((Number) eps3.evaluate()).longValue())
- == 0);
- assertTrue(
- ((fn2 + fn3)
- - ((Number) eps4.evaluate()).floatValue())
- == 0);
- assertTrue(
- ((dn2 + dn3)
- - ((Number) eps5.evaluate()).doubleValue())
- == 0);
-/*
- assertSame(
- (eps1.evaluate()).getClass(),
- (new Integer(sn1)).getClass());
- assertSame(
- (eps2.evaluate()).getClass(),
- (new Integer(in1)).getClass());
- assertSame(
- (eps3.evaluate()).getClass(),
- (new Long(ln1)).getClass());
- assertSame(
- (eps4.evaluate()).getClass(),
- (new Float(fn1)).getClass());
- assertSame(
- (eps5.evaluate()).getClass(),
- (new Double(dn1)).getClass());*/
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test Subtraction Expression
- * TODO: should Subtraction check the length of input vector?
- */
- public void testSubtractionExpression() {
- short sn1 = 300, sn2 = 500;
- int in1 = 1000, in2 = -200;
- long ln1 = 2000L, ln2 = 5000L;
- float fn1 = 505.1F, fn2 = -1.1F;
- double dn1 = 2.3, dn2 = -3.1415926;
-
- //HashMap map = new HashMap();
- propertySensor1=new ShortConstant(sn1);
- propertySensor2=new ShortConstant(sn2);
- propertySensor3=new IntegerConstant(in1);
- propertySensor4=new IntegerConstant(in2);
- propertySensor5=new LongConstant(ln1);
- propertySensor6=new LongConstant(ln2);
- propertySensor7=new FloatConstant(fn1);
- propertySensor8=new FloatConstant(fn2);
- propertySensor9=new DoubleConstant(dn1);
- propertySensor10=new DoubleConstant(dn2);
-
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new ShortConstant(sn1));
- v.add(new ShortConstant(sn2));
- Expression es = new Subtraction(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- v.add(new IntegerConstant(in2));
- Expression ei = new Subtraction(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- v.add(new LongConstant(ln2));
- Expression el = new Subtraction(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- v.add(new FloatConstant(fn2));
- Expression ef = new Subtraction(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn1));
- v.add(new DoubleConstant(dn2));
- Expression ed = new Subtraction(v,true);
-
- v.clear();
- v.add(new ShortConstant(sn1));
- v.add(new IntegerConstant(in1));
- Expression emix1 = new Subtraction(v,true);
-
- v.clear();
- v.add(new ShortConstant(sn1));
- v.add(new LongConstant(ln1));
- Expression emix2 = new Subtraction(v,true);
-
- v.clear();
- v.add(new ShortConstant(sn1));
- v.add(new FloatConstant(fn1));
- Expression emix3 = new Subtraction(v,true);
-
- v.clear();
- v.add(new ShortConstant(sn1));
- v.add(new DoubleConstant(dn1));
- Expression emix4 = new Subtraction(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- v.add(new LongConstant(ln1));
- Expression emix5 = new Subtraction(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- v.add(new FloatConstant(fn1));
- Expression emix6 = new Subtraction(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- v.add(new DoubleConstant(dn1));
- Expression emix7 = new Subtraction(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- v.add(new FloatConstant(fn1));
- Expression emix8 = new Subtraction(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- v.add(new DoubleConstant(dn1));
- Expression emix9 = new Subtraction(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- v.add(new DoubleConstant(dn1));
- Expression emix10 = new Subtraction(v,true);
-
- v.clear();
- v.add(propertySensor1);
- v.add(propertySensor2);
- Expression eps1 = new Subtraction(v,true);
-
- v.clear();
- v.add(propertySensor3);
- v.add(propertySensor4);
- Expression eps2 = new Subtraction(v,true);
-
- v.clear();
- v.add(propertySensor5);
- v.add(propertySensor6);
- Expression eps3 = new Subtraction(v,true);
-
- v.clear();
- v.add(propertySensor7);
- v.add(propertySensor8);
- Expression eps4 = new Subtraction(v,true);
-
- v.clear();
- v.add(propertySensor9);
- v.add(propertySensor10);
- Expression eps5 = new Subtraction(v,true);
-
- assertTrue(
- ((sn1 - sn2) - ((Number) es.evaluate()).shortValue())
- == 0);
- assertTrue(
- ((in1 - in2) - ((Number) ei.evaluate()).intValue()) == 0);
- assertTrue(
- ((ln1 - ln2) - ((Number) el.evaluate()).longValue())
- == 0);
- assertTrue(
- ((fn1 - fn2) - ((Number) ef.evaluate()).floatValue())
- == 0);
- assertTrue(
- ((dn1 - dn2) - ((Number) ed.evaluate()).doubleValue())
- == 0);
- assertTrue(
- ((sn1 - in1) - ((Number) emix1.evaluate()).intValue())
- == 0);
- assertTrue(
- ((sn1 - ln1) - ((Number) emix2.evaluate()).longValue())
- == 0);
- assertTrue(
- ((sn1 - fn1) - ((Number) emix3.evaluate()).floatValue())
- == 0);
- assertTrue(
- ((sn1 - dn1) - ((Number) emix4.evaluate()).doubleValue())
- == 0);
- assertTrue(
- ((in1 - ln1) - ((Number) emix5.evaluate()).longValue())
- == 0);
- assertTrue(
- ((in1 - fn1) - ((Number) emix6.evaluate()).floatValue())
- == 0);
- assertTrue(
- ((in1 - dn1) - ((Number) emix7.evaluate()).doubleValue())
- == 0);
- assertTrue(
- ((ln1 - fn1) - ((Number) emix8.evaluate()).floatValue())
- == 0);
- assertTrue(
- ((ln1 - dn1) - ((Number) emix9.evaluate()).doubleValue())
- == 0);
- assertTrue(
- ((fn1 - dn1)
- - ((Number) emix10.evaluate()).doubleValue())
- == 0);
-
- assertTrue(
- ((sn1 - sn2)
- - ((Number) eps1.evaluate()).intValue())
- == 0);
- assertTrue(
- ((in1 - in2)
- - ((Number) eps2.evaluate()).intValue())
- == 0);
- assertTrue(
- ((ln1 - ln2)
- - ((Number) eps3.evaluate()).longValue())
- == 0);
- assertTrue(
- ((fn1 - fn2)
- - ((Number) eps4.evaluate()).floatValue())
- == 0);
- assertTrue(
- ((dn1 - dn2)
- - ((Number) eps5.evaluate()).doubleValue())
- == 0);
- /*
-// assertSame((new Integer(sn1 - sn2)).getClass(),
-// (eps1.evaluate()).getClass());
- assertSame((new Integer(in1 - in2)).getClass(),
- (eps2.evaluate()).getClass());
- assertSame((new Long(ln1 - ln2)).getClass(),
- (eps3.evaluate()).getClass());
- assertSame((new Float(fn1 - fn2)).getClass(),
- (eps4.evaluate()).getClass());
- assertSame((new Double(dn1 - dn2)).getClass(),
- (eps5.evaluate()).getClass());*/
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test Product Expression
- */
- public void testProductExpression() {
- short sn1 = 30, sn2 = 5, sn3 = -10;
- int in1 = 1000, in2 = -200, in3 = 300;
- long ln1 = 2000L, ln2 = 5000L, ln3 = -10000;
- float fn1 = 505.1F, fn2 = 5.5F, fn3 = -1.1F;
- double dn1 = 2.3, dn2 = -100.4, dn3 = 3.1415926;
-
- //HashMap map = new HashMap();
- propertySensor1=new ShortConstant(sn1);
- propertySensor2=new ShortConstant(sn2);
- propertySensor3=new IntegerConstant(in1);
- propertySensor4=new IntegerConstant(in2);
- propertySensor5=new LongConstant(ln1);
- propertySensor6=new LongConstant(ln2);
- propertySensor7=new FloatConstant(fn1);
- propertySensor8=new FloatConstant(fn2);
- propertySensor9=new DoubleConstant(dn1);
- propertySensor10=new DoubleConstant(dn2);
-
-
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
-
- v.add(new ShortConstant(sn2));
- v.add(new ShortConstant(sn3));
- Expression es = new Product(v,true);
-
- v.clear();
-
- v.add(new IntegerConstant(in2));
- v.add(new IntegerConstant(in3));
- Expression ei = new Product(v,true);
-
- v.clear();
-
- v.add(new LongConstant(ln2));
- v.add(new LongConstant(ln3));
- Expression el = new Product(v,true);
-
- v.clear();
-
- v.add(new FloatConstant(fn2));
- v.add(new FloatConstant(fn3));
- Expression ef = new Product(v,true);
-
- v.clear();
-
- v.add(new DoubleConstant(dn2));
- v.add(new DoubleConstant(dn3));
- Expression ed = new Product(v,true);
-
- v.clear();
- v.add(new ShortConstant(sn1));
- v.add(new IntegerConstant(in1));
-
- Expression emix1 = new Product(v,true);
-
- v.clear();
-
- v.add(new LongConstant(ln1));
- v.add(new FloatConstant(fn1));
-
- Expression emix2 = new Product(v,true);
-
- v.clear();
-
- v.add(new FloatConstant(fn1));
- v.add(new DoubleConstant(dn1));
- Expression emix3 = new Product(v,true);
-
- v.clear();
- v.add(propertySensor1);
- v.add(propertySensor2);
- Expression eps1 = new Product(v,true);
-
- v.clear();
- v.add(propertySensor3);
- v.add(propertySensor4);
- Expression eps2 = new Product(v,true);
-
- v.clear();
- v.add(propertySensor5);
- v.add(propertySensor6);
- Expression eps3 = new Product(v,true);
-
- v.clear();
- v.add(propertySensor7);
- v.add(propertySensor8);
- Expression eps4 = new Product(v,true);
-
- v.clear();
- v.add(propertySensor9);
- v.add(propertySensor10);
- Expression eps5 = new Product(v,true);
-
- assertTrue(
- ((sn2 * sn3)
- - ((Number) es.evaluate()).shortValue())
- == 0);
- assertTrue(
- ((in2 * in3)
- - ((Number) ei.evaluate()).intValue())
- == 0);
- assertTrue(
- ((ln2 * ln3)
- - ((Number) el.evaluate()).longValue())
- == 0);
- assertTrue(
- ((fn2 * fn3)
- - ((Number) ef.evaluate()).floatValue())
- == 0);
- assertTrue(
- ((dn2 * dn3)
- - ((Number) ed.evaluate()).doubleValue())
- == 0);
- assertTrue(((sn1*in1) - ((Number)emix1.evaluate()).doubleValue()) == 0);
-
- assertTrue(((ln1*fn1) - ((Number)emix2.evaluate()).doubleValue()) == 0);
- //System.out.println("(fn1*dn1) = "+(fn1*dn1));
- //System.out.println("((Number)emix2.evaluate()).doubleValue()) = "+((Number)emix3.evaluate()).doubleValue());
-
- assertTrue(((fn1*dn1) - ((Number)emix3.evaluate()).doubleValue()) == 0);
-
- assertTrue(
- ((sn1 * sn2)
- - ((Number) eps1.evaluate()).shortValue())
- == 0);
- assertTrue(
- ((in1 * in2) - ((Number) eps2.evaluate()).intValue())
- == 0);
- assertTrue(
- ((ln1 * ln2)
- - ((Number) eps3.evaluate()).longValue())
- == 0);
- assertTrue(
- ((fn1 * fn2)
- - ((Number) eps4.evaluate()).floatValue())
- == 0);
- assertTrue(
- ((dn1 * dn2)
- - ((Number) eps5.evaluate()).doubleValue())
- == 0);
- /*
- assertSame(
- (new Integer(sn1 * sn2)).getClass(),
- (eps1.evaluate()).getClass());
- assertSame(
- (new Integer(in1 * in2)).getClass(),
- (eps2.evaluate()).getClass());
- assertSame(
- (new Long(ln1 * ln2)).getClass(),
- (eps3.evaluate()).getClass());
- assertSame(
- (new Float(fn1 * fn2)).getClass(),
- (eps4.evaluate()).getClass());
- assertSame(
- (new Double(dn1 * dn2)).getClass(),
- (eps5.evaluate()).getClass());*/
- } catch (SPLException e) {
- e.printStackTrace();
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- e.printStackTrace();
-
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test Division Expression
- */
- public void testDivisionExpression() {
- short sn1 = 30, sn2 = -10;
- int in1 = 1000, in2 = -200;
- long ln1 = 2000L, ln2 = 5000L;
- float fn1 = 505.1F, fn2 = 5.5F;
- double dn1 = 2.3, dn2 = -100.4;
-
- //HashMap map = new HashMap();
- propertySensor1=new ShortConstant(sn1);
- propertySensor2=new ShortConstant(sn2);
- propertySensor3=new IntegerConstant(in1);
- propertySensor4=new IntegerConstant(in2);
- propertySensor5=new LongConstant(ln1);
- propertySensor6=new LongConstant(ln2);
- propertySensor7=new FloatConstant(fn1);
- propertySensor8=new FloatConstant(fn2);
- propertySensor9=new DoubleConstant(dn1);
- propertySensor10=new DoubleConstant(dn2);
-
-
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new ShortConstant(sn1));
- v.add(new ShortConstant(sn2));
- Expression es = new Division(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- v.add(new IntegerConstant(in2));
- Expression ei = new Division(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- v.add(new LongConstant(ln2));
- Expression el = new Division(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- v.add(new FloatConstant(fn2));
- Expression ef = new Division(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn1));
- v.add(new DoubleConstant(dn2));
- Expression ed = new Division(v,true);
-
- v.clear();
- v.add(new ShortConstant(sn1));
- v.add(new IntegerConstant(in1));
- Expression emix1 = new Division(v,true);
-
- v.clear();
- v.add(new ShortConstant(sn1));
- v.add(new LongConstant(ln1));
- Expression emix2 = new Division(v,true);
-
- v.clear();
- v.add(new ShortConstant(sn1));
- v.add(new FloatConstant(fn1));
- Expression emix3 = new Division(v,true);
-
- v.clear();
- v.add(new ShortConstant(sn1));
- v.add(new DoubleConstant(dn1));
- Expression emix4 = new Division(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- v.add(new LongConstant(ln1));
- Expression emix5 = new Division(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- v.add(new FloatConstant(fn1));
- Expression emix6 = new Division(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- v.add(new DoubleConstant(dn1));
- Expression emix7 = new Division(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- v.add(new FloatConstant(fn1));
- Expression emix8 = new Division(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- v.add(new DoubleConstant(dn1));
- Expression emix9 = new Division(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- v.add(new DoubleConstant(dn1));
- Expression emix10 = new Division(v,true);
-
- v.clear();
- v.add(propertySensor1);
- v.add(propertySensor2);
- Expression eps1 = new Division(v,true);
-
- v.clear();
- v.add(propertySensor3);
- v.add(propertySensor4);
- Expression eps2 = new Division(v,true);
-
- v.clear();
- v.add(propertySensor5);
- v.add(propertySensor6);
- Expression eps3 = new Division(v,true);
-
- v.clear();
- v.add(propertySensor7);
- v.add(propertySensor8);
- Expression eps4 = new Division(v,true);
-
- v.clear();
- v.add(propertySensor9);
- v.add(propertySensor10);
- Expression eps5 = new Division(v,true);
-
- assertTrue(
- ((sn1 / sn2) - ((Number) es.evaluate()).shortValue())
- == 0);
- assertTrue(
- ((in1 / in2) - ((Number) ei.evaluate()).intValue()) == 0);
- assertTrue(
- ((ln1 / ln2) - ((Number) el.evaluate()).longValue())
- == 0);
- assertTrue(
- ((fn1 / fn2) - ((Number) ef.evaluate()).floatValue())
- == 0);
- assertTrue(
- ((dn1 / dn2) - ((Number) ed.evaluate()).doubleValue())
- == 0);
- assertTrue(
- ((sn1 / in1) - ((Number) emix1.evaluate()).intValue())
- == 0);
- assertTrue(
- ((sn1 / ln1) - ((Number) emix2.evaluate()).longValue())
- == 0);
- assertTrue(
- ((sn1 / fn1) - ((Number) emix3.evaluate()).floatValue())
- == 0);
- assertTrue(
- ((sn1 / dn1) - ((Number) emix4.evaluate()).doubleValue())
- == 0);
- assertTrue(
- ((in1 / ln1) - ((Number) emix5.evaluate()).longValue())
- == 0);
- assertTrue(
- ((in1 / fn1) - ((Number) emix6.evaluate()).floatValue())
- == 0);
- assertTrue(
- ((in1 / dn1) - ((Number) emix7.evaluate()).doubleValue())
- == 0);
- assertTrue(
- ((ln1 / fn1) - ((Number) emix8.evaluate()).floatValue())
- == 0);
- assertTrue(
- ((ln1 / dn1) - ((Number) emix9.evaluate()).doubleValue())
- == 0);
- assertTrue(
- ((fn1 / dn1)
- - ((Number) emix10.evaluate()).doubleValue())
- == 0);
-
- assertTrue(
- ((sn1 / sn2) - ((Number) eps1.evaluate()).shortValue())
- == 0);
- assertTrue(
- ((in1 / in2) - ((Number) eps2.evaluate()).intValue()) == 0);
- assertTrue(
- ((ln1 / ln2) - ((Number) eps3.evaluate()).longValue())
- == 0);
- assertTrue(
- ((fn1 / fn2) - ((Number) eps4.evaluate()).floatValue())
- == 0);
- assertTrue(
- ((dn1 / dn2) - ((Number) eps5.evaluate()).doubleValue())
- == 0);
-/*
- assertSame(
- (new Integer(sn1 / sn2)).getClass(),
- (eps1.evaluate()).getClass());
- assertSame(
- (new Integer(in1 / in2)).getClass(),
- (eps2.evaluate()).getClass());
- assertSame(
- (new Long(ln1 / ln2)).getClass(),
- (eps3.evaluate()).getClass());
- assertSame(
- (new Float(fn1 / fn2)).getClass(),
- (eps4.evaluate()).getClass());
- assertSame(
- (new Double(dn1 / dn2)).getClass(),
- (eps5.evaluate()).getClass());*/
-
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test Mod Expression
- */
- public void testModExpression() {
- short sn1 = 30, sn2 = 5;
- int in1 = 1000, in2 = -300;
- long ln1 = 2000L, ln2 = 60L;
- float fn1 = 505.1F, fn2 = 5.5F;
- double dn1 = -100.4, dn2 = 3.1415926;
-
- //HashMap map = new HashMap();
- // propertySensor1=new StringConstant(s1.toString());
- // propertySensor2=new StringConstant(s2.toString());
- // propertySensor3=dn1);
- // propertySensor4=dn2);
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new ShortConstant(sn1));
- v.add(new ShortConstant(sn2));
- Expression es = new Mod(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- v.add(new IntegerConstant(in2));
- Expression ei = new Mod(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- v.add(new LongConstant(ln2));
- Expression el = new Mod(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- v.add(new FloatConstant(fn2));
- Expression ef = new Mod(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn1));
- v.add(new DoubleConstant(dn2));
- Expression ed = new Mod(v,true);
-
- assertTrue(
- ((sn1 % sn2) - ((Number) es.evaluate()).shortValue())
- == 0);
- assertTrue(
- ((in1 % in2) - ((Number) ei.evaluate()).intValue()) == 0);
- assertTrue(
- ((ln1 % ln2) - ((Number) el.evaluate()).longValue())
- == 0);
- assertTrue(
- ((fn1 % fn2) - ((Number) ef.evaluate()).floatValue())
- == 0);
- assertTrue(
- ((dn1 % dn2) - ((Number) ed.evaluate()).doubleValue())
- == 0);
-
-/* assertSame(
- (new Integer(sn1 % sn2)).getClass(),
- (es.evaluate()).getClass());
- assertSame(
- (new Integer(in1 % in2)).getClass(),
- (ei.evaluate()).getClass());
- assertSame(
- (new Long(ln1 % ln2)).getClass(),
- (el.evaluate()).getClass());
- assertSame(
- (new Float(fn1 % fn2)).getClass(),
- (ef.evaluate()).getClass());
- assertSame(
- (new Double(dn1 % dn2)).getClass(),
- (ed.evaluate()).getClass());*/
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test Max Expression
- */
- public void testMaxExpression() {
- short sn1 = 30, sn2 = 5;
- int in1 = 1000, in2 = -300;
- long ln1 = 2000L, ln2 = 60L;
- float fn1 = 505.1F, fn2 = 5.5F;
- double dn1 = -100.4, dn2 = 3.1415926;
-
- //HashMap map = new HashMap();
- propertySensor1=new ShortConstant(sn1);
- propertySensor2=new ShortConstant(sn2);
- propertySensor3=new IntegerConstant(in1);
- propertySensor4=new IntegerConstant(in2);
- propertySensor5=new LongConstant(ln1);
- propertySensor6=new LongConstant(ln2);
- propertySensor7=new FloatConstant(fn1);
- propertySensor8=new FloatConstant(fn2);
- propertySensor9=new DoubleConstant(dn1);
- propertySensor10=new DoubleConstant(dn2);
-
-
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- /*v.add(new ShortConstant(sn1));
- v.add(new ShortConstant(sn2));
- v.add(new IntegerConstant(in1));
- v.add(new IntegerConstant(in2));
- v.add(new LongConstant(ln1));
- v.add(new LongConstant(ln2));
- v.add(new FloatConstant(fn1));
- v.add(new FloatConstant(fn2));
- v.add(new DoubleConstant(dn1));
- v.add(new DoubleConstant(dn2));
- Expression e = new Max(v,true);*/
-
- v.clear();
- v.add(new ShortConstant(sn2));
- v.add(new IntegerConstant(in1));
- Expression emix1 = new Max(v,true);
- v.clear();
- v.add(new IntegerConstant(in2));
- v.add(new LongConstant(ln1));
- Expression emix2 = new Max(v,true);
- v.clear();
- v.add(new LongConstant(ln2));
- v.add(new FloatConstant(fn1));
- Expression emix3 = new Max(v,true);
- v.clear();
- v.add(new FloatConstant(fn2));
- v.add(new DoubleConstant(dn1));
- Expression emix4 = new Max(v,true);
- v.clear();
- v.add(new DoubleConstant(dn2));
- v.add(new ShortConstant(sn1));
- Expression emix5 = new Max(v,true);
-
-
- v.clear();
- v.add(propertySensor1);
- v.add(propertySensor2);
- Expression eps1 = new Max(v,true);
-
- v.clear();
- v.add(propertySensor3);
- v.add(propertySensor4);
- Expression eps2 = new Max(v,true);
-
- v.clear();
- v.add(propertySensor5);
- v.add(propertySensor6);
- Expression eps3 = new Max(v,true);
-
- v.clear();
- v.add(propertySensor7);
- v.add(propertySensor8);
- Expression eps4 = new Max(v,true);
-
- v.clear();
- v.add(propertySensor9);
- v.add(propertySensor10);
- Expression eps5 = new Max(v,true);
-
- assertTrue(Math.max(sn2, in1)- ((Number) emix1.evaluate()).doubleValue()== 0);
- assertTrue(Math.max(in2, ln1)- ((Number) emix2.evaluate()).doubleValue()== 0);
- assertTrue(Math.max(ln2, fn1)- ((Number) emix3.evaluate()).doubleValue()== 0);
- assertTrue(Math.max(fn2, dn1)- ((Number) emix4.evaluate()).doubleValue()== 0);
- assertTrue(Math.max(dn2, sn1)- ((Number) emix5.evaluate()).doubleValue()== 0);
- assertTrue(Math.max(sn1, sn2)- ((Number) eps1.evaluate()).doubleValue()== 0);
- assertTrue(Math.max(in1, in2)- ((Number) eps2.evaluate()).doubleValue()== 0);
- assertTrue(Math.max(ln1, ln2)- ((Number) eps3.evaluate()).doubleValue()== 0);
- assertTrue(Math.max(fn1, fn2)- ((Number) eps4.evaluate()).doubleValue()== 0);
- assertTrue(Math.max(dn1, dn2)- ((Number) eps5.evaluate()).doubleValue()== 0);
-/*
- assertSame((new Short(sn1).getClass()), (eps1.evaluate()).getClass());
- assertSame((new Integer(in1).getClass()), (eps2.evaluate()).getClass());
- assertSame((new Long(ln1).getClass()), (eps3.evaluate()).getClass());
- assertSame((new Float(fn1).getClass()), (eps4.evaluate()).getClass());
- assertSame((new Double(dn1).getClass()), (eps5.evaluate()).getClass()); */
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test Min Expression
- */
- public void testMinExpression() {
- short sn1 = 30, sn2 = 5;
- int in1 = 1000, in2 = -300;
- long ln1 = 2000L, ln2 = 60L;
- float fn1 = 505.1F, fn2 = 5.5F;
- double dn1 = -100.4, dn2 = 3.1415926;
-
- //HashMap map = new HashMap();
- propertySensor1=new ShortConstant(sn1);
- propertySensor2=new ShortConstant(sn2);
- propertySensor3=new IntegerConstant(in1);
- propertySensor4=new IntegerConstant(in2);
- propertySensor5=new LongConstant(ln1);
- propertySensor6=new LongConstant(ln2);
- propertySensor7=new FloatConstant(fn1);
- propertySensor8=new FloatConstant(fn2);
- propertySensor9=new DoubleConstant(dn1);
- propertySensor10=new DoubleConstant(dn2);
-
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
-
- /*v.add(new ShortConstant(sn1));
- v.add(new ShortConstant(sn2));
- v.add(new IntegerConstant(in1));
- v.add(new IntegerConstant(in2));
- v.add(new LongConstant(ln1));
- v.add(new LongConstant(ln2));
- v.add(new FloatConstant(fn1));
- v.add(new FloatConstant(fn2));
- v.add(new DoubleConstant(dn1));
- v.add(new DoubleConstant(dn2));
- Expression e = new Min(v,true);*/
-
- v.clear();
- v.add(new ShortConstant(sn2));
- v.add(new IntegerConstant(in1));
- Expression emix1 = new Min(v,true);
- v.clear();
- v.add(new IntegerConstant(in2));
- v.add(new LongConstant(ln1));
- Expression emix2 = new Min(v,true);
- v.clear();
- v.add(new LongConstant(ln2));
- v.add(new FloatConstant(fn1));
- Expression emix3 = new Min(v,true);
- v.clear();
- v.add(new FloatConstant(fn2));
- v.add(new DoubleConstant(dn1));
- Expression emix4 = new Min(v,true);
- v.clear();
- v.add(new DoubleConstant(dn2));
- v.add(new ShortConstant(sn1));
- Expression emix5 = new Min(v,true);
-
- v.clear();
- v.add(propertySensor1);
- v.add(propertySensor2);
- Expression eps1 = new Min(v,true);
-
- v.clear();
- v.add(propertySensor3);
- v.add(propertySensor4);
- Expression eps2 = new Min(v,true);
-
- v.clear();
- v.add(propertySensor5);
- v.add(propertySensor6);
- Expression eps3 = new Min(v,true);
-
- v.clear();
- v.add(propertySensor7);
- v.add(propertySensor8);
- Expression eps4 = new Min(v,true);
-
- v.clear();
- v.add(propertySensor9);
- v.add(propertySensor10);
- Expression eps5 = new Min(v,true);
-
- assertTrue(Math.min(sn2, in1)- ((Number) emix1.evaluate()).doubleValue()== 0);
- assertTrue(Math.min(in2, ln1)- ((Number) emix2.evaluate()).doubleValue()== 0);
- assertTrue(Math.min(ln2, fn1)- ((Number) emix3.evaluate()).doubleValue()== 0);
- assertTrue(Math.min(fn2, dn1)- ((Number) emix4.evaluate()).doubleValue()== 0);
- assertTrue(Math.min(dn2, sn1)- ((Number) emix5.evaluate()).doubleValue()== 0);
- assertTrue(Math.min(sn1, sn2)- ((Number) eps1.evaluate()).doubleValue()== 0);
- assertTrue(Math.min(in1, in2)- ((Number) eps2.evaluate()).doubleValue()== 0);
- assertTrue(Math.min(ln1, ln2)- ((Number) eps3.evaluate()).doubleValue()== 0);
- assertTrue(Math.min(fn1, fn2)- ((Number) eps4.evaluate()).doubleValue()== 0);
- assertTrue(Math.min(dn1, dn2)- ((Number) eps5.evaluate()).doubleValue()== 0);
-
-/*
- assertSame((new Short(sn1).getClass()), (eps1.evaluate()).getClass());
- assertSame((new Integer(in1).getClass()), (eps2.evaluate()).getClass());
- assertSame((new Long(ln1).getClass()), (eps3.evaluate()).getClass());
- assertSame((new Float(fn1).getClass()), (eps4.evaluate()).getClass());
- assertSame((new Double(dn1).getClass()), (eps5.evaluate()).getClass()); */
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test Ln Expression
- */
- public void testLnExpression() {
- short sn1 = 30;
- int in1 = 1000;
- long ln1 = 2000;
- float fn1 = 505.1F;
- double dn1 = 100.4;
-
- //HashMap map = new HashMap();
- propertySensor1=new ShortConstant(sn1);
- propertySensor2=new IntegerConstant(in1);
- propertySensor3=new LongConstant(ln1);
- propertySensor4=new FloatConstant(fn1);
- propertySensor5=new DoubleConstant(dn1);
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new ShortConstant(sn1));
- Expression e1 = new Ln(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- Expression e2 = new Ln(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- Expression e3 = new Ln(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- Expression e4 = new Ln(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn1));
- Expression e5 = new Ln(v,true);
-
- v.clear();
- v.add(propertySensor1);
- Expression eps1 = new Ln(v,true);
-
- v.clear();
- v.add(propertySensor2);
- Expression eps2 = new Ln(v,true);
-
- v.clear();
- v.add(propertySensor3);
- Expression eps3 = new Ln(v,true);
-
- v.clear();
- v.add(propertySensor4);
- Expression eps4 = new Ln(v,true);
-
- v.clear();
- v.add(propertySensor5);
- Expression eps5 = new Ln(v,true);
-
- assertTrue(
- (new Double(Math.log(sn1)).shortValue()
- - ((Number) e1.evaluate()).shortValue())
- == 0);
- assertTrue(
- (new Double(Math.log(in1)).intValue()
- - ((Number) e2.evaluate()).intValue())
- == 0);
- assertTrue(
- (new Double(Math.log(ln1)).longValue()
- - ((Number) e3.evaluate()).longValue())
- == 0);
- assertTrue(
- (new Double(Math.log(fn1)).floatValue()
- - ((Number) e4.evaluate()).floatValue())
- == 0);
- assertTrue(
- (new Double(Math.log(dn1)).doubleValue()
- - ((Number) e5.evaluate()).doubleValue())
- == 0);
-
- assertTrue(
- (new Double(Math.log(sn1)).shortValue()
- - ((Number) eps1.evaluate()).shortValue())
- == 0);
- assertTrue(
- (new Double(Math.log(in1)).intValue()
- - ((Number) eps2.evaluate()).intValue())
- == 0);
- assertTrue(
- (new Double(Math.log(ln1)).longValue()
- - ((Number) eps3.evaluate()).longValue())
- == 0);
- assertTrue(
- (new Double(Math.log(fn1)).floatValue()
- - ((Number) eps4.evaluate()).floatValue())
- == 0);
- assertTrue(
- (new Double(Math.log(dn1)).doubleValue()
- - ((Number) eps5.evaluate()).doubleValue())
- == 0);
-
- assertSame((new Double(dn1)).getClass(), (eps1.evaluate()).getClass());
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test Exp Expression
- */
- public void testExpExpression() {
- short sn1 = 30;
- int in1 = 1000;
- long ln1 = 2000;
- float fn1 = 50.1F;
- double dn1 = 100.4;
-
- //HashMap map = new HashMap();
- // propertySensor1=new StringConstant(s1.toString());
- // propertySensor2=new StringConstant(s2.toString());
- // propertySensor3=dn1);
- // propertySensor4=dn2);
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new ShortConstant(sn1));
- Expression e1 = new Exp(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- Expression e2 = new Exp(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- Expression e3 = new Exp(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- Expression e4 = new Exp(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn1));
- Expression e5 = new Exp(v,true);
-
- assertTrue(
- (new Double(Math.exp(sn1)).shortValue()
- - ((Number) e1.evaluate()).shortValue())
- == 0);
- assertTrue(
- (new Double(Math.exp(in1)).intValue()
- - ((Number) e2.evaluate()).intValue())
- == 0);
- assertTrue(
- (new Double(Math.exp(ln1)).longValue()
- - ((Number) e3.evaluate()).longValue())
- == 0);
- assertTrue(
- (new Double(Math.exp(fn1)).floatValue()
- - ((Number) e4.evaluate()).floatValue())
- == 0);
- assertTrue(
- (new Double(Math.exp(dn1)).doubleValue()
- - ((Number) e5.evaluate()).doubleValue())
- == 0);
-
- //assertSame((new Double(dn1)).getClass(), (e1.evaluate()).getClass());
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test Power Expression
- */
- public void testPowerExpression() {
- short sn1 = 30, sn2 = 5;
- int in1 = 1000, in2 = 9;
- long ln1 = 2000, ln2 = 30;
- float fn1 = 50.1F, fn2 = 9.3F;
- double dn1 = 100.4, dn2 = 0.123;
-
- //HashMap map = new HashMap();
- // propertySensor1=new StringConstant(s1.toString());
- // propertySensor2=new StringConstant(s2.toString());
- // propertySensor3=dn1);
- // propertySensor4=dn2);
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new ShortConstant(sn1));
- v.add(new ShortConstant(sn2));
- Expression e1 = new Power(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- v.add(new IntegerConstant(in2));
- Expression e2 = new Power(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- v.add(new LongConstant(ln2));
- Expression e3 = new Power(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- v.add(new FloatConstant(fn2));
- Expression e4 = new Power(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn1));
- v.add(new DoubleConstant(dn2));
- Expression e5 = new Power(v,true);
-
- assertTrue(
- (new Double(Math.pow(sn1, sn2)).shortValue()
- - ((Number) e1.evaluate()).shortValue())
- == 0);
- assertTrue(
- (new Double(Math.pow(in1, in2)).intValue()
- - ((Number) e2.evaluate()).intValue())
- == 0);
- assertTrue(
- (new Double(Math.pow(ln1, ln2)).longValue()
- - ((Number) e3.evaluate()).longValue())
- == 0);
- assertTrue(
- (new Double(Math.pow(fn1, fn2)).floatValue()
- - ((Number) e4.evaluate()).floatValue())
- == 0);
- assertTrue(
- (new Double(Math.pow(dn1, dn2)).doubleValue()
- - ((Number) e5.evaluate()).doubleValue())
- == 0);
-
- //assertSame((new Double(dn1)).getClass(), (e1.evaluate()).getClass());
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test SquareRoot Expression
- */
- public void testSquareRootExpression() {
- short sn1 = 30;
- int in1 = 1000;
- long ln1 = 2000;
- float fn1 = 50.1F;
- double dn1 = 100.4;
-
- //HashMap map = new HashMap();
- // propertySensor1=new StringConstant(s1.toString());
- // propertySensor2=new StringConstant(s2.toString());
- // propertySensor3=dn1);
- // propertySensor4=dn2);
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new ShortConstant(sn1));
- Expression e1 = new SquareRoot(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- Expression e2 = new SquareRoot(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- Expression e3 = new SquareRoot(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- Expression e4 = new SquareRoot(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn1));
- Expression e5 = new SquareRoot(v,true);
-
- assertTrue(
- (new Double(Math.sqrt(sn1)).shortValue()
- - ((Number) e1.evaluate()).shortValue())
- == 0);
- assertTrue(
- (new Double(Math.sqrt(in1)).intValue()
- - ((Number) e2.evaluate()).intValue())
- == 0);
- assertTrue(
- (new Double(Math.sqrt(ln1)).longValue()
- - ((Number) e3.evaluate()).longValue())
- == 0);
- assertTrue(
- (new Double(Math.sqrt(fn1)).floatValue()
- - ((Number) e4.evaluate()).floatValue())
- == 0);
- assertTrue(
- (new Double(Math.sqrt(dn1)).doubleValue()
- - ((Number) e5.evaluate()).doubleValue())
- == 0);
-
- //assertSame((new Double(dn1)).getClass(), (e1.evaluate()).getClass());
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test Abs Expression
- */
- public void testAbsExpression() {
- short sn1 = 30;
- int in1 = 1000;
- long ln1 = -2000;
- float fn1 = -50.1F;
- double dn1 = -100.4;
-
- //HashMap map = new HashMap();
- // propertySensor1=new StringConstant(s1.toString());
- // propertySensor2=new StringConstant(s2.toString());
- // propertySensor3=dn1);
- // propertySensor4=dn2);
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new ShortConstant(sn1));
- Expression e1 = new Abs(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- Expression e2 = new Abs(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- Expression e3 = new Abs(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- Expression e4 = new Abs(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn1));
- Expression e5 = new Abs(v,true);
-
- assertTrue(
- (Math.abs(sn1) - ((Number) e1.evaluate()).shortValue())
- == 0);
- assertTrue(
- (Math.abs(in1) - ((Number) e2.evaluate()).intValue())
- == 0);
- assertTrue(
- (Math.abs(ln1) - ((Number) e3.evaluate()).longValue())
- == 0);
- assertTrue(
- (Math.abs(fn1) - ((Number) e4.evaluate()).floatValue())
- == 0);
- assertTrue(
- (Math.abs(dn1) - ((Number) e5.evaluate()).doubleValue())
- == 0);
-/*
- assertSame((new Short(sn1)).getClass(), (e1.evaluate()).getClass());
- assertSame((new Integer(in1)).getClass(), (e2.evaluate()).getClass());
- assertSame((new Long(ln1)).getClass(), (e3.evaluate()).getClass());
- assertSame((new Float(fn1)).getClass(), (e4.evaluate()).getClass());
- assertSame((new Double(dn1)).getClass(), (e5.evaluate()).getClass());*/
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test Round Expression
- */
- public void testRoundExpression() {
- short sn1 = 30;
- int in1 = 1000;
- long ln1 = -2000;
- float fn1 = -50.1F;
- double dn1 = -100.5;
-
- //HashMap map = new HashMap();
- // propertySensor1=new StringConstant(s1.toString());
- // propertySensor2=new StringConstant(s2.toString());
- // propertySensor3=dn1);
- // propertySensor4=dn2);
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new ShortConstant(sn1));
- Expression e1 = new Round(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- Expression e2 = new Round(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- Expression e3 = new Round(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- Expression e4 = new Round(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn1));
- Expression e5 = new Round(v,true);
-
- assertTrue(
- (Math.round(sn1) - ((Number) e1.evaluate()).shortValue())
- == 0);
- assertTrue(
- (Math.round(in1) - ((Number) e2.evaluate()).intValue())
- == 0);
- assertTrue(
- (Math.round(ln1) - ((Number) e3.evaluate()).intValue())
- == 0);
- assertTrue(
- (Math.round(fn1) - ((Number) e4.evaluate()).intValue())
- == 0);
- assertTrue(
- (Math.round(dn1) - ((Number) e5.evaluate()).longValue())
- == 0);
-/*
-// assertSame((new Short(sn1)).getClass(), (e1.evaluate()).getClass());
-// assertSame((new Integer(in1)).getClass(), (e2.evaluate()).getClass());
-// assertSame((new Long(ln1)).getClass(), (e3.evaluate()).getClass());
- assertSame((new Integer(in1)).getClass(), (e4.evaluate()).getClass());
- assertSame((new Long(ln1)).getClass(), (e5.evaluate()).getClass());*/
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test Rint Expression
- */
- public void testRintExpression() {
- short sn1 = 30;
- int in1 = 1000;
- long ln1 = -2000;
- float fn1 = -50.1F;
- double dn1 = -100.5;
-
- //HashMap map = new HashMap();
- // propertySensor1=new StringConstant(s1.toString());
- // propertySensor2=new StringConstant(s2.toString());
- // propertySensor3=dn1);
- // propertySensor4=dn2);
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new ShortConstant(sn1));
- Expression e1 = new Rint(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- Expression e2 = new Rint(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- Expression e3 = new Rint(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- Expression e4 = new Rint(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn1));
- Expression e5 = new Rint(v,true);
-
- assertTrue(
- (Math.rint(sn1) - ((Number) e1.evaluate()).shortValue())
- == 0);
- assertTrue(
- (Math.rint(in1) - ((Number) e2.evaluate()).intValue())
- == 0);
- assertTrue(
- (Math.rint(ln1) - ((Number) e3.evaluate()).intValue())
- == 0);
- assertTrue(
- (Math.rint(fn1) - ((Number) e4.evaluate()).intValue())
- == 0);
- assertTrue(
- (Math.rint(dn1) - ((Number) e5.evaluate()).longValue())
- == 0);
-/*
- assertSame((new Double(sn1)).getClass(), (e1.evaluate()).getClass());
- assertSame((new Double(in1)).getClass(), (e2.evaluate()).getClass());
- assertSame((new Double(ln1)).getClass(), (e3.evaluate()).getClass());
- assertSame((new Double(in1)).getClass(), (e4.evaluate()).getClass());
- assertSame((new Double(ln1)).getClass(), (e5.evaluate()).getClass());*/
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test Floor Expression
- */
- public void testFloorExpression() {
- short sn1 = 30;
- int in1 = 1000;
- long ln1 = -2000;
- float fn1 = -50.1F;
- double dn1 = -100.5;
-
- //HashMap map = new HashMap();
- // propertySensor1=new StringConstant(s1.toString());
- // propertySensor2=new StringConstant(s2.toString());
- // propertySensor3=dn1);
- // propertySensor4=dn2);
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new ShortConstant(sn1));
- Expression e1 = new Floor(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- Expression e2 = new Floor(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- Expression e3 = new Floor(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- Expression e4 = new Floor(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn1));
- Expression e5 = new Floor(v,true);
-
- assertTrue(
- (Math.floor(sn1) - ((Number) e1.evaluate()).shortValue())
- == 0);
- assertTrue(
- (Math.floor(in1) - ((Number) e2.evaluate()).intValue())
- == 0);
- assertTrue(
- (Math.floor(ln1) - ((Number) e3.evaluate()).intValue())
- == 0);
- assertTrue(
- (Math.floor(fn1) - ((Number) e4.evaluate()).intValue())
- == 0);
- assertTrue(
- (Math.floor(dn1) - ((Number) e5.evaluate()).longValue())
- == 0);
-/*
- assertSame((new Double(sn1)).getClass(), (e1.evaluate()).getClass());
- assertSame((new Double(in1)).getClass(), (e2.evaluate()).getClass());
- assertSame((new Double(ln1)).getClass(), (e3.evaluate()).getClass());
- assertSame((new Double(in1)).getClass(), (e4.evaluate()).getClass());
- assertSame((new Double(ln1)).getClass(), (e5.evaluate()).getClass());*/
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- /*
- * This will test Ceiling Expression
- */
- public void testCeilingExpression() {
- short sn1 = 30;
- int in1 = 1000;
- long ln1 = -2000;
- float fn1 = -50.1F;
- double dn1 = -100.5;
-
- ////HashMap map = new HashMap();
- // propertySensor1=new StringConstant(s1.toString());
- // propertySensor2=new StringConstant(s2.toString());
- // propertySensor3=dn1);
- // propertySensor4=dn2);
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new ShortConstant(sn1));
- Expression e1 = new Ceiling(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- Expression e2 = new Ceiling(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- Expression e3 = new Ceiling(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- Expression e4 = new Ceiling(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn1));
- Expression e5 = new Ceiling(v,true);
-
- assertTrue(
- (Math.ceil(sn1) - ((Number) e1.evaluate()).shortValue())
- == 0);
- assertTrue(
- (Math.ceil(in1) - ((Number) e2.evaluate()).intValue())
- == 0);
- assertTrue(
- (Math.ceil(ln1) - ((Number) e3.evaluate()).intValue())
- == 0);
- assertTrue(
- (Math.ceil(fn1) - ((Number) e4.evaluate()).intValue())
- == 0);
- assertTrue(
- (Math.ceil(dn1) - ((Number) e5.evaluate()).longValue())
- == 0);
-/*
- assertSame((new Double(sn1)).getClass(), (e1.evaluate()).getClass());
- assertSame((new Double(in1)).getClass(), (e2.evaluate()).getClass());
- assertSame((new Double(ln1)).getClass(), (e3.evaluate()).getClass());
- assertSame((new Double(in1)).getClass(), (e4.evaluate()).getClass());
- assertSame((new Double(ln1)).getClass(), (e5.evaluate()).getClass());*/
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
-
- public void testLog10Expression() {
- short sn1 = 30;
- int in1 = 1000;
- long ln1 = 2000;
- float fn1 = 50.1F;
- double dn1 = 100.4;
-
- //HashMap map = new HashMap();
- // propertySensor1=new StringConstant(s1.toString());
- // propertySensor2=new StringConstant(s2.toString());
- // propertySensor3=dn1);
- // propertySensor4=dn2);
- //SensorLookup lookup = new SensorLookupImpl(map);
-
- try {
- Vector v = new Vector();
- v.add(new ShortConstant(sn1));
- Expression e1 = new Log10(v,true);
-
- v.clear();
- v.add(new IntegerConstant(in1));
- Expression e2 = new Log10(v,true);
-
- v.clear();
- v.add(new LongConstant(ln1));
- Expression e3 = new Log10(v,true);
-
- v.clear();
- v.add(new FloatConstant(fn1));
- Expression e4 = new Log10(v,true);
-
- v.clear();
- v.add(new DoubleConstant(dn1));
- Expression e5 = new Log10(v,true);
-
- assertTrue(((Number) e1.evaluate()).doubleValue()==1.4771212547196624);
- assertTrue(((Number) e2.evaluate()).doubleValue()==2.9999999999999996);
- assertTrue(((Number) e3.evaluate()).doubleValue()==3.301029995663981);
- assertTrue(((Number) e4.evaluate()).doubleValue()==1.6998377126400839);
- assertTrue(((Number) e5.evaluate()).doubleValue()==2.0017337128090005);
-
-
- } catch (SPLException e) {
- fail("Received evaluation exception " + e.getMessage());
- } catch (Exception e) {
- fail("Received expression exception " + e.getMessage());
- }
- }
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+//
+
+/**
+ * @author Prashant Baliga <pr...@in.ibm.com>
+ *
+ */
+
+
+package org.apache.imperius.spl.tests;
+
+
+import java.util.Vector;
+
+import org.apache.imperius.spl.external.Expression;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
[... 2439 lines stripped ...]