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 3aca99f04225f49be8c693c6e304909bcdedca9c Author: Alex Herbert <aherb...@apache.org> AuthorDate: Wed Dec 27 08:37:44 2023 +0000 Use common test cases --- .../commons/statistics/descriptive/IntMeanTest.java | 9 ++------- .../commons/statistics/descriptive/IntSumTest.java | 18 +++++++++++------- .../commons/statistics/descriptive/LongMeanTest.java | 9 ++------- .../commons/statistics/descriptive/LongSumTest.java | 18 +++++++++++------- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntMeanTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntMeanTest.java index 5dde438..b9834e7 100644 --- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntMeanTest.java +++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntMeanTest.java @@ -22,7 +22,7 @@ import org.apache.commons.statistics.distribution.DoubleTolerance; import org.apache.commons.statistics.distribution.DoubleTolerances; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.MethodSource; /** * Test for {@link IntMean}. @@ -98,12 +98,7 @@ final class IntMeanTest extends BaseIntStatisticTest<IntMean> { * will be incorrect so the test is limited to {@code n < 2^63}. */ @ParameterizedTest - @CsvSource({ - "-1628367811, -516725738, 60", - "627834682, 456456670, 61", - "2147483647, 2147483646, 61", - "-2147483648, -2147483647, 61", - }) + @MethodSource(value = "org.apache.commons.statistics.descriptive.IntSumTest#testLongOverflow") void testLongOverflow(int x, int y, int exp) { final IntMean s = IntMean.of(x, y); final double mean = ((long) x + y) * 0.5; 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 8abc723..bee0643 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 @@ -24,7 +24,8 @@ import org.apache.commons.statistics.distribution.DoubleTolerance; import org.apache.commons.statistics.distribution.DoubleTolerances; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * Test for {@link IntSum}. @@ -95,12 +96,7 @@ final class IntSumTest extends BaseIntStatisticTest<IntSum> { * will be incorrect so the test is limited to {@code n < 2^63}. */ @ParameterizedTest - @CsvSource({ - "-1628367811, -516725738, 60", - "627834682, 456456670, 61", - "2147483647, 2147483646, 61", - "-2147483648, -2147483647, 61", - }) + @MethodSource void testLongOverflow(int x, int y, int exp) { final IntSum s = IntSum.of(x, y); BigInteger sum = BigInteger.valueOf((long) x + y); @@ -111,4 +107,12 @@ final class IntSumTest extends BaseIntStatisticTest<IntSum> { Assertions.assertEquals(sum, s.getAsBigInteger()); } } + + static Stream<Arguments> testLongOverflow() { + return Stream.of( + Arguments.of(-1628367811, -516725738, 60), + Arguments.of(627834682, 456456670, 61), + Arguments.of(2147483647, 2147483646, 61), + Arguments.of(-2147483648, -2147483647, 61)); + } } diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongMeanTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongMeanTest.java index 849732e..726b720 100644 --- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongMeanTest.java +++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongMeanTest.java @@ -25,7 +25,7 @@ import org.apache.commons.statistics.distribution.DoubleTolerance; import org.apache.commons.statistics.distribution.DoubleTolerances; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.MethodSource; /** * Test for {@link LongMean}. @@ -105,12 +105,7 @@ final class LongMeanTest extends BaseLongStatisticTest<LongMean> { * will be incorrect so the test is limited to {@code n < 2^63}. */ @ParameterizedTest - @CsvSource({ - "-1628367672438123811, -97927322516725738, 60", - "3279208082627834682, 4234564566706285432, 61", - "9223372036854775807, 9223372036854775806, 61", - "-9223372036854775808, -9223372036854775807, 61", - }) + @MethodSource(value = "org.apache.commons.statistics.descriptive.IntSumTest#testLongOverflow") void testLongOverflow(long x, long y, int exp) { final LongMean s = LongMean.of(x, y); final double mean = BigInteger.valueOf(x) 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 6b02e5f..3f94c4f 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 @@ -24,7 +24,8 @@ import org.apache.commons.statistics.distribution.DoubleTolerance; import org.apache.commons.statistics.distribution.DoubleTolerances; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * Test for {@link LongSum}. @@ -96,12 +97,7 @@ final class LongSumTest extends BaseLongStatisticTest<LongSum> { * will be incorrect so the test is limited to {@code n < 2^63}. */ @ParameterizedTest - @CsvSource({ - "-1628367672438123811, -97927322516725738, 60", - "3279208082627834682, 4234564566706285432, 61", - "9223372036854775807, 9223372036854775806, 61", - "-9223372036854775808, -9223372036854775807, 61", - }) + @MethodSource void testLongOverflow(long x, long y, int exp) { final LongSum s = LongSum.of(x, y); BigInteger sum = BigInteger.valueOf(x).add(BigInteger.valueOf(y)); @@ -112,4 +108,12 @@ final class LongSumTest extends BaseLongStatisticTest<LongSum> { Assertions.assertEquals(sum, s.getAsBigInteger()); } } + + static Stream<Arguments> testLongOverflow() { + return Stream.of( + Arguments.of(-1628367672438123811L, -97927322516725738L, 60), + Arguments.of(3279208082627834682L, 4234564566706285432L, 61), + Arguments.of(9223372036854775807L, 9223372036854775806L, 61), + Arguments.of(-9223372036854775808L, -9223372036854775807L, 61)); + } }