Repository: commons-math
Updated Branches:
  refs/heads/master b1d38d9bf -> 5c753a87c


MATH-1361: Unit test (disabled).

Example code that shows the issue.
Unit test set to "@Ignore" since it takes a long time (testing many seeds).


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/5c753a87
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/5c753a87
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/5c753a87

Branch: refs/heads/master
Commit: 5c753a87c328678f16bf89e0178448f04194f0b4
Parents: b1d38d9
Author: Gilles <[email protected]>
Authored: Tue Dec 13 10:58:45 2016 +0100
Committer: Gilles <[email protected]>
Committed: Tue Dec 13 10:58:45 2016 +0100

----------------------------------------------------------------------
 .../math4/stat/ranking/NaturalRankingTest.java  | 49 ++++++++++++++++++++
 1 file changed, 49 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/5c753a87/src/test/java/org/apache/commons/math4/stat/ranking/NaturalRankingTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/math4/stat/ranking/NaturalRankingTest.java 
b/src/test/java/org/apache/commons/math4/stat/ranking/NaturalRankingTest.java
index 137469a..b886c83 100644
--- 
a/src/test/java/org/apache/commons/math4/stat/ranking/NaturalRankingTest.java
+++ 
b/src/test/java/org/apache/commons/math4/stat/ranking/NaturalRankingTest.java
@@ -23,8 +23,11 @@ import org.apache.commons.math4.stat.ranking.NaNStrategy;
 import org.apache.commons.math4.stat.ranking.NaturalRanking;
 import org.apache.commons.math4.stat.ranking.TiesStrategy;
 import org.junit.Test;
+import org.junit.Ignore;
 import org.apache.commons.rng.UniformRandomProvider;
 import org.apache.commons.rng.simple.RandomSource;
+import org.apache.commons.rng.simple.JDKRandomBridge;
+
 
 /**
  * Test cases for NaturalRanking class
@@ -169,6 +172,52 @@ public class NaturalRankingTest {
         TestUtils.assertEquals(correctRanks, ranks, 0d);
     }
 
+    /*
+     * Cf. MATH-1361
+     * XXX To be removed when issue is fixed.
+     */
+    @Ignore
+    @Test
+    public void testNaNsFixedTiesRandomDEBUG() {
+        int count = 0;
+        final long start = 0;
+        final int num = 10000000;
+        final long max = start + num;
+        for (long i = start; i <= max; i++) {
+            UniformRandomProvider randomGenerator = 
RandomSource.create(RandomSource.MT, i);
+            NaturalRanking ranking = new NaturalRanking(NaNStrategy.FIXED,
+                                                        randomGenerator);
+            double[] ranks = ranking.rank(exampleData);
+            double[] correctRanks = { 5, 3, 6, 7, 3, 8, Double.NaN, 1, 2 };
+            if 
(!org.apache.commons.math4.util.MathArrays.equalsIncludingNaN(correctRanks, 
ranks)) continue;
+
+            ranks = ranking.rank(tiesFirst);
+            correctRanks = new double[] { 1, 2, 4, 3, 5 };
+            if 
(!org.apache.commons.math4.util.MathArrays.equalsIncludingNaN(correctRanks, 
ranks)) continue;
+
+            ranks = ranking.rank(tiesLast);
+            correctRanks = new double[] { 3, 3, 2, 1 };
+            if 
(!org.apache.commons.math4.util.MathArrays.equalsIncludingNaN(correctRanks, 
ranks)) continue;
+
+            ranks = ranking.rank(multipleNaNs);
+            correctRanks = new double[] { 1, 2, Double.NaN, Double.NaN };
+            if 
(!org.apache.commons.math4.util.MathArrays.equalsIncludingNaN(correctRanks, 
ranks)) continue;
+
+            ranks = ranking.rank(multipleTies);
+            correctRanks = new double[] { 3, 2, 4, 4, 6, 7, 1 };
+            if 
(!org.apache.commons.math4.util.MathArrays.equalsIncludingNaN(correctRanks, 
ranks)) continue;
+
+            ranks = ranking.rank(allSame);
+            correctRanks = new double[] { 2, 3, 3, 3 };
+            if 
(!org.apache.commons.math4.util.MathArrays.equalsIncludingNaN(correctRanks, 
ranks)) continue;
+
+            ++count;
+            //System.out.println("seed = " + i);
+            //break;
+        }
+        System.out.println("success rate = " + count + " / " + num);
+    }
+
     @Test
     public void testNaNsFixedTiesRandom() {
         UniformRandomProvider randomGenerator = 
RandomSource.create(RandomSource.JDK, 1000L);

Reply via email to