commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1411880 - in /commons/proper/math/trunk/src: changes/changes.xml main/java/org/apache/commons/math3/stat/ranking/NaturalRanking.java test/java/org/apache/commons/math3/stat/ranking/NaturalRankingTest.java
Date Tue, 20 Nov 2012 21:13:55 GMT
Author: tn
Date: Tue Nov 20 21:13:54 2012
New Revision: 1411880

URL: http://svn.apache.org/viewvc?rev=1411880&view=rev
Log:
[MATH-906] Use NaNStrategy.FAILED as default in NaturalRanking.

Modified:
    commons/proper/math/trunk/src/changes/changes.xml
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/ranking/NaturalRanking.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/ranking/NaturalRankingTest.java

Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1411880&r1=1411879&r2=1411880&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Tue Nov 20 21:13:54 2012
@@ -52,6 +52,9 @@ If the output is not quite correct, chec
   <body>
     <release version="3.1" date="TBD" description="
 ">
+      <action dev="tn" type="update" issue="MATH-906" due-to="Patrick Meyer">
+        Use "NaNStrategy#FAILED" as default strategy in "NaturalRanking".
+      </action>
       <action dev="erans" type="add" issue="MATH-899">
         Added a new "SynchronizedRandomGenerator" that wraps another
         "RandomGenerator" with all methods being synchronized, thus

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/ranking/NaturalRanking.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/ranking/NaturalRanking.java?rev=1411880&r1=1411879&r2=1411880&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/ranking/NaturalRanking.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/ranking/NaturalRanking.java
Tue Nov 20 21:13:54 2012
@@ -35,7 +35,7 @@ import org.apache.commons.math3.util.Fas
  * <p>NaNs are treated according to the configured {@link NaNStrategy} and ties
  * are handled using the selected {@link TiesStrategy}.
  * Configuration settings are supplied in optional constructor arguments.
- * Defaults are {@link NaNStrategy#MAXIMAL} and {@link TiesStrategy#AVERAGE},
+ * Defaults are {@link NaNStrategy#FAILED} and {@link TiesStrategy#AVERAGE},
  * respectively. When using {@link TiesStrategy#RANDOM}, a
  * {@link RandomGenerator} may be supplied as a constructor argument.</p>
  * <p>Examples:
@@ -72,7 +72,7 @@ import org.apache.commons.math3.util.Fas
 public class NaturalRanking implements RankingAlgorithm {
 
     /** default NaN strategy */
-    public static final NaNStrategy DEFAULT_NAN_STRATEGY = NaNStrategy.MAXIMAL;
+    public static final NaNStrategy DEFAULT_NAN_STRATEGY = NaNStrategy.FAILED;
 
     /** default ties strategy */
     public static final TiesStrategy DEFAULT_TIES_STRATEGY = TiesStrategy.AVERAGE;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/ranking/NaturalRankingTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/ranking/NaturalRankingTest.java?rev=1411880&r1=1411879&r2=1411880&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/ranking/NaturalRankingTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/ranking/NaturalRankingTest.java
Tue Nov 20 21:13:54 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.math3.stat.ranking;
 
+import junit.framework.Assert;
+
 import org.apache.commons.math3.TestUtils;
 import org.apache.commons.math3.exception.NotANumberException;
 import org.apache.commons.math3.random.JDKRandomGenerator;
@@ -40,20 +42,31 @@ public class NaturalRankingTest {
     private final double[] allSame = { 0, 0, 0, 0 };
 
     @Test
-    public void testDefault() { // Ties averaged, NaNs maximal
+    public void testDefault() { // Ties averaged, NaNs failed
         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);
+        double[] ranks;
+        
+        try {
+            ranks = ranking.rank(exampleData);
+            Assert.fail("expected NotANumberException due to NaNStrategy.FAILED");
+        } catch (NotANumberException e) {
+            // expected
+        }
+        
         ranks = ranking.rank(tiesFirst);
-        correctRanks = new double[] { 1.5, 1.5, 4, 3, 5 };
+        double[] 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);
+        
+        try {
+            ranks = ranking.rank(multipleNaNs);
+            Assert.fail("expected NotANumberException due to NaNStrategy.FAILED");
+        } catch (NotANumberException e) {
+            // expected
+        }
+        
         ranks = ranking.rank(multipleTies);
         correctRanks = new double[] { 3, 2, 4.5, 4.5, 6.5, 6.5, 1 };
         TestUtils.assertEquals(correctRanks, ranks, 0d);
@@ -64,7 +77,7 @@ public class NaturalRankingTest {
 
     @Test
     public void testNaNsMaximalTiesMinimum() {
-        NaturalRanking ranking = new NaturalRanking(TiesStrategy.MINIMUM);
+        NaturalRanking ranking = new NaturalRanking(NaNStrategy.MAXIMAL, TiesStrategy.MINIMUM);
         double[] ranks = ranking.rank(exampleData);
         double[] correctRanks = { 5, 2, 6, 7, 2, 8, 9, 1, 2 };
         TestUtils.assertEquals(correctRanks, ranks, 0d);



Mime
View raw message