Repository: commons-math Updated Branches: refs/heads/MATH_3_X 654d7232e -> ff35e6f27
http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/FrequencyTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/FrequencyTest.java b/src/test/java/org/apache/commons/math3/stat/FrequencyTest.java index 6e4b56d..e2e73a8 100644 --- a/src/test/java/org/apache/commons/math3/stat/FrequencyTest.java +++ b/src/test/java/org/apache/commons/math3/stat/FrequencyTest.java @@ -254,7 +254,7 @@ public final class FrequencyTest { Assert.assertEquals("Integer 1 cumPct", 0.5, f.getCumPct(1), TOLERANCE); Assert.assertEquals("Integer 1 cumPct", 0.5, f.getCumPct(Long.valueOf(1)), TOLERANCE); Assert.assertEquals("Integer 1 cumPct", 0.5, f.getCumPct(Integer.valueOf(1)), TOLERANCE); - + f.incrementValue(ONE, -2); f.incrementValue(THREE, 5); @@ -264,7 +264,7 @@ public final class FrequencyTest { Iterator<?> it = f.valuesIterator(); while (it.hasNext()) { Assert.assertTrue(it.next() instanceof Long); - } + } } @Test @@ -275,7 +275,7 @@ public final class FrequencyTest { f.addValue(TWO); Assert.assertEquals(f, TestUtils.serializeAndRecover(f)); } - + @Test public void testGetUniqueCount() { Assert.assertEquals(0, f.getUniqueCount()); @@ -286,7 +286,7 @@ public final class FrequencyTest { f.addValue(TWO); Assert.assertEquals(2, f.getUniqueCount()); } - + @Test public void testIncrement() { Assert.assertEquals(0, f.getUniqueCount()); @@ -295,10 +295,10 @@ public final class FrequencyTest { f.incrementValue(ONE_LONG, 4); Assert.assertEquals(5, f.getCount(ONE_LONG)); - + f.incrementValue(ONE_LONG, -5); Assert.assertEquals(0, f.getCount(ONE_LONG)); - + try { f.incrementValue(CHAR_A, 1); Assert.fail("Expecting IllegalArgumentException"); @@ -308,7 +308,7 @@ public final class FrequencyTest { f = new Frequency(); f.incrementValue(CHAR_A, 2); - + Assert.assertEquals(2, f.getCount(CHAR_A)); try { @@ -317,12 +317,12 @@ public final class FrequencyTest { } catch (IllegalArgumentException ex) { // expected } - + f.incrementValue(CHAR_A, 3); Assert.assertEquals(5, f.getCount(CHAR_A)); } - + @Test public void testMerge() { Assert.assertEquals(0, f.getUniqueCount()); @@ -330,7 +330,7 @@ public final class FrequencyTest { f.addValue(TWO_LONG); f.addValue(ONE); f.addValue(TWO); - + Assert.assertEquals(2, f.getUniqueCount()); Assert.assertEquals(2, f.getCount(ONE)); Assert.assertEquals(2, f.getCount(TWO)); @@ -345,18 +345,18 @@ public final class FrequencyTest { Assert.assertEquals(2, g.getCount(THREE)); f.merge(g); - + Assert.assertEquals(3, f.getUniqueCount()); Assert.assertEquals(3, f.getCount(ONE)); Assert.assertEquals(2, f.getCount(TWO)); - Assert.assertEquals(2, f.getCount(THREE)); + Assert.assertEquals(2, f.getCount(THREE)); } - + @Test public void testMergeCollection() { Assert.assertEquals(0, f.getUniqueCount()); f.addValue(ONE_LONG); - + Assert.assertEquals(1, f.getUniqueCount()); Assert.assertEquals(1, f.getCount(ONE)); Assert.assertEquals(0, f.getCount(TWO)); @@ -366,18 +366,18 @@ public final class FrequencyTest { Frequency h = new Frequency(); h.addValue(THREE_LONG); - + List<Frequency> coll = new ArrayList<Frequency>(); coll.add(g); coll.add(h); f.merge(coll); - + Assert.assertEquals(3, f.getUniqueCount()); Assert.assertEquals(1, f.getCount(ONE)); Assert.assertEquals(1, f.getCount(TWO)); - Assert.assertEquals(1, f.getCount(THREE)); + Assert.assertEquals(1, f.getCount(THREE)); } - + @Test public void testMode() { List<Comparable<?>> mode; http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/StatUtilsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/StatUtilsTest.java b/src/test/java/org/apache/commons/math3/stat/StatUtilsTest.java index dccb7b6..1a76482 100644 --- a/src/test/java/org/apache/commons/math3/stat/StatUtilsTest.java +++ b/src/test/java/org/apache/commons/math3/stat/StatUtilsTest.java @@ -269,7 +269,7 @@ public final class StatUtilsTest { x = new double[] {ONE, TWO, TWO, THREE}; TestUtils.assertEquals(0.5, StatUtils.variance(x,2.5, 2, 2), TOLERANCE); } - + @Test public void testPopulationVariance() { double[] x = null; @@ -461,10 +461,10 @@ public final class StatUtilsTest { Assert.assertEquals(FastMath.exp(0.5 * StatUtils.sumLog(test, 0, 2)), StatUtils.geometricMean(test, 0, 2), Double.MIN_VALUE); } - - + + /** - * Run the test with the values 50 and 100 and assume standardized values + * Run the test with the values 50 and 100 and assume standardized values */ @Test @@ -485,7 +485,7 @@ public final class StatUtilsTest { @Test public void testNormalize2() { - // create an sample with 77 values + // create an sample with 77 values int length = 77; double sample[] = new double[length]; for (int i = 0; i < length; i++) { @@ -499,14 +499,14 @@ public final class StatUtilsTest { for (int i = 0; i < length; i++) { stats.addValue(standardizedSample[i]); } - // the calculations do have a limited precision + // the calculations do have a limited precision double distance = 1E-10; // check the mean an standard deviation Assert.assertEquals(0.0, stats.getMean(), distance); Assert.assertEquals(1.0, stats.getStandardDeviation(), distance); } - + @Test public void testMode() { final double[] singleMode = {0, 1, 0, 2, 7, 11, 12}; @@ -542,7 +542,7 @@ public final class StatUtilsTest { final double[] nansOnly = {Double.NaN, Double.NaN}; final double[] modeNansOnly = StatUtils.mode(nansOnly); Assert.assertEquals(0, modeNansOnly.length); - + final double[] nullArray = null; try { StatUtils.mode(nullArray); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/clustering/DBSCANClustererTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/clustering/DBSCANClustererTest.java b/src/test/java/org/apache/commons/math3/stat/clustering/DBSCANClustererTest.java index 657e2de..1c10490 100644 --- a/src/test/java/org/apache/commons/math3/stat/clustering/DBSCANClustererTest.java +++ b/src/test/java/org/apache/commons/math3/stat/clustering/DBSCANClustererTest.java @@ -147,19 +147,19 @@ public class DBSCANClustererTest { new EuclideanIntegerPoint(new int[] {14, 8}), // C new EuclideanIntegerPoint(new int[] {7, 15}), // N - Noise, should not be present new EuclideanIntegerPoint(new int[] {17, 8}), // D - single-link connected to C should not be present - + }; - + final DBSCANClusterer<EuclideanIntegerPoint> clusterer = new DBSCANClusterer<EuclideanIntegerPoint>(3, 3); List<Cluster<EuclideanIntegerPoint>> clusters = clusterer.cluster(Arrays.asList(points)); - + Assert.assertEquals(1, clusters.size()); - + final List<EuclideanIntegerPoint> clusterOne = Arrays.asList(points[0], points[1], points[2], points[3], points[4], points[5], points[6], points[7]); Assert.assertTrue(clusters.get(0).getPoints().containsAll(clusterOne)); } - + @Test public void testGetEps() { final DBSCANClusterer<EuclideanDoublePoint> transformer = new DBSCANClusterer<EuclideanDoublePoint>(2.0, 5); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/clustering/KMeansPlusPlusClustererTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/clustering/KMeansPlusPlusClustererTest.java b/src/test/java/org/apache/commons/math3/stat/clustering/KMeansPlusPlusClustererTest.java index d14f77b..4247992 100644 --- a/src/test/java/org/apache/commons/math3/stat/clustering/KMeansPlusPlusClustererTest.java +++ b/src/test/java/org/apache/commons/math3/stat/clustering/KMeansPlusPlusClustererTest.java @@ -248,16 +248,16 @@ public class KMeansPlusPlusClustererTest { } Assert.assertTrue(uniquePointIsCenter); } - + /** * 2 variables cannot be clustered into 3 clusters. See issue MATH-436. */ @Test(expected=NumberIsTooSmallException.class) public void testPerformClusterAnalysisToManyClusters() { - KMeansPlusPlusClusterer<EuclideanIntegerPoint> transformer = + KMeansPlusPlusClusterer<EuclideanIntegerPoint> transformer = new KMeansPlusPlusClusterer<EuclideanIntegerPoint>( new Random(1746432956321l)); - + EuclideanIntegerPoint[] points = new EuclideanIntegerPoint[] { new EuclideanIntegerPoint(new int[] { 1959, 325100 @@ -265,7 +265,7 @@ public class KMeansPlusPlusClustererTest { 1960, 373200 }) }; - + transformer.cluster(Arrays.asList(points), 3, 1); } http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/correlation/SpearmansRankCorrelationTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/correlation/SpearmansRankCorrelationTest.java b/src/test/java/org/apache/commons/math3/stat/correlation/SpearmansRankCorrelationTest.java index 36b0c56..e75b0b9 100644 --- a/src/test/java/org/apache/commons/math3/stat/correlation/SpearmansRankCorrelationTest.java +++ b/src/test/java/org/apache/commons/math3/stat/correlation/SpearmansRankCorrelationTest.java @@ -127,7 +127,7 @@ public class SpearmansRankCorrelationTest extends PearsonsCorrelationTest { NaturalRanking ranking = new NaturalRanking(NaNStrategy.REMOVED); SpearmansCorrelation spearman = new SpearmansCorrelation(ranking); - + Assert.assertEquals(0.5, spearman.correlation(xArray, yArray), Double.MIN_VALUE); } @@ -145,7 +145,7 @@ public class SpearmansRankCorrelationTest extends PearsonsCorrelationTest { // compute correlation NaturalRanking ranking = new NaturalRanking(NaNStrategy.REMOVED); SpearmansCorrelation spearman = new SpearmansCorrelation(matrix, ranking); - + Assert.assertEquals(0.5, spearman.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE); } http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/correlation/StorelessCovarianceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/correlation/StorelessCovarianceTest.java b/src/test/java/org/apache/commons/math3/stat/correlation/StorelessCovarianceTest.java index 06052e9..b8b85a8 100644 --- a/src/test/java/org/apache/commons/math3/stat/correlation/StorelessCovarianceTest.java +++ b/src/test/java/org/apache/commons/math3/stat/correlation/StorelessCovarianceTest.java @@ -221,7 +221,7 @@ public class StorelessCovarianceTest { } } } - + /** * Test equality of covariance. chk: covariance of two * samples separately and adds them together. cov: computes @@ -232,22 +232,22 @@ public class StorelessCovarianceTest { int num_sets = 2; StorelessBivariateCovariance cov = new StorelessBivariateCovariance();// covariance of the superset StorelessBivariateCovariance chk = new StorelessBivariateCovariance();// check covariance made by appending covariance of subsets - + ISAACRandom rand = new ISAACRandom(10L);// Seed can be changed for (int s = 0; s < num_sets; s++) {// loop through sets of samlpes StorelessBivariateCovariance covs = new StorelessBivariateCovariance(); for (int i = 0; i < 5; i++) { // loop through individual samlpes. double x = rand.nextDouble(); double y = rand.nextDouble(); - covs.increment(x, y);// add sample to the subset + covs.increment(x, y);// add sample to the subset cov.increment(x, y);// add sample to the superset } chk.append(covs); } - + TestUtils.assertEquals("covariance subset test", chk.getResult(), cov.getResult(), 10E-7); } - + protected RealMatrix createRealMatrix(double[] data, int nRows, int nCols) { double[][] matrixData = new double[nRows][nCols]; int ptr = 0; http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/descriptive/DescriptiveStatisticsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/descriptive/DescriptiveStatisticsTest.java b/src/test/java/org/apache/commons/math3/stat/descriptive/DescriptiveStatisticsTest.java index d9e6aa9..f573b19 100644 --- a/src/test/java/org/apache/commons/math3/stat/descriptive/DescriptiveStatisticsTest.java +++ b/src/test/java/org/apache/commons/math3/stat/descriptive/DescriptiveStatisticsTest.java @@ -224,7 +224,7 @@ public class DescriptiveStatisticsTest { checkremoval(dstat, DescriptiveStatistics.INFINITE_WINDOW, 3.5, 2.5, 3.0); } - + @Test public void testSummaryConsistency() { final DescriptiveStatistics dstats = new DescriptiveStatistics(); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/descriptive/StatisticalSummaryValuesTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/descriptive/StatisticalSummaryValuesTest.java b/src/test/java/org/apache/commons/math3/stat/descriptive/StatisticalSummaryValuesTest.java index e3b766e..581c97b 100644 --- a/src/test/java/org/apache/commons/math3/stat/descriptive/StatisticalSummaryValuesTest.java +++ b/src/test/java/org/apache/commons/math3/stat/descriptive/StatisticalSummaryValuesTest.java @@ -64,7 +64,7 @@ public final class StatisticalSummaryValuesTest { TestUtils.assertEquals("min",s.getMin(),u.getMin(), 0); TestUtils.assertEquals("max",s.getMax(),u.getMax(), 0); } - + @Test public void testToString() { StatisticalSummaryValues u = new StatisticalSummaryValues(4.5, 16, 10, 5, 4, 45); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/descriptive/StorelessUnivariateStatisticAbstractTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/descriptive/StorelessUnivariateStatisticAbstractTest.java b/src/test/java/org/apache/commons/math3/stat/descriptive/StorelessUnivariateStatisticAbstractTest.java index c42b80e..4deca7e 100644 --- a/src/test/java/org/apache/commons/math3/stat/descriptive/StorelessUnivariateStatisticAbstractTest.java +++ b/src/test/java/org/apache/commons/math3/stat/descriptive/StorelessUnivariateStatisticAbstractTest.java @@ -74,7 +74,7 @@ public abstract class StorelessUnivariateStatisticAbstractTest protected void checkClearValue(StorelessUnivariateStatistic statistic){ Assert.assertTrue(Double.isNaN(statistic.getResult())); } - + @Test public void testSerialization() { http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/descriptive/SummaryStatisticsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/descriptive/SummaryStatisticsTest.java b/src/test/java/org/apache/commons/math3/stat/descriptive/SummaryStatisticsTest.java index e1a1f98..90786ec 100644 --- a/src/test/java/org/apache/commons/math3/stat/descriptive/SummaryStatisticsTest.java +++ b/src/test/java/org/apache/commons/math3/stat/descriptive/SummaryStatisticsTest.java @@ -296,7 +296,7 @@ public class SummaryStatisticsTest { // expected } } - + @Test public void testQuadraticMean() { final double[] values = { 1.2, 3.4, 5.6, 7.89 }; @@ -314,7 +314,7 @@ public class SummaryStatisticsTest { Assert.assertEquals(expected, stats.getQuadraticMean(), Math.ulp(expected)); } - + /** * JIRA: MATH-691 */ @@ -326,31 +326,31 @@ public class SummaryStatisticsTest { for(double i : scores) { stats.addValue(i); } - Assert.assertEquals((new Variance(false)).evaluate(scores),stats.getVariance(), 0); + Assert.assertEquals((new Variance(false)).evaluate(scores),stats.getVariance(), 0); } - + @Test public void testOverrideMeanWithMathClass() { double[] scores = {1, 2, 3, 4}; SummaryStatistics stats = new SummaryStatistics(); - stats.setMeanImpl(new Mean()); + stats.setMeanImpl(new Mean()); for(double i : scores) { stats.addValue(i); } - Assert.assertEquals((new Mean()).evaluate(scores),stats.getMean(), 0); + Assert.assertEquals((new Mean()).evaluate(scores),stats.getMean(), 0); } - + @Test public void testOverrideGeoMeanWithMathClass() { double[] scores = {1, 2, 3, 4}; SummaryStatistics stats = new SummaryStatistics(); - stats.setGeoMeanImpl(new GeometricMean()); + stats.setGeoMeanImpl(new GeometricMean()); for(double i : scores) { stats.addValue(i); } - Assert.assertEquals((new GeometricMean()).evaluate(scores),stats.getGeometricMean(), 0); + Assert.assertEquals((new GeometricMean()).evaluate(scores),stats.getGeometricMean(), 0); } - + @Test public void testToString() { SummaryStatistics u = createSummaryStatistics(); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/descriptive/UnivariateStatisticAbstractTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/descriptive/UnivariateStatisticAbstractTest.java b/src/test/java/org/apache/commons/math3/stat/descriptive/UnivariateStatisticAbstractTest.java index ac15c85..2d8d2d8 100644 --- a/src/test/java/org/apache/commons/math3/stat/descriptive/UnivariateStatisticAbstractTest.java +++ b/src/test/java/org/apache/commons/math3/stat/descriptive/UnivariateStatisticAbstractTest.java @@ -100,7 +100,7 @@ public abstract class UnivariateStatisticAbstractTest { getUnivariateStatistic().evaluate(testArray), getTolerance()); } - + @Test public void testEvaluateArraySegment() { final UnivariateStatistic stat = getUnivariateStatistic(); @@ -114,7 +114,7 @@ public abstract class UnivariateStatisticAbstractTest { System.arraycopy(testArray, testArray.length - 5, arrayEnd, 0, 5); Assert.assertEquals(stat.evaluate(arrayEnd), stat.evaluate(testArray, testArray.length - 5, 5), 0); } - + @Test public void testEvaluateArraySegmentWeighted() { // See if this statistic computes weighted statistics http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/descriptive/rank/PSquarePercentileTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/descriptive/rank/PSquarePercentileTest.java b/src/test/java/org/apache/commons/math3/stat/descriptive/rank/PSquarePercentileTest.java index 8f7295a..68d9e08 100644 --- a/src/test/java/org/apache/commons/math3/stat/descriptive/rank/PSquarePercentileTest.java +++ b/src/test/java/org/apache/commons/math3/stat/descriptive/rank/PSquarePercentileTest.java @@ -41,7 +41,7 @@ import org.junit.Test; /** * Test cases for the {@link PSquarePercentile} class which naturally extends - * {@link StorelessUnivariateStatisticAbstractTest}. + * {@link StorelessUnivariateStatisticAbstractTest}. */ public class PSquarePercentileTest extends StorelessUnivariateStatisticAbstractTest { @@ -49,7 +49,7 @@ public class PSquarePercentileTest extends protected double percentile5 = 8.2299d; protected double percentile95 = 16.72195;// 20.82d; this is approximation protected double tolerance = 10E-12; - + private final RandomGenerator randomGenerator = new Well19937c(1000); @Override http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/descriptive/rank/PercentileTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/descriptive/rank/PercentileTest.java b/src/test/java/org/apache/commons/math3/stat/descriptive/rank/PercentileTest.java index 5381213..b380417 100644 --- a/src/test/java/org/apache/commons/math3/stat/descriptive/rank/PercentileTest.java +++ b/src/test/java/org/apache/commons/math3/stat/descriptive/rank/PercentileTest.java @@ -785,12 +785,12 @@ public class PercentileTest extends UnivariateStatisticAbstractTest{ Assert.assertEquals(2d,new Percentile(50d).withEstimationType(Percentile.EstimationType.R_1).withNaNStrategy(NaNStrategy.REMOVED).evaluate(specialValues),0d); Assert.assertEquals(Double.NaN,new Percentile(50d).withEstimationType(Percentile.EstimationType.R_5).withNaNStrategy(NaNStrategy.REMOVED).evaluate(new double[] {Double.NaN,Double.NaN,Double.NaN}),0d); Assert.assertEquals(50d,new Percentile(50d).withEstimationType(Percentile.EstimationType.R_7).withNaNStrategy(NaNStrategy.MINIMAL).evaluate(new double[] {50d,50d,50d},1,2),0d); - + specialValues = new double[] { 0d, 1d, 2d, 3d, 4d, Double.NaN, Double.NaN }; Assert.assertEquals(3.5,new Percentile().evaluate(specialValues, 3, 4),0d); Assert.assertEquals(4d,new Percentile().evaluate(specialValues, 4, 3),0d); Assert.assertTrue(Double.isNaN(new Percentile().evaluate(specialValues, 5, 2))); - + specialValues = new double[] { 0d, 1d, 2d, 3d, 4d, Double.NaN, Double.NaN, 5d, 6d }; Assert.assertEquals(4.5,new Percentile().evaluate(specialValues, 3, 6),0d); Assert.assertEquals(5d,new Percentile().evaluate(specialValues, 4, 5),0d); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/descriptive/summary/ProductTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/descriptive/summary/ProductTest.java b/src/test/java/org/apache/commons/math3/stat/descriptive/summary/ProductTest.java index 7dcaa7c..106286b 100644 --- a/src/test/java/org/apache/commons/math3/stat/descriptive/summary/ProductTest.java +++ b/src/test/java/org/apache/commons/math3/stat/descriptive/summary/ProductTest.java @@ -80,7 +80,7 @@ public class ProductTest extends StorelessUnivariateStatisticAbstractTest{ Assert.assertEquals(expectedWeightedValue(), product.evaluate(testArray, testWeightsArray, 0, testArray.length),getTolerance()); Assert.assertEquals(expectedValue(), product.evaluate(testArray, unitWeightsArray, 0, testArray.length), getTolerance()); } - + @Override protected void checkClearValue(StorelessUnivariateStatistic statistic){ Assert.assertEquals(1, statistic.getResult(), 0); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/descriptive/summary/SumLogTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/descriptive/summary/SumLogTest.java b/src/test/java/org/apache/commons/math3/stat/descriptive/summary/SumLogTest.java index ad3576a..bab0577 100644 --- a/src/test/java/org/apache/commons/math3/stat/descriptive/summary/SumLogTest.java +++ b/src/test/java/org/apache/commons/math3/stat/descriptive/summary/SumLogTest.java @@ -75,11 +75,11 @@ public class SumLogTest extends StorelessUnivariateStatisticAbstractTest{ sum.increment(-2d); Assert.assertTrue(Double.isNaN(sum.getResult())); } - + @Override protected void checkClearValue(StorelessUnivariateStatistic statistic){ Assert.assertEquals(0, statistic.getResult(), 0); } - + } http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/descriptive/summary/SumSqTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/descriptive/summary/SumSqTest.java b/src/test/java/org/apache/commons/math3/stat/descriptive/summary/SumSqTest.java index b19ca4e..d0760a6 100644 --- a/src/test/java/org/apache/commons/math3/stat/descriptive/summary/SumSqTest.java +++ b/src/test/java/org/apache/commons/math3/stat/descriptive/summary/SumSqTest.java @@ -61,7 +61,7 @@ public class SumSqTest extends StorelessUnivariateStatisticAbstractTest{ sumSq.increment(1); Assert.assertTrue(Double.isNaN(sumSq.getResult())); } - + @Override protected void checkClearValue(StorelessUnivariateStatistic statistic){ Assert.assertEquals(0, statistic.getResult(), 0); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/descriptive/summary/SumTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/descriptive/summary/SumTest.java b/src/test/java/org/apache/commons/math3/stat/descriptive/summary/SumTest.java index 87a3f5e..08a13f3 100644 --- a/src/test/java/org/apache/commons/math3/stat/descriptive/summary/SumTest.java +++ b/src/test/java/org/apache/commons/math3/stat/descriptive/summary/SumTest.java @@ -70,7 +70,7 @@ public class SumTest extends StorelessUnivariateStatisticAbstractTest{ Assert.assertEquals(expectedWeightedValue(), sum.evaluate(testArray, testWeightsArray, 0, testArray.length), getTolerance()); Assert.assertEquals(expectedValue(), sum.evaluate(testArray, unitWeightsArray, 0, testArray.length), getTolerance()); } - + @Override protected void checkClearValue(StorelessUnivariateStatistic statistic){ Assert.assertEquals(0, statistic.getResult(), 0); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/inference/GTestTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/inference/GTestTest.java b/src/test/java/org/apache/commons/math3/stat/inference/GTestTest.java index 228f0ce..ef606f4 100644 --- a/src/test/java/org/apache/commons/math3/stat/inference/GTestTest.java +++ b/src/test/java/org/apache/commons/math3/stat/inference/GTestTest.java @@ -180,7 +180,7 @@ public class GTestTest { // expected } } - + @Test public void testUnmatchedArrays() { final long[] observed = { 0, 1, 2, 3 }; @@ -199,7 +199,7 @@ public class GTestTest { // expected } } - + @Test public void testNegativeObservedCounts() { final long[] observed = { 0, 1, 2, -3 }; @@ -216,9 +216,9 @@ public class GTestTest { Assert.fail("negative observed count, NotPositiveException expected"); } catch (NotPositiveException ex) { // expected - } + } } - + @Test public void testZeroExpectedCounts() { final long[] observed = { 0, 1, 2, -3 }; @@ -230,7 +230,7 @@ public class GTestTest { // expected } } - + @Test public void testBadAlpha() { final long[] observed = { 0, 1, 2, 3 }; @@ -247,9 +247,9 @@ public class GTestTest { Assert.fail("zero expected count, NotStrictlyPositiveException expected"); } catch (OutOfRangeException ex) { // expected - } + } } - + @Test public void testScaling() { final long[] observed = {9, 11, 10, 8, 12}; http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java b/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java index e46f8c5..e72d1a6 100644 --- a/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java +++ b/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java @@ -37,11 +37,11 @@ public class MannWhitneyUTestTest { * x <- c(19, 22, 16, 29, 24) * y <- c(20, 11, 17, 12) * wilcox.test(x, y, alternative = "two.sided", mu = 0, paired = FALSE, exact = FALSE, correct = FALSE) - * W = 17, p-value = 0.08641 + * W = 17, p-value = 0.08641 */ final double x[] = {19, 22, 16, 29, 24}; final double y[] = {20, 11, 17, 12}; - + Assert.assertEquals(17, testStatistic.mannWhitneyU(x, y), 1e-10); Assert.assertEquals(0.08641, testStatistic.mannWhitneyUTest(x, y), 1e-5); } @@ -74,14 +74,14 @@ public class MannWhitneyUTestTest { } catch (NullArgumentException ex) { // expected } - + try { testStatistic.mannWhitneyUTest(null, null); Assert.fail("x and y is null (asymptotic), NullArgumentException expected"); } catch (NullArgumentException ex) { // expected } - + /* * x or y is null */ @@ -91,7 +91,7 @@ public class MannWhitneyUTestTest { } catch (NullArgumentException ex) { // expected } - + try { testStatistic.mannWhitneyUTest(new double[] { 1.0 }, null); Assert.fail("y is null (exact), NullArgumentException expected"); @@ -99,7 +99,7 @@ public class MannWhitneyUTestTest { // expected } } - + @Test public void testBigDataSet() { double[] d1 = new double[1500]; @@ -111,7 +111,7 @@ public class MannWhitneyUTestTest { double result = testStatistic.mannWhitneyUTest(d1, d2); Assert.assertTrue(result > 0.1); } - + @Test public void testBigDataSetOverflow() { // MATH-1145 http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/inference/TestUtilsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/inference/TestUtilsTest.java b/src/test/java/org/apache/commons/math3/stat/inference/TestUtilsTest.java index 69bd58a..d3785f5 100644 --- a/src/test/java/org/apache/commons/math3/stat/inference/TestUtilsTest.java +++ b/src/test/java/org/apache/commons/math3/stat/inference/TestUtilsTest.java @@ -528,7 +528,7 @@ public class TestUtilsTest { Assert.assertEquals(FastMath.sqrt(5734.343), TestUtils.rootLogLikelihoodRatio(1000, 1000, 1000, 100000), 0.001); Assert.assertEquals(FastMath.sqrt(5714.932), TestUtils.rootLogLikelihoodRatio(1000, 1000, 1000, 99000), 0.001); } - + @Test public void testKSOneSample() throws Exception { final NormalDistribution unitNormal = new NormalDistribution(0d, 1d); @@ -537,7 +537,7 @@ public class TestUtilsTest { Assert.assertEquals(0.3172069207622391, TestUtils.kolmogorovSmirnovTest(unitNormal, sample), tol); Assert.assertEquals(0.0932947561266756, TestUtils.kolmogorovSmirnovStatistic(unitNormal, sample), tol); } - + @Test public void testKSTwoSample() throws Exception { final double tol = KolmogorovSmirnovTestTest.TOLERANCE; @@ -552,6 +552,6 @@ public class TestUtilsTest { final double d = TestUtils.kolmogorovSmirnovStatistic(smallSample1, smallSample2); Assert.assertEquals(0.5, d, tol); Assert - .assertEquals(0.105577085453247, TestUtils.exactP(d, smallSample1.length,smallSample2.length, false), tol); + .assertEquals(0.105577085453247, TestUtils.exactP(d, smallSample1.length,smallSample2.length, false), tol); } } http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/inference/WilcoxonSignedRankTestTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/inference/WilcoxonSignedRankTestTest.java b/src/test/java/org/apache/commons/math3/stat/inference/WilcoxonSignedRankTestTest.java index 23ad58b..b273ecb 100644 --- a/src/test/java/org/apache/commons/math3/stat/inference/WilcoxonSignedRankTestTest.java +++ b/src/test/java/org/apache/commons/math3/stat/inference/WilcoxonSignedRankTestTest.java @@ -41,28 +41,28 @@ public class WilcoxonSignedRankTestTest { */ final double x[] = {1.83, 0.50, 1.62, 2.48, 1.68, 1.88, 1.55, 3.06, 1.30}; final double y[] = {0.878, 0.647, 0.598, 2.05, 1.06, 1.29, 1.06, 3.14, 1.29}; - + /* EXACT: * wilcox.test(x, y, alternative = "two.sided", mu = 0, paired = TRUE, exact = TRUE, correct = FALSE) * V = 40, p-value = 0.03906 - * + * * Corresponds to the value obtained in R. */ Assert.assertEquals(40, testStatistic.wilcoxonSignedRank(x, y), 1e-10); - Assert.assertEquals(0.03906, testStatistic.wilcoxonSignedRankTest(x, y, true), 1e-5); - + Assert.assertEquals(0.03906, testStatistic.wilcoxonSignedRankTest(x, y, true), 1e-5); + /* ASYMPTOTIC: * wilcox.test(x, y, alternative = "two.sided", mu = 0, paired = TRUE, exact = FALSE, correct = FALSE) * V = 40, p-value = 0.03815 - * - * This is not entirely the same due to different corrects, + * + * This is not entirely the same due to different corrects, * e.g. http://mlsc.lboro.ac.uk/resources/statistics/wsrt.pdf * and src/library/stats/R/wilcox.test.R in the R source */ Assert.assertEquals(40, testStatistic.wilcoxonSignedRank(x, y), 1e-10); Assert.assertEquals(0.0329693812, testStatistic.wilcoxonSignedRankTest(x, y, false), 1e-10); } - + @Test public void testWilcoxonSignedRankInputValidation() { /* @@ -73,19 +73,19 @@ public class WilcoxonSignedRankTestTest { final double[] y1 = new double[30]; final double[] y2 = new double[31]; for (int i = 0; i < 30; ++i) { - x1[i] = x2[i] = y1[i] = y2[i] = i; + x1[i] = x2[i] = y1[i] = y2[i] = i; } - + // Exactly 30 is okay - //testStatistic.wilcoxonSignedRankTest(x1, y1, true); - + //testStatistic.wilcoxonSignedRankTest(x1, y1, true); + try { testStatistic.wilcoxonSignedRankTest(x2, y2, true); Assert.fail("More than 30 samples and exact chosen, NumberIsTooLargeException expected"); } catch (NumberIsTooLargeException ex) { // expected } - + /* Samples must be present, i.e. length > 0 */ try { @@ -131,7 +131,7 @@ public class WilcoxonSignedRankTestTest { } catch (DimensionMismatchException ex) { // expected } - + /* * x and y is null */ @@ -141,14 +141,14 @@ public class WilcoxonSignedRankTestTest { } catch (NullArgumentException ex) { // expected } - + try { testStatistic.wilcoxonSignedRankTest(null, null, false); Assert.fail("x and y is null (asymptotic), NullArgumentException expected"); } catch (NullArgumentException ex) { // expected } - + /* * x or y is null */ @@ -158,21 +158,21 @@ public class WilcoxonSignedRankTestTest { } catch (NullArgumentException ex) { // expected } - + try { testStatistic.wilcoxonSignedRankTest(null, new double[] { 1.0 }, false); Assert.fail("x is null (asymptotic), NullArgumentException expected"); } catch (NullArgumentException ex) { // expected } - + try { testStatistic.wilcoxonSignedRankTest(new double[] { 1.0 }, null, true); Assert.fail("y is null (exact), NullArgumentException expected"); } catch (NullArgumentException ex) { // expected } - + try { testStatistic.wilcoxonSignedRankTest(new double[] { 1.0 }, null, false); Assert.fail("y is null (asymptotic), NullArgumentException expected"); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/interval/AgrestiCoullIntervalTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/interval/AgrestiCoullIntervalTest.java b/src/test/java/org/apache/commons/math3/stat/interval/AgrestiCoullIntervalTest.java index 2072b0e..4b757c9 100644 --- a/src/test/java/org/apache/commons/math3/stat/interval/AgrestiCoullIntervalTest.java +++ b/src/test/java/org/apache/commons/math3/stat/interval/AgrestiCoullIntervalTest.java @@ -32,7 +32,7 @@ public class AgrestiCoullIntervalTest extends BinomialConfidenceIntervalAbstract protected BinomialConfidenceInterval createBinomialConfidenceInterval() { return new AgrestiCoullInterval(); } - + @Test public void testStandardInterval() { ConfidenceInterval confidenceInterval = createStandardTestInterval(); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/interval/BinomialConfidenceIntervalAbstractTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/interval/BinomialConfidenceIntervalAbstractTest.java b/src/test/java/org/apache/commons/math3/stat/interval/BinomialConfidenceIntervalAbstractTest.java index a346297..7cc75a3 100644 --- a/src/test/java/org/apache/commons/math3/stat/interval/BinomialConfidenceIntervalAbstractTest.java +++ b/src/test/java/org/apache/commons/math3/stat/interval/BinomialConfidenceIntervalAbstractTest.java @@ -35,10 +35,10 @@ public abstract class BinomialConfidenceIntervalAbstractTest { private final double confidenceLevel = 0.9; protected abstract BinomialConfidenceInterval createBinomialConfidenceInterval(); - + /** * Returns the confidence interval for the given statistic with the following values: - * + * * <ul> * <li>trials: 500</li> * <li>successes: 50</li> http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/interval/ClopperPearsonIntervalTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/interval/ClopperPearsonIntervalTest.java b/src/test/java/org/apache/commons/math3/stat/interval/ClopperPearsonIntervalTest.java index 2dfe1be..8258021 100644 --- a/src/test/java/org/apache/commons/math3/stat/interval/ClopperPearsonIntervalTest.java +++ b/src/test/java/org/apache/commons/math3/stat/interval/ClopperPearsonIntervalTest.java @@ -32,7 +32,7 @@ public class ClopperPearsonIntervalTest extends BinomialConfidenceIntervalAbstra protected BinomialConfidenceInterval createBinomialConfidenceInterval() { return new ClopperPearsonInterval(); } - + @Test public void testStandardInterval() { ConfidenceInterval confidenceInterval = createStandardTestInterval(); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/interval/IntervalUtilsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/interval/IntervalUtilsTest.java b/src/test/java/org/apache/commons/math3/stat/interval/IntervalUtilsTest.java index 4f87371..8ebab58 100644 --- a/src/test/java/org/apache/commons/math3/stat/interval/IntervalUtilsTest.java +++ b/src/test/java/org/apache/commons/math3/stat/interval/IntervalUtilsTest.java @@ -21,14 +21,14 @@ import org.junit.Test; /** * Test cases for the IntervalUtils class. - * + * */ public class IntervalUtilsTest { private final int successes = 50; private final int trials = 500; private final double confidenceLevel = 0.9; - + // values to test must be exactly the same private final double eps = 0.0; http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/interval/NormalApproximationIntervalTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/interval/NormalApproximationIntervalTest.java b/src/test/java/org/apache/commons/math3/stat/interval/NormalApproximationIntervalTest.java index 2b0384a..66f6166 100644 --- a/src/test/java/org/apache/commons/math3/stat/interval/NormalApproximationIntervalTest.java +++ b/src/test/java/org/apache/commons/math3/stat/interval/NormalApproximationIntervalTest.java @@ -32,7 +32,7 @@ public class NormalApproximationIntervalTest extends BinomialConfidenceIntervalA protected BinomialConfidenceInterval createBinomialConfidenceInterval() { return new NormalApproximationInterval(); } - + @Test public void testStandardInterval() { ConfidenceInterval confidenceInterval = createStandardTestInterval(); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/interval/WilsonScoreIntervalTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/interval/WilsonScoreIntervalTest.java b/src/test/java/org/apache/commons/math3/stat/interval/WilsonScoreIntervalTest.java index af64a54..b612ff4 100644 --- a/src/test/java/org/apache/commons/math3/stat/interval/WilsonScoreIntervalTest.java +++ b/src/test/java/org/apache/commons/math3/stat/interval/WilsonScoreIntervalTest.java @@ -32,7 +32,7 @@ public class WilsonScoreIntervalTest extends BinomialConfidenceIntervalAbstractT protected BinomialConfidenceInterval createBinomialConfidenceInterval() { return new WilsonScoreInterval(); } - + @Test public void testStandardInterval() { ConfidenceInterval confidenceInterval = createStandardTestInterval(); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/ranking/NaturalRankingTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/ranking/NaturalRankingTest.java b/src/test/java/org/apache/commons/math3/stat/ranking/NaturalRankingTest.java index e1ddf06..33a3db4 100644 --- a/src/test/java/org/apache/commons/math3/stat/ranking/NaturalRankingTest.java +++ b/src/test/java/org/apache/commons/math3/stat/ranking/NaturalRankingTest.java @@ -44,28 +44,28 @@ public class NaturalRankingTest { public void testDefault() { // Ties averaged, NaNs failed NaturalRanking ranking = new NaturalRanking(); double[] ranks; - + try { ranks = ranking.rank(exampleData); Assert.fail("expected NotANumberException due to NaNStrategy.FAILED"); } catch (NotANumberException e) { // expected } - + ranks = ranking.rank(tiesFirst); 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); - + 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); @@ -207,14 +207,14 @@ public class NaturalRankingTest { correctRanks = new double[] { 3, 4, 1.5, 1.5 }; TestUtils.assertEquals(correctRanks, ranks, 0d); } - + @Test(expected=NotANumberException.class) public void testNaNsFailed() { double[] data = { 0, Double.POSITIVE_INFINITY, Double.NaN, Double.NEGATIVE_INFINITY }; NaturalRanking ranking = new NaturalRanking(NaNStrategy.FAILED); ranking.rank(data); } - + @Test public void testNoNaNsFailed() { double[] data = { 1, 2, 3, 4 }; @@ -222,5 +222,5 @@ public class NaturalRankingTest { double[] ranks = ranking.rank(data); TestUtils.assertEquals(data, ranks, 0d); } - + } http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/regression/GLSMultipleLinearRegressionTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/regression/GLSMultipleLinearRegressionTest.java b/src/test/java/org/apache/commons/math3/stat/regression/GLSMultipleLinearRegressionTest.java index 3896487..e00cee5 100644 --- a/src/test/java/org/apache/commons/math3/stat/regression/GLSMultipleLinearRegressionTest.java +++ b/src/test/java/org/apache/commons/math3/stat/regression/GLSMultipleLinearRegressionTest.java @@ -162,18 +162,18 @@ public class GLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs model.newSampleData(y, x, omega); TestUtils.assertEquals(model.calculateYVariance(), 3.5, 0); } - + /** * Verifies that setting X, Y and covariance separately has the same effect as newSample(X,Y,cov). */ @Test public void testNewSample2() { - double[] y = new double[] {1, 2, 3, 4}; + double[] y = new double[] {1, 2, 3, 4}; double[][] x = new double[][] { {19, 22, 33}, {20, 30, 40}, {25, 35, 45}, - {27, 37, 47} + {27, 37, 47} }; double[][] covariance = MatrixUtils.createRealIdentityMatrix(4).scalarMultiply(2).getData(); GLSMultipleLinearRegression regression = new GLSMultipleLinearRegression(); @@ -187,13 +187,13 @@ public class GLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs Assert.assertEquals(combinedY, regression.getY()); Assert.assertEquals(combinedCovInv, regression.getOmegaInverse()); } - + /** * Verifies that GLS with identity covariance matrix gives the same results * as OLS. */ @Test - public void testGLSOLSConsistency() { + public void testGLSOLSConsistency() { RealMatrix identityCov = MatrixUtils.createRealIdentityMatrix(16); GLSMultipleLinearRegression glsModel = new GLSMultipleLinearRegression(); OLSMultipleLinearRegression olsModel = new OLSMultipleLinearRegression(); @@ -208,7 +208,7 @@ public class GLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs TestUtils.assertRelativelyEquals(olsBeta[i], glsBeta[i], 10E-7); } } - + /** * Generate an error covariance matrix and sample data representing models * with this error structure. Then verify that GLS estimated coefficients, @@ -218,7 +218,7 @@ public class GLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs public void testGLSEfficiency() { RandomGenerator rg = new JDKRandomGenerator(); rg.setSeed(200); // Seed has been selected to generate non-trivial covariance - + // Assume model has 16 observations (will use Longley data). Start by generating // non-constant variances for the 16 error terms. final int nObs = 16; @@ -226,7 +226,7 @@ public class GLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs for (int i = 0; i < nObs; i++) { sigma[i] = 10 * rg.nextDouble(); } - + // Now generate 1000 error vectors to use to estimate the covariance matrix // Columns are draws on N(0, sigma[col]) final int numSeeds = 1000; @@ -236,16 +236,16 @@ public class GLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs errorSeeds.setEntry(i, j, rg.nextGaussian() * sigma[j]); } } - + // Get covariance matrix for columns RealMatrix cov = (new Covariance(errorSeeds)).getCovarianceMatrix(); - + // Create a CorrelatedRandomVectorGenerator to use to generate correlated errors GaussianRandomGenerator rawGenerator = new GaussianRandomGenerator(rg); double[] errorMeans = new double[nObs]; // Counting on init to 0 here CorrelatedRandomVectorGenerator gen = new CorrelatedRandomVectorGenerator(errorMeans, cov, 1.0e-12 * cov.getNorm(), rawGenerator); - + // Now start generating models. Use Longley X matrix on LHS // and Longley OLS beta vector as "true" beta. Generate // Y values by XB + u where u is a CorrelatedRandomVector generated @@ -254,44 +254,44 @@ public class GLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs ols.newSampleData(longley, nObs, 6); final RealVector b = ols.calculateBeta().copy(); final RealMatrix x = ols.getX().copy(); - + // Create a GLS model to reuse GLSMultipleLinearRegression gls = new GLSMultipleLinearRegression(); gls.newSampleData(longley, nObs, 6); gls.newCovarianceData(cov.getData()); - + // Create aggregators for stats measuring model performance DescriptiveStatistics olsBetaStats = new DescriptiveStatistics(); DescriptiveStatistics glsBetaStats = new DescriptiveStatistics(); - + // Generate Y vectors for 10000 models, estimate GLS and OLS and // Verify that OLS estimates are better final int nModels = 10000; for (int i = 0; i < nModels; i++) { - + // Generate y = xb + u with u cov RealVector u = MatrixUtils.createRealVector(gen.nextVector()); double[] y = u.add(x.operate(b)).toArray(); - + // Estimate OLS parameters ols.newYSampleData(y); RealVector olsBeta = ols.calculateBeta(); - + // Estimate GLS parameters gls.newYSampleData(y); RealVector glsBeta = gls.calculateBeta(); - + // Record deviations from "true" beta double dist = olsBeta.getDistance(b); olsBetaStats.addValue(dist * dist); dist = glsBeta.getDistance(b); glsBetaStats.addValue(dist * dist); - + } - + // Verify that GLS is on average more efficient, lower variance assert(olsBetaStats.getMean() > 1.5 * glsBetaStats.getMean()); - assert(olsBetaStats.getStandardDeviation() > glsBetaStats.getStandardDeviation()); + assert(olsBetaStats.getStandardDeviation() > glsBetaStats.getStandardDeviation()); } - + } http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/regression/MillerUpdatingRegressionTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/regression/MillerUpdatingRegressionTest.java b/src/test/java/org/apache/commons/math3/stat/regression/MillerUpdatingRegressionTest.java index 2ff023c..7f0a06a 100644 --- a/src/test/java/org/apache/commons/math3/stat/regression/MillerUpdatingRegressionTest.java +++ b/src/test/java/org/apache/commons/math3/stat/regression/MillerUpdatingRegressionTest.java @@ -30,9 +30,9 @@ public class MillerUpdatingRegressionTest { public MillerUpdatingRegressionTest() { } - /* This is the Greene Airline Cost data. + /* This is the Greene Airline Cost data. * The data can be downloaded from http://www.indiana.edu/~statmath/stat/all/panel/airline.csv - */ + */ private final static double[][] airdata = { /*"I",*/new double[]{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6}, /*"T",*/ new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, @@ -327,7 +327,7 @@ public class MillerUpdatingRegressionTest { // tmp[6] = tmp[2] * tmp[3]; //^7 // tmp[7] = tmp[3] * tmp[3]; //^8 // tmp[8] = tmp[4] * tmp[3]; //^9 -// tmp[9] = tmp[4] * tmp[4]; //^10 +// tmp[9] = tmp[4] * tmp[4]; //^10 tmp[1] = tmp[0] * tmp[0]; tmp[2] = tmp[0] * tmp[1]; tmp[3] = tmp[0] * tmp[2]; @@ -678,12 +678,12 @@ public class MillerUpdatingRegressionTest { 0.214274163161675, 0.226073200069370, 455.478499142212}, errors, 1E-6); -// +// // Check R-Square statistics against R TestUtils.assertEquals(0.995479004577296, result.getRSquared(), 1E-12); TestUtils.assertEquals(0.992465007628826, result.getAdjustedRSquared(), 1E-12); -// -// +// +// // // Estimate model without intercept model = new MillerUpdatingRegression(6, false); off = 0; @@ -699,13 +699,13 @@ public class MillerUpdatingRegressionTest { new double[]{-52.99357013868291, 0.07107319907358, -0.42346585566399, -0.57256866841929, -0.41420358884978, 48.41786562001326}, 1E-11); -// +// // Check standard errors from R errors = result.getStdErrorOfEstimates(); TestUtils.assertEquals(new double[]{129.54486693117232, 0.03016640003786, 0.41773654056612, 0.27899087467676, 0.32128496193363, 17.68948737819961}, errors, 1E-11); -// +// // // Check R-Square statistics against R TestUtils.assertEquals(0.9999670130706, result.getRSquared(), 1E-12); @@ -1045,11 +1045,11 @@ public class MillerUpdatingRegressionTest { } return; } - - + + @Test public void testSubsetRegression() { - + MillerUpdatingRegression instance = new MillerUpdatingRegression(3, true); MillerUpdatingRegression redRegression = new MillerUpdatingRegression(2, true); double[][] x = new double[airdata[0].length][]; @@ -1060,23 +1060,23 @@ public class MillerUpdatingRegressionTest { x[i][0] = FastMath.log(airdata[3][i]); x[i][1] = FastMath.log(airdata[4][i]); x[i][2] = airdata[5][i]; - + xReduced[i] = new double[2]; xReduced[i][0] = FastMath.log(airdata[3][i]); xReduced[i][1] = FastMath.log(airdata[4][i]); - + y[i] = FastMath.log(airdata[2][i]); } instance.addObservations(x, y); redRegression.addObservations(xReduced, y); - + RegressionResults resultsInstance = instance.regress( new int[]{0,1,2} ); RegressionResults resultsReduced = redRegression.regress(); - + TestUtils.assertEquals(resultsInstance.getParameterEstimates(), resultsReduced.getParameterEstimates(), 1.0e-12); TestUtils.assertEquals(resultsInstance.getStdErrorOfEstimates(), resultsReduced.getStdErrorOfEstimates(), 1.0e-12); } - - + + } http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/regression/MultipleLinearRegressionAbstractTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/regression/MultipleLinearRegressionAbstractTest.java b/src/test/java/org/apache/commons/math3/stat/regression/MultipleLinearRegressionAbstractTest.java index ea5fecf..759422b 100644 --- a/src/test/java/org/apache/commons/math3/stat/regression/MultipleLinearRegressionAbstractTest.java +++ b/src/test/java/org/apache/commons/math3/stat/regression/MultipleLinearRegressionAbstractTest.java @@ -64,7 +64,7 @@ public abstract class MultipleLinearRegressionAbstractTest { Assert.assertTrue(variance > 0.0); } } - + /** * Verifies that newSampleData methods consistently insert unitary columns * in design matrix. Confirms the fix for MATH-411. @@ -77,12 +77,12 @@ public abstract class MultipleLinearRegressionAbstractTest { 3, 25, 35, 45, 4, 27, 37, 47 }; - double[] y = new double[] {1, 2, 3, 4}; + double[] y = new double[] {1, 2, 3, 4}; double[][] x = new double[][] { {19, 22, 33}, {20, 30, 40}, {25, 35, 45}, - {27, 37, 47} + {27, 37, 47} }; AbstractMultipleLinearRegression regression = createRegression(); regression.newSampleData(design, 4, 3); @@ -92,7 +92,7 @@ public abstract class MultipleLinearRegressionAbstractTest { regression.newYSampleData(y); Assert.assertEquals(flatX, regression.getX()); Assert.assertEquals(flatY, regression.getY()); - + // No intercept regression.setNoIntercept(true); regression.newSampleData(design, 4, 3); @@ -103,30 +103,30 @@ public abstract class MultipleLinearRegressionAbstractTest { Assert.assertEquals(flatX, regression.getX()); Assert.assertEquals(flatY, regression.getY()); } - + @Test(expected=IllegalArgumentException.class) public void testNewSampleNullData() { double[] data = null; - createRegression().newSampleData(data, 2, 3); + createRegression().newSampleData(data, 2, 3); } - + @Test(expected=IllegalArgumentException.class) public void testNewSampleInvalidData() { double[] data = new double[] {1, 2, 3, 4}; createRegression().newSampleData(data, 2, 3); } - + @Test(expected=IllegalArgumentException.class) public void testNewSampleInsufficientData() { double[] data = new double[] {1, 2, 3, 4}; createRegression().newSampleData(data, 1, 3); } - + @Test(expected=IllegalArgumentException.class) public void testXSampleDataNull() { createRegression().newXSampleData(null); } - + @Test(expected=IllegalArgumentException.class) public void testYSampleDataNull() { createRegression().newYSampleData(null); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/regression/OLSMultipleLinearRegressionTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/regression/OLSMultipleLinearRegressionTest.java b/src/test/java/org/apache/commons/math3/stat/regression/OLSMultipleLinearRegressionTest.java index d719c8b..87dabb8 100644 --- a/src/test/java/org/apache/commons/math3/stat/regression/OLSMultipleLinearRegressionTest.java +++ b/src/test/java/org/apache/commons/math3/stat/regression/OLSMultipleLinearRegressionTest.java @@ -63,7 +63,7 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs protected int getSampleSize() { return y.length; } - + @Test(expected=IllegalArgumentException.class) public void cannotAddSampleDataWithSizeMismatch() { double[] y = new double[]{1.0, 2.0}; @@ -170,33 +170,33 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs 0.214274163161675, 0.226073200069370, 455.478499142212}, errors, 1E-6); - + // Check regression standard error against R Assert.assertEquals(304.8540735619638, model.estimateRegressionStandardError(), 1E-10); - + // Check R-Square statistics against R Assert.assertEquals(0.995479004577296, model.calculateRSquared(), 1E-12); Assert.assertEquals(0.992465007628826, model.calculateAdjustedRSquared(), 1E-12); - + checkVarianceConsistency(model); - + // Estimate model without intercept model.setNoIntercept(true); model.newSampleData(design, nobs, nvars); - + // Check expected beta values from R betaHat = model.estimateRegressionParameters(); TestUtils.assertEquals(betaHat, new double[]{-52.99357013868291, 0.07107319907358, -0.42346585566399,-0.57256866841929, - -0.41420358884978, 48.41786562001326}, 1E-11); - + -0.41420358884978, 48.41786562001326}, 1E-11); + // Check standard errors from R errors = model.estimateRegressionParametersStandardErrors(); TestUtils.assertEquals(new double[] {129.54486693117232, 0.03016640003786, 0.41773654056612, 0.27899087467676, 0.32128496193363, 17.68948737819961}, errors, 1E-11); - + // Check expected residuals from R residuals = model.estimateResiduals(); TestUtils.assertEquals(residuals, new double[]{ @@ -205,14 +205,14 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs 73.09368242049943, 913.21694494481869, 424.82484953610174, -8.56475876776709, -361.32974610842876, 27.34560497213464, 151.28955976355002, -492.49937355336846}, 1E-10); - + // Check regression standard error against R Assert.assertEquals(475.1655079819517, model.estimateRegressionStandardError(), 1E-10); - + // Check R-Square statistics against R Assert.assertEquals(0.9999670130706, model.calculateRSquared(), 1E-12); Assert.assertEquals(0.999947220913, model.calculateAdjustedRSquared(), 1E-12); - + } /** @@ -270,7 +270,7 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs 44.7,46.6,16,29,50.43, 42.8,27.7,22,29,58.33 }; - + final int nobs = 47; final int nvars = 4; @@ -315,16 +315,16 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs 0.27410957467466, 0.19454551679325, 0.03726654773803}, errors, 1E-10); - + // Check regression standard error against R Assert.assertEquals(7.73642194433223, model.estimateRegressionStandardError(), 1E-12); - + // Check R-Square statistics against R Assert.assertEquals(0.649789742860228, model.calculateRSquared(), 1E-12); Assert.assertEquals(0.6164363850373927, model.calculateAdjustedRSquared(), 1E-12); - + checkVarianceConsistency(model); - + // Estimate the model with no intercept model = new OLSMultipleLinearRegression(); model.setNoIntercept(true); @@ -335,15 +335,15 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs TestUtils.assertEquals(betaHat, new double[]{0.52191832900513, 2.36588087917963, - -0.94770353802795, + -0.94770353802795, 0.30851985863609}, 1E-12); // Check expected residuals from R residuals = model.estimateResiduals(); TestUtils.assertEquals(residuals, new double[]{ - 44.138759883538249, 27.720705122356215, 35.873200836126799, + 44.138759883538249, 27.720705122356215, 35.873200836126799, 34.574619581211977, 26.600168342080213, 15.074636243026923, -12.704904871199814, - 1.497443824078134, 2.691972687079431, 5.582798774291231, -4.422986561283165, + 1.497443824078134, 2.691972687079431, 5.582798774291231, -4.422986561283165, -9.198581600334345, 4.481765170730647, 2.273520207553216, -22.649827853221336, -17.747900013943308, 20.298314638496436, 6.861405135329779, -8.684712790954924, -10.298639278062371, -9.896618896845819, 4.568568616351242, -15.313570491727944, @@ -359,10 +359,10 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs errors = model.estimateRegressionParametersStandardErrors(); TestUtils.assertEquals(new double[] {0.10470063765677, 0.41684100584290, 0.43370143099691, 0.07694953606522}, errors, 1E-10); - + // Check regression standard error against R Assert.assertEquals(17.24710630547, model.estimateRegressionStandardError(), 1E-10); - + // Check R-Square statistics against R Assert.assertEquals(0.946350722085, model.calculateRSquared(), 1E-12); Assert.assertEquals(0.9413600915813, model.calculateAdjustedRSquared(), 1E-12); @@ -449,7 +449,7 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs model.newSampleData(y, x); TestUtils.assertEquals(model.calculateYVariance(), 3.5, 0); } - + /** * Verifies that calculateYVariance and calculateResidualVariance return consistent * values with direct variance computation from Y, residuals, respectively. @@ -457,27 +457,27 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs protected void checkVarianceConsistency(OLSMultipleLinearRegression model) { // Check Y variance consistency TestUtils.assertEquals(StatUtils.variance(model.getY().toArray()), model.calculateYVariance(), 0); - + // Check residual variance consistency double[] residuals = model.calculateResiduals().toArray(); RealMatrix X = model.getX(); TestUtils.assertEquals( StatUtils.variance(model.calculateResiduals().toArray()) * (residuals.length - 1), model.calculateErrorVariance() * (X.getRowDimension() - X.getColumnDimension()), 1E-20); - + } - + /** * Verifies that setting X and Y separately has the same effect as newSample(X,Y). */ @Test public void testNewSample2() { - double[] y = new double[] {1, 2, 3, 4}; + double[] y = new double[] {1, 2, 3, 4}; double[][] x = new double[][] { {19, 22, 33}, {20, 30, 40}, {25, 35, 45}, - {27, 37, 47} + {27, 37, 47} }; OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression(); regression.newSampleData(y, x); @@ -487,7 +487,7 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs regression.newYSampleData(y); Assert.assertEquals(combinedX, regression.getX()); Assert.assertEquals(combinedY, regression.getY()); - + // No intercept regression.setNoIntercept(true); regression.newSampleData(y, x); @@ -498,17 +498,17 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs Assert.assertEquals(combinedX, regression.getX()); Assert.assertEquals(combinedY, regression.getY()); } - + @Test(expected=IllegalArgumentException.class) public void testNewSampleDataYNull() { createRegression().newSampleData(null, new double[][] {}); } - + @Test(expected=IllegalArgumentException.class) public void testNewSampleDataXNull() { createRegression().newSampleData(new double[] {}, null); } - + /* * This is a test based on the Wampler1 data set * http://www.itl.nist.gov/div898/strd/lls/data/Wampler1.shtml @@ -568,7 +568,7 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs new double[]{0.0, 0.0, 0.0, 0.0, 0.0, - 0.0}, 1E-8); + 0.0}, 1E-8); TestUtils.assertEquals(1.0, model.calculateRSquared(), 1.0e-10); TestUtils.assertEquals(0, model.estimateErrorVariance(), 1.0e-7); @@ -576,7 +576,7 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs return; } - + /* * This is a test based on the Wampler2 data set * http://www.itl.nist.gov/div898/strd/lls/data/Wampler2.shtml @@ -638,13 +638,13 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs new double[]{0.0, 0.0, 0.0, 0.0, 0.0, - 0.0}, 1E-8); + 0.0}, 1E-8); TestUtils.assertEquals(1.0, model.calculateRSquared(), 1.0e-10); TestUtils.assertEquals(0, model.estimateErrorVariance(), 1.0e-7); TestUtils.assertEquals(0.00, model.calculateResidualSumOfSquares(), 1.0e-6); return; } - + /* * This is a test based on the Wampler3 data set * http://www.itl.nist.gov/div898/strd/lls/data/Wampler3.shtml @@ -699,7 +699,7 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs 1.0, 1.0, 1.0, - 1.0}, 1E-8); + 1.0}, 1E-8); double[] se = model.estimateRegressionParametersStandardErrors(); TestUtils.assertEquals(se, @@ -768,21 +768,21 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs 1.0, 1.0, 1.0, - 1.0}, 1E-6); + 1.0}, 1E-6); double[] se = model.estimateRegressionParametersStandardErrors(); TestUtils.assertEquals(se, new double[]{215232.624678170, 236355.173469681, 77934.3524331583, 10147.5507550350, 564.566512170752, - 11.2324854679312}, 1E-8); + 11.2324854679312}, 1E-8); TestUtils.assertEquals(.957478440825662, model.calculateRSquared(), 1.0e-10); TestUtils.assertEquals(55702845333.3333, model.estimateErrorVariance(), 1.0e-4); TestUtils.assertEquals(835542680000.000, model.calculateResidualSumOfSquares(), 1.0e-3); return; } - + /** * Anything requiring beta calculation should advertise SME. */ @@ -792,26 +792,26 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs model.newSampleData(new double[] {1, 2, 3, 1, 2, 3, 1, 2, 3}, 3, 2); model.calculateBeta(); } - + @Test public void testNoSSTOCalculateRsquare() { OLSMultipleLinearRegression model = new OLSMultipleLinearRegression(); model.newSampleData(new double[] {1, 2, 3, 1, 7, 8, 1, 10, 12}, 3, 2); Assert.assertTrue(Double.isNaN(model.calculateRSquared())); } - + @Test(expected=NullPointerException.class) public void testNoDataNPECalculateBeta() { OLSMultipleLinearRegression model = new OLSMultipleLinearRegression(); model.calculateBeta(); } - + @Test(expected=NullPointerException.class) public void testNoDataNPECalculateHat() { OLSMultipleLinearRegression model = new OLSMultipleLinearRegression(); model.calculateHat(); } - + @Test(expected=NullPointerException.class) public void testNoDataNPESSTO() { OLSMultipleLinearRegression model = new OLSMultipleLinearRegression(); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/stat/regression/SimpleRegressionTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/stat/regression/SimpleRegressionTest.java b/src/test/java/org/apache/commons/math3/stat/regression/SimpleRegressionTest.java index 063e06b..e79ab6a 100644 --- a/src/test/java/org/apache/commons/math3/stat/regression/SimpleRegressionTest.java +++ b/src/test/java/org/apache/commons/math3/stat/regression/SimpleRegressionTest.java @@ -547,7 +547,7 @@ public final class SimpleRegressionTest { Assert.assertTrue(regression.getSlope() > 0.0); Assert.assertTrue(regression.getSumSquaredErrors() >= 0.0); } - + @Test public void testPerfect2() { SimpleRegression regression = new SimpleRegression(); http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/util/CombinationsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/util/CombinationsTest.java b/src/test/java/org/apache/commons/math3/util/CombinationsTest.java index 99b8e60..da52951 100644 --- a/src/test/java/org/apache/commons/math3/util/CombinationsTest.java +++ b/src/test/java/org/apache/commons/math3/util/CombinationsTest.java @@ -145,7 +145,7 @@ public class CombinationsTest { * Verifies that the iterator generates a lexicographically * increasing sequence of b(n,k) arrays, each having length k * and each array itself increasing. - * + * * @param c Combinations. */ private void checkLexicographicIterator(Combinations c) { @@ -177,7 +177,7 @@ public class CombinationsTest { Assert.assertEquals(CombinatoricsUtils.binomialCoefficient(n, k), numIterates); } - + @Test public void testCombinationsIteratorFail() { try { http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/util/FastMathTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/util/FastMathTest.java b/src/test/java/org/apache/commons/math3/util/FastMathTest.java index 2df5542..2d7607d 100644 --- a/src/test/java/org/apache/commons/math3/util/FastMathTest.java +++ b/src/test/java/org/apache/commons/math3/util/FastMathTest.java @@ -182,14 +182,14 @@ public class FastMathTest { for (double x = start; x < end; x += 1e-3) { final double tst = FastMath.cosh(x); final double ref = Math.cosh(x); - maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref)); + maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref)); } Assert.assertEquals(0, maxErr, 3); for (double x = start; x < end; x += 1e-3) { final double tst = FastMath.sinh(x); final double ref = Math.sinh(x); - maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref)); + maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref)); } Assert.assertEquals(0, maxErr, 3); } @@ -204,18 +204,18 @@ public class FastMathTest { for (double x = start; x > end; x -= 1e-3) { final double tst = FastMath.cosh(x); final double ref = Math.cosh(x); - maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref)); + maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref)); } Assert.assertEquals(0, maxErr, 3); for (double x = start; x > end; x -= 1e-3) { final double tst = FastMath.sinh(x); final double ref = Math.sinh(x); - maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref)); + maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref)); } Assert.assertEquals(0, maxErr, 3); } - + @Test public void testMath1269() { final double arg = 709.8125; @@ -1027,13 +1027,13 @@ public class FastMathTest { */ @Test public void testAcosSpecialCases() { - + Assert.assertTrue("acos(NaN) should be NaN", Double.isNaN(FastMath.acos(Double.NaN))); - + Assert.assertTrue("acos(-1.1) should be NaN", Double.isNaN(FastMath.acos(-1.1))); Assert.assertTrue("acos(-1.1) should be NaN", Double.isNaN(FastMath.acos(1.1))); - + Assert.assertEquals("acos(-1.0) should be PI", FastMath.acos(-1.0), FastMath.PI, Precision.EPSILON); Assert.assertEquals("acos(1.0) should be 0.0", FastMath.acos(1.0), 0.0, Precision.EPSILON); @@ -1046,13 +1046,13 @@ public class FastMathTest { */ @Test public void testAsinSpecialCases() { - + Assert.assertTrue("asin(NaN) should be NaN", Double.isNaN(FastMath.asin(Double.NaN))); - + Assert.assertTrue("asin(1.1) should be NaN", Double.isNaN(FastMath.asin(1.1))); - + Assert.assertTrue("asin(-1.1) should be NaN", Double.isNaN(FastMath.asin(-1.1))); - + Assert.assertEquals("asin(1.0) should be PI/2", FastMath.asin(1.0), FastMath.PI / 2.0, Precision.EPSILON); Assert.assertEquals("asin(-1.0) should be -PI/2", FastMath.asin(-1.0), -FastMath.PI / 2.0, Precision.EPSILON); @@ -1458,7 +1458,7 @@ public class FastMathTest { public void testIntPowLongMinValue() { Assert.assertEquals(1.0, FastMath.pow(1.0, Long.MIN_VALUE), -1.0); } - + @Test(timeout=5000L) public void testIntPowSpecialCases() { final double EXACT = -1.0; http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/util/IncrementorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/util/IncrementorTest.java b/src/test/java/org/apache/commons/math3/util/IncrementorTest.java index 0c7d4fb..382b0fc 100644 --- a/src/test/java/org/apache/commons/math3/util/IncrementorTest.java +++ b/src/test/java/org/apache/commons/math3/util/IncrementorTest.java @@ -134,4 +134,4 @@ public class IncrementorTest { i.incrementCount(1); Assert.assertEquals(3, i.getCount()); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/commons-math/blob/ff35e6f2/src/test/java/org/apache/commons/math3/util/ResizableDoubleArrayTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/util/ResizableDoubleArrayTest.java b/src/test/java/org/apache/commons/math3/util/ResizableDoubleArrayTest.java index 3a1a1d7..1a7b45a 100644 --- a/src/test/java/org/apache/commons/math3/util/ResizableDoubleArrayTest.java +++ b/src/test/java/org/apache/commons/math3/util/ResizableDoubleArrayTest.java @@ -61,11 +61,11 @@ public class ResizableDoubleArrayTest extends DoubleArrayAbstractTest { } catch (IllegalArgumentException ex) { // expected } - + testDa = new ResizableDoubleArray((double[]) null); Assert.assertEquals(0, testDa.getNumElements()); - - double[] initialArray = new double[] { 0, 1, 2 }; + + double[] initialArray = new double[] { 0, 1, 2 }; testDa = new ResizableDoubleArray(initialArray); Assert.assertEquals(3, testDa.getNumElements()); @@ -125,14 +125,14 @@ public class ResizableDoubleArrayTest extends DoubleArrayAbstractTest { ResizableDoubleArray copyDa = new ResizableDoubleArray(testDa); Assert.assertEquals(copyDa, testDa); Assert.assertEquals(testDa, copyDa); - + // JIRA: MATH-1252 final double[] values = {1}; testDa = new ResizableDoubleArray(values); Assert.assertArrayEquals(values, testDa.getElements(), 0); Assert.assertEquals(1, testDa.getNumElements()); Assert.assertEquals(1, testDa.getElement(0), 0); - + } @@ -205,24 +205,24 @@ public class ResizableDoubleArrayTest extends DoubleArrayAbstractTest { "16 and an expansion factor of 2.0", 1024, ((ResizableDoubleArray) da).getCapacity()); } - + @Test public void testAddElements() { ResizableDoubleArray testDa = new ResizableDoubleArray(); - + // MULTIPLICATIVE_MODE testDa.addElements(new double[] {4, 5, 6}); Assert.assertEquals(3, testDa.getNumElements(), 0); Assert.assertEquals(4, testDa.getElement(0), 0); Assert.assertEquals(5, testDa.getElement(1), 0); Assert.assertEquals(6, testDa.getElement(2), 0); - + testDa.addElements(new double[] {4, 5, 6}); Assert.assertEquals(6, testDa.getNumElements()); // ADDITIVE_MODE (x's are occupied storage locations, 0's are open) testDa = new ResizableDoubleArray(2, 2.0, 2.5, - ResizableDoubleArray.ExpansionMode.ADDITIVE); + ResizableDoubleArray.ExpansionMode.ADDITIVE); Assert.assertEquals(2, testDa.getCapacity()); testDa.addElements(new double[] { 1d }); // x,0 testDa.addElements(new double[] { 2d }); // x,x