This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-statistics.git
commit 90e0ae3760d43a21d5da202b8d226cdd82a7a7c0 Author: Alex Herbert <aherb...@apache.org> AuthorDate: Sat Dec 23 19:39:59 2023 +0000 Add random test case data for integer sum statistics --- .../apache/commons/statistics/descriptive/IntSumTest.java | 14 +++++++++++--- .../apache/commons/statistics/descriptive/LongSumTest.java | 14 +++++++++++--- .../apache/commons/statistics/descriptive/TestHelper.java | 3 ++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntSumTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntSumTest.java index 10c90dd..27bc0d3 100644 --- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntSumTest.java +++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntSumTest.java @@ -19,6 +19,7 @@ package org.apache.commons.statistics.descriptive; import java.math.BigInteger; import java.util.Arrays; import java.util.stream.Stream; +import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.statistics.distribution.DoubleTolerance; import org.apache.commons.statistics.distribution.DoubleTolerances; import org.junit.jupiter.api.Assertions; @@ -53,7 +54,8 @@ final class IntSumTest extends BaseIntStatisticTest<IntSum> { @Override protected DoubleTolerance getToleranceAsDouble() { // Floating-point sum may be inexact. - // Currently the double sum matches on the standard test data. + // Currently the double sum matches on the standard test data + // and larger random data added in streamTestData(). return DoubleTolerances.equals(); } @@ -73,9 +75,15 @@ final class IntSumTest extends BaseIntStatisticTest<IntSum> { @Override protected Stream<StatisticTestData> streamTestData() { + // A null seed will create a different RNG each time + final UniformRandomProvider rng = TestHelper.createRNG(null); return Stream.of( - addCase(Integer.MAX_VALUE, 1, 2, 3, 4, Integer.MAX_VALUE), - addCase(Integer.MIN_VALUE, -1, -2, -3, -4, Integer.MIN_VALUE) + addCase(Integer.MAX_VALUE, 1, 2, 3, 4, -20, Integer.MAX_VALUE), + addCase(Integer.MIN_VALUE, -1, -2, -3, -4, 20, Integer.MIN_VALUE), + addCase(rng.ints(5).toArray()), + addCase(rng.ints(10).toArray()), + addCase(rng.ints(20).toArray()), + addCase(rng.ints(40).toArray()) ); } diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongSumTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongSumTest.java index 9207112..de203f7 100644 --- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongSumTest.java +++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongSumTest.java @@ -19,6 +19,7 @@ package org.apache.commons.statistics.descriptive; import java.math.BigInteger; import java.util.Arrays; import java.util.stream.Stream; +import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.statistics.distribution.DoubleTolerance; import org.apache.commons.statistics.distribution.DoubleTolerances; import org.junit.jupiter.api.Assertions; @@ -54,7 +55,8 @@ final class LongSumTest extends BaseLongStatisticTest<LongSum> { protected DoubleTolerance getToleranceAsDouble() { // Floating-point sum may be inexact. // Currently the double sum matches on the standard test data. - return DoubleTolerances.equals(); + // It fails on large random data added in streamTestData(). + return DoubleTolerances.ulps(5); } @Override @@ -74,9 +76,15 @@ final class LongSumTest extends BaseLongStatisticTest<LongSum> { @Override protected Stream<StatisticTestData> streamTestData() { + // A null seed will create a different RNG each time + final UniformRandomProvider rng = TestHelper.createRNG(null); return Stream.of( - addCase(Long.MAX_VALUE, 1, 2, 3, 4, Long.MAX_VALUE), - addCase(Long.MIN_VALUE, -1, -2, -3, -4, Long.MIN_VALUE) + addCase(Long.MAX_VALUE, 1, 2, 3, 4, -20, Long.MAX_VALUE), + addCase(Long.MIN_VALUE, -1, -2, -3, -4, 20, Long.MIN_VALUE), + addCase(rng.longs(5).toArray()), + addCase(rng.longs(10).toArray()), + addCase(rng.longs(20).toArray()), + addCase(rng.longs(40).toArray()) ); } diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestHelper.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestHelper.java index 4df0044..c524e36 100644 --- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestHelper.java +++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestHelper.java @@ -231,8 +231,9 @@ final class TestHelper { /** * Creates a RNG instance. + * A null seed will create a different RNG each time. * - * @param seed Seed. + * @param seed Seed (can be null). * @return A new RNG instance. * @see #createRNGSeed() */