Author: ruschein
Date: 2010-05-27 13:49:12 -0700 (Thu, 27 May 2010)
New Revision: 20337

Added:
   corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Cos.java
   corelibs/trunk/equations/src/org/cytoscape/equations/builtins/NormDist.java
   corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Radians.java
   corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Sin.java
Modified:
   corelibs/trunk/equations/src/org/cytoscape/equations/FunctionUtil.java
   corelibs/trunk/equations/src/org/cytoscape/equations/Parser.java
   
corelibs/trunk/equations/tests/org/cytoscape/equations/interpreter/InterpreterTest.java
Log:
Added new built-ins RADIANS(), SIN(), COS(), and NORMDIST().

Modified: corelibs/trunk/equations/src/org/cytoscape/equations/FunctionUtil.java
===================================================================
--- corelibs/trunk/equations/src/org/cytoscape/equations/FunctionUtil.java      
2010-05-27 20:38:27 UTC (rev 20336)
+++ corelibs/trunk/equations/src/org/cytoscape/equations/FunctionUtil.java      
2010-05-27 20:49:12 UTC (rev 20337)
@@ -85,6 +85,33 @@
        }
 
        /**
+        *  Assumes that "arg" is a "String", "Boolean", "Long" or a "Double 
and converts it to "boolean".
+        *  @return the converted argument as a "boolean"
+        *  @throws IllegalArgumentException if the argument cannot be 
converted to a "boolean"
+        */
+       static public boolean getArgAsBoolean(final Object arg) throws 
IllegalArgumentException {
+               if (arg.getClass() == Double.class) {
+                       final double d = (Double)arg;
+                       return d == 0.0 ? false : true;
+               }
+               if (arg.getClass() == Long.class) {
+                       final long l = (Long)arg;
+                       return l == 0L ? false : true;
+               }
+               if (arg.getClass() == String.class) {
+                       try {
+                               return Boolean.parseBoolean((String)arg);
+                       } catch (final Exception e) {
+                               throw new IllegalArgumentException("can't 
convert \"" + arg + "\" to a boolean!");
+                       }
+               }
+               if (arg.getClass() == Boolean.class)
+                       return (Boolean)arg;
+
+               throw new IllegalArgumentException("can't convert argument to a 
boolean!");
+       }
+
+       /**
         *  Carefully adds the numbers in "a" minimising loss of precision.
         *
         *  @return the sum of the elements of "a"
@@ -175,4 +202,11 @@
 
                return x;
        }
+
+       /**
+        *  @return true, if type is Double.class, Long.class, String.class or 
Boolean.class, else false
+        */
+       static public boolean isScalarArgType(final Class type) {
+               return type == Double.class || type == Long.class || type == 
String.class || type == Boolean.class;
+       }
 }

Modified: corelibs/trunk/equations/src/org/cytoscape/equations/Parser.java
===================================================================
--- corelibs/trunk/equations/src/org/cytoscape/equations/Parser.java    
2010-05-27 20:38:27 UTC (rev 20336)
+++ corelibs/trunk/equations/src/org/cytoscape/equations/Parser.java    
2010-05-27 20:49:12 UTC (rev 20337)
@@ -47,6 +47,7 @@
                        eqnParser.registerFunction(new And());
                        eqnParser.registerFunction(new Average());
                        eqnParser.registerFunction(new Combin());
+                       eqnParser.registerFunction(new Cos());
                        eqnParser.registerFunction(new Count());
                        eqnParser.registerFunction(new Exp());
                        eqnParser.registerFunction(new First());
@@ -67,13 +68,16 @@
                        eqnParser.registerFunction(new Mod());
                        eqnParser.registerFunction(new Mode());
                        eqnParser.registerFunction(new Not());
+                       eqnParser.registerFunction(new NormDist());
                        eqnParser.registerFunction(new Nth());
                        eqnParser.registerFunction(new Or());
                        eqnParser.registerFunction(new Permut());
                        eqnParser.registerFunction(new Pi());
+                       eqnParser.registerFunction(new Radians());
                        eqnParser.registerFunction(new Right());
                        eqnParser.registerFunction(new Round());
                        eqnParser.registerFunction(new Sign());
+                       eqnParser.registerFunction(new Sin());
                        eqnParser.registerFunction(new StDev());
                        eqnParser.registerFunction(new Sqrt());
                        eqnParser.registerFunction(new Substitute());

Copied: corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Cos.java 
(from rev 20310, 
corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Abs.java)
===================================================================
--- corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Cos.java      
                        (rev 0)
+++ corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Cos.java      
2010-05-27 20:49:12 UTC (rev 20337)
@@ -0,0 +1,99 @@
+/*
+  File: Cos.java
+
+  Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+  This library is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License, or
+  any later version.
+
+  This library is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+  documentation provided hereunder is on an "as is" basis, and the
+  Institute for Systems Biology and the Whitehead Institute
+  have no obligations to provide maintenance, support,
+  updates, enhancements or modifications.  In no event shall the
+  Institute for Systems Biology and the Whitehead Institute
+  be liable to any party for direct, indirect, special,
+  incidental or consequential damages, including lost profits, arising
+  out of the use of this software and its documentation, even if the
+  Institute for Systems Biology and the Whitehead Institute
+  have been advised of the possibility of such damage.  See
+  the GNU Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this library; if not, write to the Free Software Foundation,
+  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.equations.builtins;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import org.cytoscape.equations.Function;
+import org.cytoscape.equations.FunctionUtil;
+
+
+public class Cos implements Function {
+       /**
+        *  Used to parse the function string.  This name is treated in a 
case-insensitive manner!
+        *  @return the name by which you must call the function when used in 
an attribute equation.
+        */
+       public String getName() { return "COS"; }
+
+       /**
+        *  Used to provide help for users.
+        *  @return a description of what this function does
+        */
+       public String getFunctionSummary() { return "Returns the cosine of a 
number."; }
+
+       /**
+        *  Used to provide help for users.
+        *  @return a description of how to use this function
+        */
+       public String getUsageDescription() { return "Call this with 
\"COS(radians)\""; }
+
+       public Class getReturnType() { return Double.class; }
+
+       /**
+        *  @return Double.class or null if there is not exactly 1 arg or the 
arg is not of type Double, Long, String or Boolean
+        */
+       public Class validateArgTypes(final Class[] argTypes) {
+               if (argTypes.length != 1 || 
!FunctionUtil.isScalarArgType(argTypes[0]))
+                       return null;
+
+               return Double.class;
+       }
+
+       /**
+        *  @param args the function arguments which must be either one object 
of type Double or Long
+        *  @return the result of the function evaluation which is the natural 
logarithm of the first argument
+        */
+       public Object evaluateFunction(final Object[] args) {
+               final double angleInRadians = 
FunctionUtil.getArgAsDouble(args[0]);
+               return Math.cos(angleInRadians);
+       }
+
+       /**
+        *  Used with the equation builder.
+        *
+        *  @param leadingArgs the types of the arguments that have already 
been selected by the user.
+        *  @return the set of arguments (must be a collection of String.class, 
Long.class, Double.class,
+        *           Boolean.class and List.class) that are candidates for the 
next argument.  An empty
+        *           set indicates that no further arguments are valid.
+        */
+       public List<Class> getPossibleArgTypes(final Class[] leadingArgs) {
+               if (leadingArgs.length == 0) {
+                       final List<Class> possibleNextArgs = new 
ArrayList<Class>();
+                       possibleNextArgs.add(Double.class);
+                       possibleNextArgs.add(Long.class);
+                       possibleNextArgs.add(String.class);
+                       possibleNextArgs.add(Boolean.class);
+                       return possibleNextArgs;
+               }
+
+               return null;
+       }
+}

Copied: 
corelibs/trunk/equations/src/org/cytoscape/equations/builtins/NormDist.java 
(from rev 20332, 
corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Permut.java)
===================================================================
--- corelibs/trunk/equations/src/org/cytoscape/equations/builtins/NormDist.java 
                        (rev 0)
+++ corelibs/trunk/equations/src/org/cytoscape/equations/builtins/NormDist.java 
2010-05-27 20:49:12 UTC (rev 20337)
@@ -0,0 +1,170 @@
+/*
+  File: NormDist.java
+
+  Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+  This library is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License, or
+  any later version.
+
+  This library is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+  documentation provided hereunder is on an "as is" basis, and the
+  Institute for Systems Biology and the Whitehead Institute
+  have no obligations to provide maintenance, support,
+  updates, enhancements or modifications.  In no event shall the
+  Institute for Systems Biology and the Whitehead Institute
+  be liable to any party for direct, indirect, special,
+  incidental or consequential damages, including lost profits, arising
+  out of the use of this software and its documentation, even if the
+  Institute for Systems Biology and the Whitehead Institute
+  have been advised of the possibility of such damage.  See
+  the GNU Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this library; if not, write to the Free Software Foundation,
+  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.equations.builtins;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import org.cytoscape.equations.Function;
+import org.cytoscape.equations.FunctionUtil;
+
+
+public class NormDist implements Function {
+       /**
+        *  Used to parse the function string.  This name is treated in a 
case-insensitive manner!
+        *  @return the name by which you must call the function when used in 
an attribute equation.
+        */
+       public String getName() { return "NORMDIST"; }
+
+       /**
+        *  Used to provide help for users.
+        *  @return a description of what this function does
+        */
+       public String getFunctionSummary() { return "Returns the Normal 
Probability Density Function or the Cumulative Normal Distribution Function."; }
+
+       /**
+        *  Used to provide help for users.
+        *  @return a description of how to use this function
+        */
+       public String getUsageDescription() { return "Call this with 
\"NORMDIST(x,mean,stddev,cumulative?)\""; }
+
+       public Class getReturnType() { return Double.class; }
+
+       /**
+        *  @return Double.class or null if there are 2 args or the args are 
not of type Double, Long, Boolean or String
+        */
+       public Class validateArgTypes(final Class[] argTypes) {
+               if (argTypes.length != 4)
+                       return null;
+
+               for (final Class argType : argTypes) {
+                       if (argType != Double.class && argType != Long.class && 
argType != String.class && argType != Boolean.class)
+                               return null;
+               }
+
+               return Double.class;
+       }
+
+       /**
+        *  @param args the function arguments which must be either one or two 
objects of type Double
+        *  @return the result of the function evaluation which is the 
logarithm of the first argument
+        *  @throws ArithmeticException 
+        *  @throws IllegalArgumentException thrown if any of the arguments is 
not of type Double
+        */
+       public Object evaluateFunction(final Object[] args) throws 
IllegalArgumentException, ArithmeticException {
+               final double x = FunctionUtil.getArgAsDouble(args[0]);
+               final double mu = FunctionUtil.getArgAsDouble(args[1]);
+               final double sigma = FunctionUtil.getArgAsDouble(args[2]);
+               if (sigma <= 0)
+                       throw new IllegalArgumentException("mean parameter in 
call to NORMDIST must be nonnegative!");
+               final boolean cumulative = 
FunctionUtil.getArgAsBoolean(args[3]);
+
+               if (cumulative) {
+                       final double z = (x - mu) / sigma;
+                       return (Double)cdf(z);
+               }
+               else
+                       return (Double)pdf(x, mu, sigma);
+       }
+
+       /**
+        *  Used with the equation builder.
+        *
+        *  @param leadingArgs the types of the arguments that have already 
been selected by the user.
+        *  @return the set of arguments (must be a collection of String.class, 
Long.class, Double.class,
+        *           Boolean.class and List.class) that are candidates for the 
next argument.  An empty
+        *           set indicates that no further arguments are valid.
+        */
+       public List<Class> getPossibleArgTypes(final Class[] leadingArgs) {
+               if (leadingArgs.length < 4) {
+                       final List<Class> possibleNextArgs = new 
ArrayList<Class>();
+                       possibleNextArgs.add(Double.class);
+                       possibleNextArgs.add(Long.class);
+                       possibleNextArgs.add(Boolean.class);
+                       possibleNextArgs.add(String.class);
+                       return possibleNextArgs;
+               }
+
+               return null;
+       }
+
+       /**
+        *  @return the pdf of a normal distribution with mean "mu" and std. 
dev. "sigma"
+        */
+       private double pdf(final double x, final double mu, final double sigma) 
{
+               final double z = (x - mu) / sigma;
+               return Math.exp(- 0.5 * z * z) / (Math.sqrt(2.0 * Math.PI) * 
sigma);
+       }
+
+       /**
+        *  Calculates an approximation to the CDF of the standard normal 
distribution
+        *  based on "BETTER APPROXIMATIONS TO CUMULATIVE NORMAL FUNCTIONS" by 
Graeme West.
+        *
+        *  @return the CDF of the standard normal distribution
+        */
+       private double cdf(final double z) {
+               double cumulativeNorm;
+               final double zAbs = Math.abs(z);
+               if (zAbs > 37.0)
+                       cumulativeNorm = 0.0;
+               else {
+                       final double Exponential = Math.exp(-zAbs * zAbs / 2.0);
+                       if (zAbs < 7.07106781186547) {
+                               double build = 3.52624965998911E-02 * zAbs + 
0.700383064443688;
+                               build = build * zAbs + 6.37396220353165;
+                               build = build * zAbs + 33.912866078383;
+                               build = build * zAbs + 112.079291497871;
+                               build = build * zAbs + 221.213596169931;
+                               build = build * zAbs + 220.206867912376;
+                               cumulativeNorm = Exponential * build;
+                               build = 8.83883476483184E-02 * zAbs + 
1.75566716318264;
+                               build = build * zAbs + 16.064177579207;
+                               build = build * zAbs + 86.7807322029461;
+                               build = build * zAbs + 296.564248779674;
+                               build = build * zAbs + 637.333633378831;
+                               build = build * zAbs + 793.826512519948;
+                               build = build * zAbs + 440.413735824752;
+                               cumulativeNorm = cumulativeNorm / build;
+                       } else {
+                               double build = zAbs + 0.65;
+                               build = zAbs + 4 / build;
+                               build = zAbs + 3 / build;
+                               build = zAbs + 2 / build;
+                               build = zAbs + 1 / build;
+                               cumulativeNorm = Exponential / build / 
2.506628274631;
+                       }
+               }
+
+               if (z > 0.0)
+                       cumulativeNorm = 1.0 - cumulativeNorm;
+
+               return cumulativeNorm;
+       }
+}

Copied: 
corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Radians.java 
(from rev 20310, 
corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Abs.java)
===================================================================
--- corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Radians.java  
                        (rev 0)
+++ corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Radians.java  
2010-05-27 20:49:12 UTC (rev 20337)
@@ -0,0 +1,99 @@
+/*
+  File: Radians.java
+
+  Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+  This library is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License, or
+  any later version.
+
+  This library is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+  documentation provided hereunder is on an "as is" basis, and the
+  Institute for Systems Biology and the Whitehead Institute
+  have no obligations to provide maintenance, support,
+  updates, enhancements or modifications.  In no event shall the
+  Institute for Systems Biology and the Whitehead Institute
+  be liable to any party for direct, indirect, special,
+  incidental or consequential damages, including lost profits, arising
+  out of the use of this software and its documentation, even if the
+  Institute for Systems Biology and the Whitehead Institute
+  have been advised of the possibility of such damage.  See
+  the GNU Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this library; if not, write to the Free Software Foundation,
+  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.equations.builtins;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import org.cytoscape.equations.Function;
+import org.cytoscape.equations.FunctionUtil;
+
+
+public class Radians implements Function {
+       /**
+        *  Used to parse the function string.  This name is treated in a 
case-insensitive manner!
+        *  @return the name by which you must call the function when used in 
an attribute equation.
+        */
+       public String getName() { return "RADIANS"; }
+
+       /**
+        *  Used to provide help for users.
+        *  @return a description of what this function does
+        */
+       public String getFunctionSummary() { return "Returns the value in 
radians converted from degrees."; }
+
+       /**
+        *  Used to provide help for users.
+        *  @return a description of how to use this function
+        */
+       public String getUsageDescription() { return "Call this with 
\"RADIANS(degrees)\""; }
+
+       public Class getReturnType() { return Double.class; }
+
+       /**
+        *  @return Double.class or null if there is not exactly 1 arg or the 
arg is not of type Double, Long, String or Boolean
+        */
+       public Class validateArgTypes(final Class[] argTypes) {
+               if (argTypes.length != 1 || 
!FunctionUtil.isScalarArgType(argTypes[0]))
+                       return null;
+
+               return Double.class;
+       }
+
+       /**
+        *  @param args the function arguments which must be either one object 
of type Double or Long
+        *  @return the result of the function evaluation which is the natural 
logarithm of the first argument
+        */
+       public Object evaluateFunction(final Object[] args) {
+               final double angleInDegrees = 
FunctionUtil.getArgAsDouble(args[0]);
+               return angleInDegrees * Math.PI / 180.0;
+       }
+
+       /**
+        *  Used with the equation builder.
+        *
+        *  @param leadingArgs the types of the arguments that have already 
been selected by the user.
+        *  @return the set of arguments (must be a collection of String.class, 
Long.class, Double.class,
+        *           Boolean.class and List.class) that are candidates for the 
next argument.  An empty
+        *           set indicates that no further arguments are valid.
+        */
+       public List<Class> getPossibleArgTypes(final Class[] leadingArgs) {
+               if (leadingArgs.length == 0) {
+                       final List<Class> possibleNextArgs = new 
ArrayList<Class>();
+                       possibleNextArgs.add(Double.class);
+                       possibleNextArgs.add(Long.class);
+                       possibleNextArgs.add(String.class);
+                       possibleNextArgs.add(Boolean.class);
+                       return possibleNextArgs;
+               }
+
+               return null;
+       }
+}

Copied: corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Sin.java 
(from rev 20310, 
corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Abs.java)
===================================================================
--- corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Sin.java      
                        (rev 0)
+++ corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Sin.java      
2010-05-27 20:49:12 UTC (rev 20337)
@@ -0,0 +1,99 @@
+/*
+  File: Sin.java
+
+  Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+  This library is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License, or
+  any later version.
+
+  This library is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+  documentation provided hereunder is on an "as is" basis, and the
+  Institute for Systems Biology and the Whitehead Institute
+  have no obligations to provide maintenance, support,
+  updates, enhancements or modifications.  In no event shall the
+  Institute for Systems Biology and the Whitehead Institute
+  be liable to any party for direct, indirect, special,
+  incidental or consequential damages, including lost profits, arising
+  out of the use of this software and its documentation, even if the
+  Institute for Systems Biology and the Whitehead Institute
+  have been advised of the possibility of such damage.  See
+  the GNU Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this library; if not, write to the Free Software Foundation,
+  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.equations.builtins;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import org.cytoscape.equations.Function;
+import org.cytoscape.equations.FunctionUtil;
+
+
+public class Sin implements Function {
+       /**
+        *  Used to parse the function string.  This name is treated in a 
case-insensitive manner!
+        *  @return the name by which you must call the function when used in 
an attribute equation.
+        */
+       public String getName() { return "SIN"; }
+
+       /**
+        *  Used to provide help for users.
+        *  @return a description of what this function does
+        */
+       public String getFunctionSummary() { return "Returns the sine of a 
number."; }
+
+       /**
+        *  Used to provide help for users.
+        *  @return a description of how to use this function
+        */
+       public String getUsageDescription() { return "Call this with 
\"SIN(radians)\""; }
+
+       public Class getReturnType() { return Double.class; }
+
+       /**
+        *  @return Double.class or null if there is not exactly 1 arg or the 
arg is not of type Double, Long, String or Boolean
+        */
+       public Class validateArgTypes(final Class[] argTypes) {
+               if (argTypes.length != 1 || 
!FunctionUtil.isScalarArgType(argTypes[0]))
+                       return null;
+
+               return Double.class;
+       }
+
+       /**
+        *  @param args the function arguments which must be either one object 
of type Double or Long
+        *  @return the result of the function evaluation which is the natural 
logarithm of the first argument
+        */
+       public Object evaluateFunction(final Object[] args) {
+               final double angleInRadians = 
FunctionUtil.getArgAsDouble(args[0]);
+               return Math.sin(angleInRadians);
+       }
+
+       /**
+        *  Used with the equation builder.
+        *
+        *  @param leadingArgs the types of the arguments that have already 
been selected by the user.
+        *  @return the set of arguments (must be a collection of String.class, 
Long.class, Double.class,
+        *           Boolean.class and List.class) that are candidates for the 
next argument.  An empty
+        *           set indicates that no further arguments are valid.
+        */
+       public List<Class> getPossibleArgTypes(final Class[] leadingArgs) {
+               if (leadingArgs.length == 0) {
+                       final List<Class> possibleNextArgs = new 
ArrayList<Class>();
+                       possibleNextArgs.add(Double.class);
+                       possibleNextArgs.add(Long.class);
+                       possibleNextArgs.add(String.class);
+                       possibleNextArgs.add(Boolean.class);
+                       return possibleNextArgs;
+               }
+
+               return null;
+       }
+}

Modified: 
corelibs/trunk/equations/tests/org/cytoscape/equations/interpreter/InterpreterTest.java
===================================================================
--- 
corelibs/trunk/equations/tests/org/cytoscape/equations/interpreter/InterpreterTest.java
     2010-05-27 20:38:27 UTC (rev 20336)
+++ 
corelibs/trunk/equations/tests/org/cytoscape/equations/interpreter/InterpreterTest.java
     2010-05-27 20:49:12 UTC (rev 20337)
@@ -947,4 +947,63 @@
                final Interpreter interpreter3 = new 
Interpreter(compiler.getEquation(), nameToDescriptorMap);
                 assertEquals(new Long(28L), interpreter3.run());
        }
+
+       public void testNORMDIST() throws Exception {
+               final Map<String, Class> attribNameToTypeMap = new 
HashMap<String, Class>();
+               final Map<String, IdentDescriptor> nameToDescriptorMap = new 
HashMap<String, IdentDescriptor>();
+
+               assertTrue(compiler.compile("=NORMDIST( 50, 40, 20, FALSE)", 
attribNameToTypeMap));
+               final Interpreter interpreter1 = new 
Interpreter(compiler.getEquation(), nameToDescriptorMap);
+                assertEquals(new Double(0.017603266338214976), 
interpreter1.run());
+
+               assertTrue(compiler.compile("=NORMDIST( 0.8, 1, 0.3, TRUE)", 
attribNameToTypeMap));
+               final Interpreter interpreter2 = new 
Interpreter(compiler.getEquation(), nameToDescriptorMap);
+                assertEquals(new Double(0.25249253754692297), 
interpreter2.run());
+       }
+
+       public void testRADIANS() throws Exception {
+               final Map<String, Class> attribNameToTypeMap = new 
HashMap<String, Class>();
+               final Map<String, IdentDescriptor> nameToDescriptorMap = new 
HashMap<String, IdentDescriptor>();
+               assertTrue(compiler.compile("=RADIANS(180)", 
attribNameToTypeMap));
+               final Interpreter interpreter = new 
Interpreter(compiler.getEquation(), nameToDescriptorMap);
+                assertEquals(new Double(Math.PI), interpreter.run());
+       }
+
+       public void testSIN() throws Exception {
+               final Map<String, Class> attribNameToTypeMap = new 
HashMap<String, Class>();
+               final Map<String, IdentDescriptor> nameToDescriptorMap = new 
HashMap<String, IdentDescriptor>();
+
+               assertTrue(compiler.compile("=SIN("+Math.PI+"/6)", 
attribNameToTypeMap));
+               final Interpreter interpreter1 = new 
Interpreter(compiler.getEquation(), nameToDescriptorMap);
+                assertEquals(new Double(0.49999999999999994), 
interpreter1.run());
+
+               assertTrue(compiler.compile("=SIN(RADIANS(60))", 
attribNameToTypeMap));
+               final Interpreter interpreter2 = new 
Interpreter(compiler.getEquation(), nameToDescriptorMap);
+                assertEquals(new Double(0.8660254037844386), 
interpreter2.run());
+
+               assertTrue(compiler.compile("=SIN(RADIANS(-30))", 
attribNameToTypeMap));
+               final Interpreter interpreter3 = new 
Interpreter(compiler.getEquation(), nameToDescriptorMap);
+                assertEquals(new Double(-0.49999999999999994), 
interpreter3.run());
+       }
+
+       public void testCOS() throws Exception {
+               final Map<String, Class> attribNameToTypeMap = new 
HashMap<String, Class>();
+               final Map<String, IdentDescriptor> nameToDescriptorMap = new 
HashMap<String, IdentDescriptor>();
+
+               assertTrue(compiler.compile("=COS("+Math.PI+"/6)", 
attribNameToTypeMap));
+               final Interpreter interpreter1 = new 
Interpreter(compiler.getEquation(), nameToDescriptorMap);
+                assertEquals(new Double(0.8660254037844387), 
interpreter1.run());
+
+               assertTrue(compiler.compile("=COS(RADIANS(60))", 
attribNameToTypeMap));
+               final Interpreter interpreter2 = new 
Interpreter(compiler.getEquation(), nameToDescriptorMap);
+                assertEquals(new Double(0.5000000000000001), 
interpreter2.run());
+
+               assertTrue(compiler.compile("=COS(RADIANS(-30))", 
attribNameToTypeMap));
+               final Interpreter interpreter3 = new 
Interpreter(compiler.getEquation(), nameToDescriptorMap);
+                assertEquals(new Double(0.8660254037844387), 
interpreter3.run());
+
+               assertTrue(compiler.compile("=COS(0.785398163)", 
attribNameToTypeMap));
+               final Interpreter interpreter4 = new 
Interpreter(compiler.getEquation(), nameToDescriptorMap);
+                assertEquals(new Double(0.7071067814675859), 
interpreter4.run());
+       }
 }

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to