commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brentwor...@apache.org
Subject svn commit: r776939 - in /commons/proper/math/trunk/src/test/org/apache/commons/math: TestUtils.java stat/ranking/NaturalRankingTest.java
Date Thu, 21 May 2009 03:17:53 GMT
Author: brentworden
Date: Thu May 21 03:17:52 2009
New Revision: 776939

URL: http://svn.apache.org/viewvc?rev=776939&view=rev
Log:
re-enabled unit test.  changed testutils to use own assertEquals method to safely compare
NaN values.

Modified:
    commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/stat/ranking/NaturalRankingTest.java

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java?rev=776939&r1=776938&r2=776939&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java Thu May 21 03:17:52
2009
@@ -323,7 +323,7 @@
         boolean failure = false;
         for (int i=0; i < expected.length; i++) {
             try {
-                Assert.assertEquals(expected[i], observed[i], tolerance);
+                assertEquals(expected[i], observed[i], tolerance);
             } catch (AssertionFailedError ex) {
                 failure = true;
                 out.append("\n Elements at index ");

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/stat/ranking/NaturalRankingTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/ranking/NaturalRankingTest.java?rev=776939&r1=776938&r2=776939&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/stat/ranking/NaturalRankingTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/stat/ranking/NaturalRankingTest.java
Thu May 21 03:17:52 2009
@@ -1,6 +1,18 @@
 /*
- * TiesEquivalentRankTest.java created on Aug 24, 2005 by jdgant01
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
  */
 package org.apache.commons.math.stat.ranking;
 
@@ -17,175 +29,175 @@
  * @version $Revision:$ $Date:$
  */
 public class NaturalRankingTest extends TestCase {
-    
-    private final double[] exampleData = 
-    {20, 17, 30, 42.3, 17, 50, Double.NaN, Double.NEGATIVE_INFINITY, 17};
-    private final double[] tiesFirst = {0, 0, 2, 1, 4};
-    private final double[] tiesLast = {4, 4, 1, 0};
-    private final double[] multipleNaNs = {0, 1, Double.NaN, Double.NaN};
-    private final double[] multipleTies = {3, 2, 5, 5, 6, 6, 1};
-    private final double[] allSame = {0, 0, 0, 0};
-    
-    public NaturalRankingTest(String arg0) {
-        super(arg0);
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-    }
-    
-    public void testDefault() {  // Ties averaged, NaNs maximal
-        NaturalRanking ranking = new NaturalRanking();
-        double[] ranks = ranking.rank(exampleData);
-        double[] correctRanks = {5, 3, 6, 7, 3, 8, 9, 1, 3};
-        TestUtils.assertEquals(correctRanks, ranks, 0d); 
-        ranks = ranking.rank(tiesFirst);
-        correctRanks = new double[] {1.5, 1.5, 4, 3, 5};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(tiesLast);
-        correctRanks = new double[] {3.5, 3.5, 2, 1};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(multipleNaNs);
-        correctRanks = new double[] {1, 2, 3.5, 3.5};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(multipleTies);
-        correctRanks = new double[] {3, 2, 4.5, 4.5, 6.5, 6.5, 1};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(allSame);
-        correctRanks = new double[] {2.5, 2.5, 2.5, 2.5};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-    }
-    
-    public void testNaNsMaximalTiesMinimum() {
-        NaturalRanking ranking = new NaturalRanking(TiesStrategy.MINIMUM);
-        double[] ranks = ranking.rank(exampleData);
-        double[] correctRanks = {5, 2, 6, 7, 2, 8, 9, 1, 2};
-        TestUtils.assertEquals(correctRanks, ranks, 0d); 
-        ranks = ranking.rank(tiesFirst);
-        correctRanks = new double[] {1, 1, 4, 3, 5};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(tiesLast);
-        correctRanks = new double[] {3, 3, 2, 1};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(multipleNaNs);
-        correctRanks = new double[] {1, 2, 3, 3};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(multipleTies);
-        correctRanks = new double[] {3, 2, 4, 4, 6, 6, 1};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(allSame);
-        correctRanks = new double[] {1, 1, 1, 1};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-    }
-    
-    public void testNaNsRemovedTiesSequential() {
-        NaturalRanking ranking = new NaturalRanking(NaNStrategy.REMOVED, 
-                TiesStrategy.SEQUENTIAL);
-        double[] ranks = ranking.rank(exampleData);
-        double[] correctRanks = {5, 2, 6, 7, 3, 8, 1, 4};
-        TestUtils.assertEquals(correctRanks, ranks, 0d); 
-        ranks = ranking.rank(tiesFirst);
-        correctRanks = new double[] {1, 2, 4, 3, 5};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(tiesLast);
-        correctRanks = new double[] {3, 4, 2, 1};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(multipleNaNs);
-        correctRanks = new double[] {1, 2};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(multipleTies);
-        correctRanks = new double[] {3, 2, 4, 5, 6, 7, 1};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(allSame);
-        correctRanks = new double[] {1, 2, 3, 4};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-    }
-    
-    public void testNaNsMinimalTiesMaximum() {
-        NaturalRanking ranking = new NaturalRanking(NaNStrategy.MINIMAL, 
-                TiesStrategy.MAXIMUM);
-        double[] ranks = ranking.rank(exampleData);
-        double[] correctRanks = {6, 5, 7, 8, 5, 9, 2, 2, 5};
-        TestUtils.assertEquals(correctRanks, ranks, 0d); 
-        ranks = ranking.rank(tiesFirst);
-        correctRanks = new double[] {2, 2, 4, 3, 5};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(tiesLast);
-        correctRanks = new double[] {4, 4, 2, 1};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(multipleNaNs);
-        correctRanks = new double[] {3, 4, 2, 2};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(multipleTies);
-        correctRanks = new double[] {3, 2, 5, 5, 7, 7, 1};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(allSame);
-        correctRanks = new double[] {4, 4, 4, 4};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-    }
-    
-    public void testNaNsMinimalTiesAverage() {
-        NaturalRanking ranking = new NaturalRanking(NaNStrategy.MINIMAL);
-        double[] ranks = ranking.rank(exampleData);
-        double[] correctRanks = {6, 4, 7, 8, 4, 9, 1.5, 1.5, 4};
-        TestUtils.assertEquals(correctRanks, ranks, 0d); 
-        ranks = ranking.rank(tiesFirst);
-        correctRanks = new double[] {1.5, 1.5, 4, 3, 5};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(tiesLast);
-        correctRanks = new double[] {3.5, 3.5, 2, 1};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(multipleNaNs);
-        correctRanks = new double[] {3, 4, 1.5, 1.5};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(multipleTies);
-        correctRanks = new double[] {3, 2, 4.5, 4.5, 6.5, 6.5, 1};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(allSame);
-        correctRanks = new double[] {2.5, 2.5, 2.5, 2.5};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-    }
-    /**
-    public void testNaNsFixedTiesRandom() {
-        RandomGenerator randomGenerator = new JDKRandomGenerator();
-        randomGenerator.setSeed(1000);
-        NaturalRanking ranking = new NaturalRanking(NaNStrategy.FIXED,
-                randomGenerator);
-        double[] ranks = ranking.rank(exampleData);
-        double[] correctRanks = {5, 4, 6, 7, 3, 8, Double.NaN, 1, 4};
-        TestUtils.assertEquals(correctRanks, ranks, 0d); 
-        ranks = ranking.rank(tiesFirst);
-        correctRanks = new double[] {1, 1, 4, 3, 5};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(tiesLast);
-        correctRanks = new double[] {3, 4, 2, 1};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(multipleNaNs);
-        correctRanks = new double[] {1, 2, Double.NaN, Double.NaN};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(multipleTies);
-        correctRanks = new double[] {3, 2, 5, 5, 7, 6, 1};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranks = ranking.rank(allSame);
-        correctRanks = new double[] {1, 3, 4, 4};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);  
-    }
-    */
-    
-    public void testNaNsAndInfs() {
-        double[] data = {0, Double.POSITIVE_INFINITY, Double.NaN, Double.NEGATIVE_INFINITY};
-        NaturalRanking ranking = new NaturalRanking(NaNStrategy.MAXIMAL);
-        double[] ranks = ranking.rank(data);
-        double[] correctRanks = new double[] {2, 3.5, 3.5, 1};
-        TestUtils.assertEquals(correctRanks, ranks, 0d);
-        ranking = new NaturalRanking(NaNStrategy.MINIMAL);
-        ranks = ranking.rank(data);
-        correctRanks = new double[] {3, 4, 1.5, 1.5};
-    }
+
+	private final double[] exampleData = { 20, 17, 30, 42.3, 17, 50,
+			Double.NaN, Double.NEGATIVE_INFINITY, 17 };
+	private final double[] tiesFirst = { 0, 0, 2, 1, 4 };
+	private final double[] tiesLast = { 4, 4, 1, 0 };
+	private final double[] multipleNaNs = { 0, 1, Double.NaN, Double.NaN };
+	private final double[] multipleTies = { 3, 2, 5, 5, 6, 6, 1 };
+	private final double[] allSame = { 0, 0, 0, 0 };
+
+	public NaturalRankingTest(String arg0) {
+		super(arg0);
+	}
+
+	@Override
+	protected void setUp() throws Exception {
+		super.setUp();
+	}
+
+	@Override
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	public void testDefault() { // Ties averaged, NaNs maximal
+		NaturalRanking ranking = new NaturalRanking();
+		double[] ranks = ranking.rank(exampleData);
+		double[] correctRanks = { 5, 3, 6, 7, 3, 8, 9, 1, 3 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(tiesFirst);
+		correctRanks = new double[] { 1.5, 1.5, 4, 3, 5 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(tiesLast);
+		correctRanks = new double[] { 3.5, 3.5, 2, 1 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(multipleNaNs);
+		correctRanks = new double[] { 1, 2, 3.5, 3.5 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(multipleTies);
+		correctRanks = new double[] { 3, 2, 4.5, 4.5, 6.5, 6.5, 1 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(allSame);
+		correctRanks = new double[] { 2.5, 2.5, 2.5, 2.5 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+	}
+
+	public void testNaNsMaximalTiesMinimum() {
+		NaturalRanking ranking = new NaturalRanking(TiesStrategy.MINIMUM);
+		double[] ranks = ranking.rank(exampleData);
+		double[] correctRanks = { 5, 2, 6, 7, 2, 8, 9, 1, 2 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(tiesFirst);
+		correctRanks = new double[] { 1, 1, 4, 3, 5 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(tiesLast);
+		correctRanks = new double[] { 3, 3, 2, 1 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(multipleNaNs);
+		correctRanks = new double[] { 1, 2, 3, 3 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(multipleTies);
+		correctRanks = new double[] { 3, 2, 4, 4, 6, 6, 1 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(allSame);
+		correctRanks = new double[] { 1, 1, 1, 1 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+	}
+
+	public void testNaNsRemovedTiesSequential() {
+		NaturalRanking ranking = new NaturalRanking(NaNStrategy.REMOVED,
+				TiesStrategy.SEQUENTIAL);
+		double[] ranks = ranking.rank(exampleData);
+		double[] correctRanks = { 5, 2, 6, 7, 3, 8, 1, 4 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(tiesFirst);
+		correctRanks = new double[] { 1, 2, 4, 3, 5 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(tiesLast);
+		correctRanks = new double[] { 3, 4, 2, 1 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(multipleNaNs);
+		correctRanks = new double[] { 1, 2 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(multipleTies);
+		correctRanks = new double[] { 3, 2, 4, 5, 6, 7, 1 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(allSame);
+		correctRanks = new double[] { 1, 2, 3, 4 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+	}
+
+	public void testNaNsMinimalTiesMaximum() {
+		NaturalRanking ranking = new NaturalRanking(NaNStrategy.MINIMAL,
+				TiesStrategy.MAXIMUM);
+		double[] ranks = ranking.rank(exampleData);
+		double[] correctRanks = { 6, 5, 7, 8, 5, 9, 2, 2, 5 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(tiesFirst);
+		correctRanks = new double[] { 2, 2, 4, 3, 5 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(tiesLast);
+		correctRanks = new double[] { 4, 4, 2, 1 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(multipleNaNs);
+		correctRanks = new double[] { 3, 4, 2, 2 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(multipleTies);
+		correctRanks = new double[] { 3, 2, 5, 5, 7, 7, 1 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(allSame);
+		correctRanks = new double[] { 4, 4, 4, 4 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+	}
+
+	public void testNaNsMinimalTiesAverage() {
+		NaturalRanking ranking = new NaturalRanking(NaNStrategy.MINIMAL);
+		double[] ranks = ranking.rank(exampleData);
+		double[] correctRanks = { 6, 4, 7, 8, 4, 9, 1.5, 1.5, 4 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(tiesFirst);
+		correctRanks = new double[] { 1.5, 1.5, 4, 3, 5 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(tiesLast);
+		correctRanks = new double[] { 3.5, 3.5, 2, 1 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(multipleNaNs);
+		correctRanks = new double[] { 3, 4, 1.5, 1.5 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(multipleTies);
+		correctRanks = new double[] { 3, 2, 4.5, 4.5, 6.5, 6.5, 1 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(allSame);
+		correctRanks = new double[] { 2.5, 2.5, 2.5, 2.5 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+	}
+
+	public void testNaNsFixedTiesRandom() {
+		RandomGenerator randomGenerator = new JDKRandomGenerator();
+		randomGenerator.setSeed(1000);
+		NaturalRanking ranking = new NaturalRanking(NaNStrategy.FIXED,
+				randomGenerator);
+		double[] ranks = ranking.rank(exampleData);
+		double[] correctRanks = { 5, 4, 6, 7, 3, 8, Double.NaN, 1, 4 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(tiesFirst);
+		correctRanks = new double[] { 1, 1, 4, 3, 5 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(tiesLast);
+		correctRanks = new double[] { 3, 4, 2, 1 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(multipleNaNs);
+		correctRanks = new double[] { 1, 2, Double.NaN, Double.NaN };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(multipleTies);
+		correctRanks = new double[] { 3, 2, 5, 5, 7, 6, 1 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranks = ranking.rank(allSame);
+		correctRanks = new double[] { 1, 3, 4, 4 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+	}
+
+	public void testNaNsAndInfs() {
+		double[] data = { 0, Double.POSITIVE_INFINITY, Double.NaN,
+				Double.NEGATIVE_INFINITY };
+		NaturalRanking ranking = new NaturalRanking(NaNStrategy.MAXIMAL);
+		double[] ranks = ranking.rank(data);
+		double[] correctRanks = new double[] { 2, 3.5, 3.5, 1 };
+		TestUtils.assertEquals(correctRanks, ranks, 0d);
+		ranking = new NaturalRanking(NaNStrategy.MINIMAL);
+		ranks = ranking.rank(data);
+		correctRanks = new double[] { 3, 4, 1.5, 1.5 };
+	}
 }



Mime
View raw message