commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1503623 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/FrequencyTest.java
Date Tue, 16 Jul 2013 09:15:33 GMT
Author: sebb
Date: Tue Jul 16 09:15:32 2013
New Revision: 1503623

URL: http://svn.apache.org/r1503623
Log:
Add some tests of NaNs

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/FrequencyTest.java

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/FrequencyTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/FrequencyTest.java?rev=1503623&r1=1503622&r2=1503623&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/FrequencyTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/FrequencyTest.java
Tue Jul 16 09:15:32 2013
@@ -24,6 +24,7 @@ import java.util.List;
 
 
 import org.apache.commons.math3.TestUtils;
+import org.apache.commons.math3.exception.MathIllegalArgumentException;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -357,5 +358,63 @@ public final class FrequencyTest {
         Assert.assertEquals("2", mode.get(0));
         Assert.assertFalse(mode.contains("1"));
         Assert.assertTrue(mode.contains("2"));
+
+        try {
+            f.addValue(Double.valueOf(Double.NaN));
+            Assert.fail("Expected MathIllegalArgumentException");
+        } catch (MathIllegalArgumentException e) {
+            // expected
+        }
     }
+
+    @Test
+    public void testModeDoubleNan() {
+        List<Comparable<?>> mode;
+        f.addValue(Double.valueOf(Double.NaN));
+        f.addValue(Double.valueOf(Double.NaN));
+        f.addValue(Double.valueOf(Double.NaN));
+        f.addValue(Double.valueOf(Double.NEGATIVE_INFINITY));
+        f.addValue(Double.valueOf(Double.POSITIVE_INFINITY));
+        f.addValue(Double.valueOf(Double.NEGATIVE_INFINITY));
+        f.addValue(Double.valueOf(Double.POSITIVE_INFINITY));
+        f.addValue(Double.valueOf(Double.NEGATIVE_INFINITY));
+        f.addValue(Double.valueOf(Double.POSITIVE_INFINITY));
+        mode = f.getMode();
+        Assert.assertEquals(3, mode.size());
+        Assert.assertEquals(Double.valueOf(Double.NEGATIVE_INFINITY), mode.get(0));
+        Assert.assertEquals(Double.valueOf(Double.POSITIVE_INFINITY), mode.get(1));
+        Assert.assertEquals(Double.valueOf(Double.NaN), mode.get(2));
+        try {
+            f.addValue(Float.valueOf(Float.NaN));
+            Assert.fail("Expected MathIllegalArgumentException");
+        } catch (MathIllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void testModeFloatNan() {
+        List<Comparable<?>> mode;
+        f.addValue(Float.valueOf(Float.NaN));
+        f.addValue(Float.valueOf(Float.NaN));
+        f.addValue(Float.valueOf(Float.NaN));
+        f.addValue(Float.valueOf(Float.NEGATIVE_INFINITY));
+        f.addValue(Float.valueOf(Float.POSITIVE_INFINITY));
+        f.addValue(Float.valueOf(Float.NEGATIVE_INFINITY));
+        f.addValue(Float.valueOf(Float.POSITIVE_INFINITY));
+        f.addValue(Float.valueOf(Float.NEGATIVE_INFINITY));
+        f.addValue(Float.valueOf(Float.POSITIVE_INFINITY));
+        mode = f.getMode();
+        Assert.assertEquals(3, mode.size());
+        Assert.assertEquals(Float.valueOf(Float.NEGATIVE_INFINITY), mode.get(0));
+        Assert.assertEquals(Float.valueOf(Float.POSITIVE_INFINITY), mode.get(1));
+        Assert.assertEquals(Float.valueOf(Float.NaN), mode.get(2));
+        try {
+            f.addValue(Double.valueOf(Double.NaN));
+            Assert.fail("Expected MathIllegalArgumentException");
+        } catch (MathIllegalArgumentException e) {
+            // expected
+        }
+    }
+
 }



Mime
View raw message