Author: ruschein
Date: 2010-06-15 14:04:21 -0700 (Tue, 15 Jun 2010)
New Revision: 20546

Added:
   cytoscape/trunk/src/cytoscape/util/AbstractScaler.java
   cytoscape/trunk/src/cytoscape/util/LinearScaler.java
   cytoscape/trunk/src/cytoscape/util/RankScaler.java
   cytoscape/trunk/src/cytoscape/util/Scaler.java
   cytoscape/trunk/src/cytoscape/util/ScalerFactory.java
   cytoscape/trunk/tests/cytoscape/util/LinearScalerTest.java
   cytoscape/trunk/tests/cytoscape/util/RankScalerTest.java
   cytoscape/trunk/tests/cytoscape/util/ScalerFactoryTest.java
Removed:
   cytoscape/trunk/src/cytoscape/util/ProbabilityScaler.java
   cytoscape/trunk/tests/cytoscape/util/ProbabilityScalerTest.java
Modified:
   cytoscape/trunk/src/cytoscape/util/MathUtil.java
Log:
Replaced ProbabilityScaler with a hopefully cleaner Scaler interface and a 
ScalerFactory class.

Copied: cytoscape/trunk/src/cytoscape/util/AbstractScaler.java (from rev 20541, 
cytoscape/trunk/src/cytoscape/util/ProbabilityScaler.java)
===================================================================
--- cytoscape/trunk/src/cytoscape/util/AbstractScaler.java                      
        (rev 0)
+++ cytoscape/trunk/src/cytoscape/util/AbstractScaler.java      2010-06-15 
21:04:21 UTC (rev 20546)
@@ -0,0 +1,67 @@
+/*
+  File: AbstractScaler.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 cytoscape.util;
+
+
+import java.util.AbstractCollection;
+
+
+/**
+ *  Used to scale a list of values to [a,b]
+ */
+public abstract class AbstractScaler implements Scaler {
+       public abstract double[] scale(final double values[], final double a, 
final double b) throws IllegalArgumentException;
+
+       public final double[] scale(final AbstractCollection<Double> values, 
final double a,
+                                   final double b) throws 
IllegalArgumentException
+       {
+               // Convert the collection to an array:
+               final double[] array = new double[values.size()];
+               int i = 0;
+               for (final Double d : values)
+                       array[i++] = d;
+
+               return scale(array, a, b);
+       }
+
+       public abstract float[] scale(final float values[], final float a, 
final float b) throws IllegalArgumentException;
+
+       public final float[] scale(final AbstractCollection<Float> values, 
final float a,
+                                  final float b) throws 
IllegalArgumentException
+       {
+               // Convert the collection to an array:
+               final float[] array = new float[values.size()];
+               int i = 0;
+               for (final Float f : values)
+                       array[i++] = f;
+
+               return scale(array, a, b);
+       }
+}

Copied: cytoscape/trunk/src/cytoscape/util/LinearScaler.java (from rev 20541, 
cytoscape/trunk/src/cytoscape/util/ProbabilityScaler.java)
===================================================================
--- cytoscape/trunk/src/cytoscape/util/LinearScaler.java                        
        (rev 0)
+++ cytoscape/trunk/src/cytoscape/util/LinearScaler.java        2010-06-15 
21:04:21 UTC (rev 20546)
@@ -0,0 +1,94 @@
+/*
+  File: LinearScaler.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 cytoscape.util;
+
+
+/**
+ *  Used to scale a list of values to [a,b]
+ */
+class LinearScaler extends AbstractScaler {
+       public double[] scale(final double values[], final double a, final 
double b) throws IllegalArgumentException
+       {
+               if (values.length < 2)
+                       throw new IllegalArgumentException("need at least 2 
values for scaling!");
+               if (a >= b)
+                       throw new IllegalArgumentException("bad bounds!");
+
+               double min = Double.POSITIVE_INFINITY;
+               double max = Double.NEGATIVE_INFINITY;
+               for (final double d : values) {
+                       if (d < min)
+                               min = d;
+                       if (d > max)
+                               max = d;
+               }
+
+               if (min == max)
+                       throw new IllegalArgumentException("input values are 
all identical!");
+
+               final double c = (a - b) / (min - max);
+               final double d = a - c * min;
+
+               final double[] scaledValues = new double[values.length];
+               for (int i = 0; i < values.length; ++i)
+                       scaledValues[i] = c * values[i] + d;
+
+               return scaledValues;
+       }
+
+       public float[] scale(final float values[], final float a, final float 
b) throws IllegalArgumentException
+       {
+               if (values.length < 2)
+                       throw new IllegalArgumentException("need at least 2 
values for scaling!");
+               if (a >= b)
+                       throw new IllegalArgumentException("bad bounds!");
+
+               float min = Float.POSITIVE_INFINITY;
+               float max = Float.NEGATIVE_INFINITY;
+               for (final float d : values) {
+                       if (d < min)
+                               min = d;
+                       if (d > max)
+                               max = d;
+               }
+
+               if (min == max)
+                       throw new IllegalArgumentException("input values are 
all identical!");
+
+               final float c = (a - b) / (min - max);
+               final float d = a - c * min;
+
+               final float[] scaledValues = new float[values.length];
+               for (int i = 0; i < values.length; ++i)
+                       scaledValues[i] = c * values[i] + d;
+
+               return scaledValues;
+       }
+}

Modified: cytoscape/trunk/src/cytoscape/util/MathUtil.java
===================================================================
--- cytoscape/trunk/src/cytoscape/util/MathUtil.java    2010-06-15 20:15:40 UTC 
(rev 20545)
+++ cytoscape/trunk/src/cytoscape/util/MathUtil.java    2010-06-15 21:04:21 UTC 
(rev 20546)
@@ -12,6 +12,16 @@
                final int BIT_OFFSET = 23;
                return (bits >> BIT_OFFSET) - BIAS;
        }
+       /**
+        *  @returns the unbiased exponent of a double-precision IEEE floating 
point number
+        */
+       static public long getExponent(final double f) {
+               final long EXPONENT_MASK = 0x7FFFF00000000000L;
+               final long bits = Double.doubleToLongBits(f) & EXPONENT_MASK;
+               final int BIAS = 1023;
+               final int BIT_OFFSET = 52;
+               return (bits >> BIT_OFFSET) - BIAS;
+       }
 
        static public boolean almostEqual(final float x1, final float x2) {
                if (x1 == x2)
@@ -31,4 +41,23 @@
                else
                        return Math.abs(x1 - x2) / Math.abs(x2) < 1.0e-6f;
        }
+
+       static public boolean almostEqual(final double x1, final double x2) {
+               if (x1 == x2)
+                       return true;
+
+               if (Math.signum(x1) != Math.signum(x2))
+                       return false;
+
+               if (MathUtil.getExponent(x1) != MathUtil.getExponent(x2))
+                       return false;
+
+               final double absX1 = Math.abs(x1);
+               final double absX2 = Math.abs(x2);
+
+               if (x1 != 0.0)
+                       return Math.abs(x1 - x2) / Math.abs(x1) < 1.0e-10;
+               else
+                       return Math.abs(x1 - x2) / Math.abs(x2) < 1.0e-10;
+       }
 }
\ No newline at end of file

Deleted: cytoscape/trunk/src/cytoscape/util/ProbabilityScaler.java
===================================================================
--- cytoscape/trunk/src/cytoscape/util/ProbabilityScaler.java   2010-06-15 
20:15:40 UTC (rev 20545)
+++ cytoscape/trunk/src/cytoscape/util/ProbabilityScaler.java   2010-06-15 
21:04:21 UTC (rev 20546)
@@ -1,110 +0,0 @@
-package cytoscape.util;
-
-
-import java.util.Arrays;
-
-
-/**
- *  This class exists to support scaling of numeric values to the range 
(0.5,1.0).
- *  @author ruschein
- */
-public class ProbabilityScaler {
-       private static float min, max;
-
-       public static float[] scale(final float[] values,
-                                   final ScalingMethod scalingMethod,
-                                   final StringBuilder errorMessage)
-       {
-               errorMessage.setLength(0);
-
-               // Sanity check:
-               if (values.length < 2) {
-                       errorMessage.append("the values cannot be scaled since 
there are/is only "
-                                           + values.length + " of them!");
-                       return null;
-               }
-
-               if (scalingMethod == ScalingMethod.NONE)
-                       return values;
-
-               findMinAndMax(values);
-               if (min == max) {
-                       errorMessage.append("cannot scale any values because 
they are all identical!");
-                       return null;
-               }
-
-
-               switch (scalingMethod) {
-               case LINEAR_LOWER:
-                       return scaleLinearLower(values, errorMessage);
-               case LINEAR_UPPER:
-                       return scaleLinearUpper(values, errorMessage);
-               case RANK_LOWER:
-                       return scaleRankLower(values, errorMessage);
-               case RANK_UPPER:
-                       return scaleRankUpper(values, errorMessage);
-               default:
-                       throw new IllegalStateException("unknown scaling 
method: " + scalingMethod);
-               }
-       }
-
-       private static float[] scaleLinearLower(final float[] values, final 
StringBuilder errorMessage)
-       {
-               final float eps = 0.5f / (values.length + 1);
-
-               // We map the values from (max,min) to (0.5+eps,1.0-eps)
-               final float x0 = max;
-               final float x1 = min;
-               final float a = (0.5f - 2.0f * eps) / (x1 - x0);
-               final float b = 1.0f -eps - (0.5f - 2.0f * eps) * x1 / (x1 - 
x0);
-
-               for (int i = 0; i < values.length; ++i)
-                       values[i] = a * values[i] + b;
-
-               return values;
-       }
-
-       private static float[] scaleLinearUpper(final float[] values, final 
StringBuilder errorMessage)
-       {
-               final float eps = 0.5f / (values.length + 1);
-
-               // We map the values from (min,max) to (0.5+eps,1.0-eps)
-               final float x0 = min;
-               final float x1 = max;
-               final float a = (0.5f - 2.0f * eps) / (x1 - x0);
-               final float b = 1.0f - eps - (0.5f - 2.0f * eps) * x1 / (x1 - 
x0);
-
-               for (int i = 0; i < values.length; ++i)
-                       values[i] = a * values[i] + b;
-
-               return values;
-       }
-
-       private static float[] scaleRankLower(final float[] values, final 
StringBuilder errorMessage)
-       {
-               float[] scaledValues = QuantileNorm.quantileNorm(values);
-               for (int i = 0; i < scaledValues.length; ++i)
-                       scaledValues[i] = 0.5f + scaledValues[i] / 2.0f;
-               return scaledValues;
-       }
-
-       private static float[] scaleRankUpper(final float[] values, final 
StringBuilder errorMessage)
-       {
-               for (int i = 0; i < values.length; ++i)
-                       values[i] = -values[i];
-               float[] scaledValues = QuantileNorm.quantileNorm(values);
-               for (int i = 0; i < scaledValues.length; ++i)
-                       scaledValues[i] = 0.5f + scaledValues[i] / 2.0f;
-               return scaledValues;
-       }
-
-       private static void findMinAndMax(final float[] values) {
-               min = max = values[0];
-               for (final float f : values) {
-                       if (f < min)
-                               min = f;
-                       else if (f > max)
-                               max = f;
-               }
-       }
-}
\ No newline at end of file

Copied: cytoscape/trunk/src/cytoscape/util/RankScaler.java (from rev 20541, 
cytoscape/trunk/src/cytoscape/util/ProbabilityScaler.java)
===================================================================
--- cytoscape/trunk/src/cytoscape/util/RankScaler.java                          
(rev 0)
+++ cytoscape/trunk/src/cytoscape/util/RankScaler.java  2010-06-15 21:04:21 UTC 
(rev 20546)
@@ -0,0 +1,112 @@
+/*
+  File: RankScaler.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 cytoscape.util;
+
+
+import java.util.Arrays;
+import java.util.HashMap;
+
+
+/**
+ *  Used to scale a list of values to [a,b]
+ */
+class RankScaler extends AbstractScaler {
+       public double[] scale(final double values[], final double a, final 
double b) throws IllegalArgumentException
+       {
+               if (values.length < 2)
+                       throw new IllegalArgumentException("need at least 2 
values for scaling!");
+               if (a >= b)
+                       throw new IllegalArgumentException("bad bounds!");
+
+               final double sortedValues[] = values.clone();
+               Arrays.sort(sortedValues);
+
+               final HashMap<Double, Double> origValueToRankValueMap = new 
HashMap<Double, Double>();
+               final double stepSize = (b - a) / values.length;
+               double currentValue = sortedValues[0];
+               double sum = stepSize / 2.0;
+               double count = 1.0;
+               for (int i = 1; i < values.length; ++i) {
+                       final double currentRankValue = stepSize * (0.5 + i);
+                       if (sortedValues[i] == currentValue) {
+                               ++count;
+                               sum += currentRankValue;
+                       } else {
+                               origValueToRankValueMap.put(currentValue, sum / 
count);
+                               currentValue = sortedValues[i];
+                               sum = currentRankValue;
+                               count = 1.0;
+                       }
+               }
+               origValueToRankValueMap.put(sortedValues[values.length - 1], 
sum / count);
+
+               final double[] scaledValues = new double[values.length];
+               for (int i = 0; i < values.length; ++i)
+                       scaledValues[i] = 
origValueToRankValueMap.get(values[i]);
+
+               return scaledValues;
+       }
+
+       public float[] scale(final float values[], final float a, final float 
b) throws IllegalArgumentException
+       {
+               if (values.length < 2)
+                       throw new IllegalArgumentException("need at least 2 
values for scaling!");
+               if (a >= b)
+                       throw new IllegalArgumentException("bad bounds!");
+
+               final float sortedValues[] = values.clone();
+               Arrays.sort(sortedValues);
+
+               final HashMap<Float, Float> origValueToRankValueMap = new 
HashMap<Float, Float>();
+               final float stepSize = (b - a) / values.length;
+               float currentValue = sortedValues[0];
+               float sum = stepSize / 2.0f;
+               float count = 1.0f;
+               for (int i = 1; i < values.length; ++i) {
+                       final float currentRankValue = stepSize * (0.5f + i);
+                       if (sortedValues[i] == currentValue) {
+                               ++count;
+                               sum += currentRankValue;
+                       } else {
+                               origValueToRankValueMap.put(currentValue, sum / 
count);
+                               currentValue = sortedValues[i];
+                               sum = currentRankValue;
+                               count = 1.0f;
+                       }
+               }
+               origValueToRankValueMap.put(sortedValues[values.length - 1], 
sum / count);
+
+               final float[] scaledValues = new float[values.length];
+               for (int i = 0; i < values.length; ++i)
+                       scaledValues[i] = 
origValueToRankValueMap.get(values[i]);
+
+               return scaledValues;
+       }
+}

Copied: cytoscape/trunk/src/cytoscape/util/Scaler.java (from rev 20541, 
cytoscape/trunk/src/cytoscape/util/ProbabilityScaler.java)
===================================================================
--- cytoscape/trunk/src/cytoscape/util/Scaler.java                              
(rev 0)
+++ cytoscape/trunk/src/cytoscape/util/Scaler.java      2010-06-15 21:04:21 UTC 
(rev 20546)
@@ -0,0 +1,48 @@
+/*
+  File: Scaler.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 cytoscape.util;
+
+
+import java.util.AbstractCollection;
+
+
+/**
+ *  Used to scale a list of values to [a,b]
+ */
+interface Scaler {
+       double[] scale(final double values[], final double a, final double b) 
throws IllegalArgumentException;
+       double[] scale(final AbstractCollection<Double> values, final double a, 
final double b) throws IllegalArgumentException;
+
+       float[] scale(final float values[], final float a, final float b) 
throws IllegalArgumentException;
+       float[] scale(final AbstractCollection<Float> values, final float a, 
final float b) throws IllegalArgumentException;
+}
+
+
+

Copied: cytoscape/trunk/src/cytoscape/util/ScalerFactory.java (from rev 20541, 
cytoscape/trunk/src/cytoscape/util/ProbabilityScaler.java)
===================================================================
--- cytoscape/trunk/src/cytoscape/util/ScalerFactory.java                       
        (rev 0)
+++ cytoscape/trunk/src/cytoscape/util/ScalerFactory.java       2010-06-15 
21:04:21 UTC (rev 20546)
@@ -0,0 +1,72 @@
+/*
+  File: ScalerFactory.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 cytoscape.util;
+
+
+import java.util.Map;
+import java.util.TreeMap;
+
+
+public class ScalerFactory {
+       private static Map<String, Scaler> typeToScalerMap = null;
+
+       /**
+        *  @return one of the registered Scaler types.  Preregistered are 
"linear" and "rank".
+        */
+       public static synchronized Scaler getScaler(final String type) throws 
IllegalArgumentException {
+               if (typeToScalerMap == null)
+                       init();
+
+               final Scaler scaler = typeToScalerMap.get(type);
+               if (scaler == null)
+                       throw new IllegalArgumentException("unknown type \"" + 
type + "\"!");
+
+               return scaler;
+       }
+
+       public static synchronized void registerScaler(final String type, final 
Scaler newScaler) {
+               if (typeToScalerMap == null)
+                       init();
+
+               if (typeToScalerMap.containsKey(type))
+                       throw new IllegalArgumentException("trying to register 
a duplicate type \"" + type + "\"!");
+
+               typeToScalerMap.put(type, newScaler);
+       }
+
+       private static void init() {
+               if (typeToScalerMap != null)
+                       throw new IllegalStateException("already initialised!");
+               typeToScalerMap = new TreeMap<String, Scaler>();
+
+               typeToScalerMap.put("linear", new LinearScaler());
+               typeToScalerMap.put("rank", new RankScaler());
+       }
+}

Copied: cytoscape/trunk/tests/cytoscape/util/LinearScalerTest.java (from rev 
20541, cytoscape/trunk/tests/cytoscape/util/MathUtilTest.java)
===================================================================
--- cytoscape/trunk/tests/cytoscape/util/LinearScalerTest.java                  
        (rev 0)
+++ cytoscape/trunk/tests/cytoscape/util/LinearScalerTest.java  2010-06-15 
21:04:21 UTC (rev 20546)
@@ -0,0 +1,26 @@
+package cytoscape.util;
+
+
+import junit.framework.*;
+
+
+public class LinearScalerTest extends TestCase {
+       public void test() {
+               final Scaler linearScaler = new LinearScaler();
+               final double[] unscaledValues = new double[] { 3.0, 10.2, 5.4, 
3.0, 7.7 };
+               final double MIN = 0.0;
+               final double MAX = 1.0;
+               final double[] scaledValues = 
linearScaler.scale(unscaledValues, MIN, MAX);
+               boolean foundMin = false;
+               boolean foundMax = false;
+               for (final double d : scaledValues) {
+                       if (MathUtil.almostEqual(MIN, d))
+                               foundMin = true;
+                       if (MathUtil.almostEqual(MAX, d))
+                               foundMax = true;
+                       assertTrue(d >= MIN && d <= MAX);
+               }
+               assertTrue(foundMin);
+               assertTrue(foundMax);
+       }
+}
\ No newline at end of file

Deleted: cytoscape/trunk/tests/cytoscape/util/ProbabilityScalerTest.java
===================================================================
--- cytoscape/trunk/tests/cytoscape/util/ProbabilityScalerTest.java     
2010-06-15 20:15:40 UTC (rev 20545)
+++ cytoscape/trunk/tests/cytoscape/util/ProbabilityScalerTest.java     
2010-06-15 21:04:21 UTC (rev 20546)
@@ -1,108 +0,0 @@
-package cytoscape.util;
-
-
-import junit.framework.*;
-
-
-public class ProbabilityScalerTest extends TestCase {
-       public void testNoRanking() {
-               final float[] distinctValues = getDistinctValues();
-               final float[] unscaledValues1 = (float[])distinctValues.clone();
-
-               final StringBuilder errorMessage = new StringBuilder();
-               final float[] scaledValues1 = 
ProbabilityScaler.scale(distinctValues, ScalingMethod.NONE,
-                                                                     
errorMessage);
-
-               for (int i = 0; i < unscaledValues1.length; ++i)
-                       assertEquals(unscaledValues1[i], scaledValues1[i]);
-
-               final float[] valuesWithDups = getDistinctValues();
-               final float[] unscaledValues2 = (float[])valuesWithDups.clone();
-
-               final float[] scaledValues2 = 
ProbabilityScaler.scale(valuesWithDups, ScalingMethod.NONE,
-                                                                     
errorMessage);
-
-               for (int i = 0; i < unscaledValues2.length; ++i)
-                       assertEquals(unscaledValues2[i], scaledValues2[i]);
-       }
-
-       public void testLinearUpper() {
-               final float[] distinctValues = getDistinctValues();
-
-               final StringBuilder errorMessage = new StringBuilder();
-               final float [] scaledValues1 = 
ProbabilityScaler.scale(distinctValues, ScalingMethod.LINEAR_UPPER,
-                                                                      
errorMessage);
-               final float[] expectedValues1 = new float[] { 0.5999999f, 
0.6449999f, 0.74999994f, 0.9f };
-               for (int i = 0; i < expectedValues1.length; ++i)
-                       assertTrue(MathUtil.almostEqual(expectedValues1[i], 
scaledValues1[i]));
-
-               final float[] valuesWithDups = getValuesWithDups();
-               final float [] scaledValues2 = 
ProbabilityScaler.scale(valuesWithDups, ScalingMethod.LINEAR_UPPER,
-                                                                      
errorMessage);
-               final float[] expectedValues2 = new float[] { 0.5625f, 
0.61875f, 0.61875f, 0.61875f, 0.75f, 0.9375f, 0.9375f };
-               for (int i = 0; i < expectedValues2.length; ++i)
-                       assertTrue(MathUtil.almostEqual(expectedValues2[i], 
scaledValues2[i]));
-       }
-
-       public void testLinearLower() {
-               final float[] distinctValues = getDistinctValues();
-
-               final StringBuilder errorMessage = new StringBuilder();
-               final float [] scaledValues1 = 
ProbabilityScaler.scale(distinctValues, ScalingMethod.LINEAR_LOWER,
-                                                                      
errorMessage);
-               final float[] expectedValues1 = new float[] { 0.9f, 
0.85499996f, 0.74999994f, 0.5999999f };
-               for (int i = 0; i < expectedValues1.length; ++i)
-                       assertTrue(MathUtil.almostEqual(expectedValues1[i], 
scaledValues1[i]));
-
-               final float[] valuesWithDups = getValuesWithDups();
-               final float [] scaledValues2 = 
ProbabilityScaler.scale(valuesWithDups, ScalingMethod.LINEAR_LOWER,
-                                                                      
errorMessage);
-               final float[] expectedValues2 = new float[] { 0.9375f, 
0.88125f, 0.88125f, 0.88125f, 0.75f, 0.5625f, 0.5625f };
-               for (int i = 0; i < expectedValues2.length; ++i)
-                       assertTrue(MathUtil.almostEqual(expectedValues2[i], 
scaledValues2[i]));
-       }
-
-       public void testRankUpper() {
-               final float[] distinctValues = getDistinctValues();
-
-               final StringBuilder errorMessage = new StringBuilder();
-               final float [] scaledValues1 = 
ProbabilityScaler.scale(distinctValues, ScalingMethod.RANK_UPPER,
-                                                                      
errorMessage);
-               final float[] expectedValues1 = new float[] { 0.9375f, 0.8125f, 
0.6875f, 0.5625f };
-               for (int i = 0; i < expectedValues1.length; ++i)
-                       assertTrue(MathUtil.almostEqual(expectedValues1[i], 
scaledValues1[i]));
-
-               final float[] valuesWithDups = getValuesWithDups();
-               final float [] scaledValues2 = 
ProbabilityScaler.scale(valuesWithDups, ScalingMethod.RANK_UPPER,
-                                                                      
errorMessage);
-               final float[] expectedValues2 = new float[] { 0.96428573f, 
0.82142854f, 0.82142854f, 0.82142854f, 0.67857146f, 0.5714286f, 0.5714286f };
-               for (int i = 0; i < expectedValues2.length; ++i)
-                       assertTrue(MathUtil.almostEqual(expectedValues2[i], 
scaledValues2[i]));
-       }
-
-       public void testRankLower() {
-               final float[] distinctValues = getDistinctValues();
-
-               final StringBuilder errorMessage = new StringBuilder();
-               final float [] scaledValues1 = 
ProbabilityScaler.scale(distinctValues, ScalingMethod.RANK_LOWER,
-                                                                      
errorMessage);
-               final float[] expectedValues1 = new float[] { 0.5625f, 0.6875f, 
0.8125f, 0.9375f };
-               for (int i = 0; i < expectedValues1.length; ++i)
-                       assertTrue(MathUtil.almostEqual(expectedValues1[i], 
scaledValues1[i]));
-
-               final float[] valuesWithDups = getValuesWithDups();
-               final float [] scaledValues2 = 
ProbabilityScaler.scale(valuesWithDups, ScalingMethod.RANK_LOWER,
-                                                                      
errorMessage);
-               final float[] expectedValues2 = new float[] { 0.53571427f, 
0.67857146f, 0.67857146f, 0.67857146f, 0.82142854f, 0.92857146f };
-               for (int i = 0; i < expectedValues2.length; ++i)
-                       assertTrue(MathUtil.almostEqual(expectedValues2[i], 
scaledValues2[i]));
-       }
-
-       static private float[] getDistinctValues() {
-               return new float[] { 0.2f, 0.5f, 1.2f, 2.2f };
-       }
-
-       static private float[] getValuesWithDups() {
-               return new float[] { 0.2f, 0.5f, 0.5f, 0.5f, 1.2f, 2.2f, 2.2f };
-       }
-}

Copied: cytoscape/trunk/tests/cytoscape/util/RankScalerTest.java (from rev 
20541, cytoscape/trunk/tests/cytoscape/util/MathUtilTest.java)
===================================================================
--- cytoscape/trunk/tests/cytoscape/util/RankScalerTest.java                    
        (rev 0)
+++ cytoscape/trunk/tests/cytoscape/util/RankScalerTest.java    2010-06-15 
21:04:21 UTC (rev 20546)
@@ -0,0 +1,26 @@
+package cytoscape.util;
+
+
+import junit.framework.*;
+
+
+public class RankScalerTest extends TestCase {
+       public void test() {
+               final Scaler linearScaler = new RankScaler();
+               final double[] unscaledValues = new double[] { 3.0, 10.2, 5.4, 
3.0, 7.7 };
+               final double MIN = 0.0;
+               final double MAX = 1.0;
+               final double[] scaledValues = 
linearScaler.scale(unscaledValues, MIN, MAX);
+               boolean foundMin = false;
+               boolean foundMax = false;
+               for (final double d : scaledValues) {
+                       if (MathUtil.almostEqual(MIN, d))
+                               foundMin = true;
+                       if (MathUtil.almostEqual(MAX, d))
+                               foundMax = true;
+                       assertTrue(d >= MIN && d <= MAX);
+               }
+               assertFalse(foundMin);
+               assertFalse(foundMax);
+       }
+}
\ No newline at end of file

Copied: cytoscape/trunk/tests/cytoscape/util/ScalerFactoryTest.java (from rev 
20541, cytoscape/trunk/tests/cytoscape/util/MathUtilTest.java)
===================================================================
--- cytoscape/trunk/tests/cytoscape/util/ScalerFactoryTest.java                 
        (rev 0)
+++ cytoscape/trunk/tests/cytoscape/util/ScalerFactoryTest.java 2010-06-15 
21:04:21 UTC (rev 20546)
@@ -0,0 +1,24 @@
+package cytoscape.util;
+
+
+import junit.framework.*;
+
+
+public class ScalerFactoryTest extends TestCase {
+       public void testGetKnownScaler() {
+               final Scaler linearScaler = ScalerFactory.getScaler("linear");
+               assertTrue(linearScaler instanceof LinearScaler);
+
+               final Scaler rankScaler = ScalerFactory.getScaler("rank");
+               assertTrue(rankScaler instanceof RankScaler);
+       }
+
+       public void testGetUnknownScaler() {
+               try {
+                       final Scaler scaler = ScalerFactory.getScaler("random 
junk!#$");
+                       fail();
+               } catch (final IllegalArgumentException e) {
+                       assertTrue(true);
+               }
+       }
+}
\ No newline at end of file

-- 
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