You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2025/03/24 16:13:09 UTC

(commons-statistics) branch master updated (0998fa6 -> 32b8ad6)

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git


    from 0998fa6  Track changes
     new e23ed4f  Sonar fix: Replace lambda with function reference
     new c4257cd  Update comments to avoid Sonarcloud false positive
     new fdad1f8  Sonar fix: assert throws lambda to have one invocation under test
     new ef2a769  Sonar fix: replace lambda with method reference
     new f7f2623  Correct comment
     new 84e42ef  Sonar fix: replace lambda with method reference
     new 070d928  Sonar fix: remove useless assignment
     new e17836c  Sonar fix: remove use of restricted keyword var
     new 510579a  Update comments to avoid Sonarcloud code detection
     new 5174f56  Comment out timing code
     new 32b8ad6  Update comments to avoid Sonarcloud false positives

The 11 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../descriptive/BaseDoubleStatisticTest.java       |  2 +-
 .../descriptive/BaseIntStatisticTest.java          |  2 +-
 .../descriptive/BaseLongStatisticTest.java         |  2 +-
 .../descriptive/DoubleStatisticsTest.java          |  2 +-
 .../commons/statistics/descriptive/Int128Test.java |  4 ++--
 .../statistics/descriptive/IntStatisticsTest.java  |  2 +-
 .../statistics/descriptive/LongStatisticsTest.java |  2 +-
 .../commons/statistics/descriptive/MeanTest.java   |  4 ++--
 .../commons/statistics/descriptive/MedianTest.java |  6 +++--
 .../statistics/descriptive/QuantileTest.java       | 26 ++++++++++++----------
 .../descriptive/StatisticResultTest.java           | 12 +++++-----
 .../commons/statistics/descriptive/TestData.java   |  2 +-
 .../commons/statistics/descriptive/TestHelper.java |  8 +++----
 .../statistics/descriptive/UInt128Test.java        | 10 ++++-----
 .../statistics/descriptive/UInt192Test.java        | 18 +++++++--------
 .../statistics/descriptive/VarianceTest.java       |  4 ++--
 .../distribution/NakagamiDistributionTest.java     |  2 +-
 .../distribution/PoissonDistributionTest.java      |  3 +--
 .../distribution/TrapezoidalDistributionTest.java  |  4 ++--
 .../TruncatedNormalDistributionTest.java           | 18 +++++++--------
 .../statistics/distribution/UserGuideTest.java     |  4 ++--
 .../KolmogorovSmirnovDistributionTest.java         | 23 ++++++++++---------
 .../inference/KolmogorovSmirnovTestTest.java       |  3 +--
 23 files changed, 83 insertions(+), 80 deletions(-)


(commons-statistics) 08/11: Sonar fix: remove use of restricted keyword var

Posted by ah...@apache.org.
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 e17836cb1dbae0855691e568b3256f0a1a696a92
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Mar 24 15:54:32 2025 +0000

    Sonar fix: remove use of restricted keyword var
---
 .../distribution/NakagamiDistributionTest.java         |  2 +-
 .../distribution/TrapezoidalDistributionTest.java      |  4 ++--
 .../distribution/TruncatedNormalDistributionTest.java  | 18 +++++++++---------
 .../commons/statistics/distribution/UserGuideTest.java |  4 ++--
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/NakagamiDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/NakagamiDistributionTest.java
index 711cf68..bc1b2ae 100644
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/NakagamiDistributionTest.java
+++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/NakagamiDistributionTest.java
@@ -101,7 +101,7 @@ class NakagamiDistributionTest extends BaseContinuousDistributionTest {
         // #define quad boost::multiprecision::float128
         // T v = boost::math::tgamma_delta_ratio(mu, T(0.5));
         // T mean = sqrt(omega / mu) / v;
-        // T var = omega - (omega / mu) / v / v;
+        // T variance = omega - (omega / mu) / v / v;
         "175, 0.75, 0.865407035923572335404337637742305354, 0.00107066217397678136642741884083229635",
         "175, 1, 0.999285970298141244170512691211913862, 0.0014275495653023751552365584544430618",
         "175, 1.25, 1.11723567927423980521693795242933784, 0.00178443695662796894404569806805382725",
diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TrapezoidalDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TrapezoidalDistributionTest.java
index 0d0915c..361a6a8 100644
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TrapezoidalDistributionTest.java
+++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TrapezoidalDistributionTest.java
@@ -128,8 +128,8 @@ class TrapezoidalDistributionTest extends BaseContinuousDistributionTest {
         divisor = divisor.multiply(BigDecimal.valueOf(2));
         dc = dd.pow(4).subtract(cc.pow(4)).divide(dd.subtract(cc), mc);
         ba = bb.pow(4).subtract(aa.pow(4)).divide(bb.subtract(aa), mc);
-        final BigDecimal var = dc.subtract(ba).divide(divisor, mc).subtract(mu.pow(2));
-        return Arguments.of(a, b, c, d, mu.doubleValue(), var.doubleValue(), ulps);
+        final BigDecimal variance = dc.subtract(ba).divide(divisor, mc).subtract(mu.pow(2));
+        return Arguments.of(a, b, c, d, mu.doubleValue(), variance.doubleValue(), ulps);
     }
 
     /**
diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TruncatedNormalDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TruncatedNormalDistributionTest.java
index 50d55de..919654e 100644
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TruncatedNormalDistributionTest.java
+++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TruncatedNormalDistributionTest.java
@@ -340,10 +340,10 @@ class TruncatedNormalDistributionTest extends BaseContinuousDistributionTest {
             // Allow small absolute variances using an absolute threshold of
             // machine epsilon (2^-52) * 1.5. Any true variance approaching machine epsilon
             // is allowed to be computed as small or zero but cannot be too large.
-            final double var = TruncatedNormalDistribution.variance(lower, upper);
-            Assertions.assertTrue(var >= 0, () -> "Variance is not positive: " + var);
-            Assertions.assertEquals(var, TruncatedNormalDistribution.variance(-upper, -lower));
-            TestUtils.assertEquals(variance, var,
+            final double v = TruncatedNormalDistribution.variance(lower, upper);
+            Assertions.assertTrue(v >= 0, () -> "Variance is not positive: " + v);
+            Assertions.assertEquals(v, TruncatedNormalDistribution.variance(-upper, -lower));
+            TestUtils.assertEquals(variance, v,
                     createAbsOrRelTolerance(1.5 * 0x1.0p-52, -varianceRelativeError),
                 () -> String.format("variance(%s, %s)", lower, upper));
         } else {
@@ -378,9 +378,9 @@ class TruncatedNormalDistributionTest extends BaseContinuousDistributionTest {
      * Assert the variance of the truncated normal distribution is within the provided relative error.
      */
     private static void assertVariance(double lower, double upper, double expected, double eps) {
-        final double var = TruncatedNormalDistribution.variance(lower, upper);
-        Assertions.assertEquals(var, TruncatedNormalDistribution.variance(-upper, -lower));
-        TestUtils.assertEquals(expected, var, DoubleTolerances.relative(eps),
+        final double variance = TruncatedNormalDistribution.variance(lower, upper);
+        Assertions.assertEquals(variance, TruncatedNormalDistribution.variance(-upper, -lower));
+        TestUtils.assertEquals(expected, variance, DoubleTolerances.relative(eps),
             () -> String.format("variance(%s, %s)", lower, upper));
     }
 
@@ -392,8 +392,8 @@ class TruncatedNormalDistributionTest extends BaseContinuousDistributionTest {
     private static void assertVariance(double lower, double upper, double u, double s, double expected, double eps) {
         final double a = (lower - u) / s;
         final double b = (upper - u) / s;
-        final double var = TruncatedNormalDistribution.variance(a, b) * s * s;
-        TestUtils.assertEquals(expected, var, DoubleTolerances.relative(eps),
+        final double variance = TruncatedNormalDistribution.variance(a, b) * s * s;
+        TestUtils.assertEquals(expected, variance, DoubleTolerances.relative(eps),
             () -> String.format("variance(%s, %s, %s, %s)", lower, upper, u, s));
     }
 }
diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/UserGuideTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/UserGuideTest.java
index 6e0ac77..c1bbb98 100644
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/UserGuideTest.java
+++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/UserGuideTest.java
@@ -63,7 +63,7 @@ class UserGuideTest {
         ChiSquaredDistribution chi2 = ChiSquaredDistribution.of(42);
         double df = chi2.getDegreesOfFreedom();    // 42
         double mean = chi2.getMean();              // 42
-        double var = chi2.getVariance();           // 84
+        double variance = chi2.getVariance();           // 84
 
         CauchyDistribution cauchy = CauchyDistribution.of(1.23, 4.56);
         double location = cauchy.getLocation();    // 1.23
@@ -73,7 +73,7 @@ class UserGuideTest {
 
         Assertions.assertEquals(42, df);
         Assertions.assertEquals(42, mean);
-        Assertions.assertEquals(84, var);
+        Assertions.assertEquals(84, variance);
         Assertions.assertEquals(1.23, location);
         Assertions.assertEquals(4.56, scale);
         Assertions.assertEquals(Double.NaN, undefined1);


(commons-statistics) 11/11: Update comments to avoid Sonarcloud false positives

Posted by ah...@apache.org.
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 32b8ad699ba0fa017b703e910ab52df049034c89
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Mar 24 16:11:44 2025 +0000

    Update comments to avoid Sonarcloud false positives
---
 .../apache/commons/statistics/inference/KolmogorovSmirnovTestTest.java | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/commons-statistics-inference/src/test/java/org/apache/commons/statistics/inference/KolmogorovSmirnovTestTest.java b/commons-statistics-inference/src/test/java/org/apache/commons/statistics/inference/KolmogorovSmirnovTestTest.java
index 9fa95c9..a81953f 100644
--- a/commons-statistics-inference/src/test/java/org/apache/commons/statistics/inference/KolmogorovSmirnovTestTest.java
+++ b/commons-statistics-inference/src/test/java/org/apache/commons/statistics/inference/KolmogorovSmirnovTestTest.java
@@ -791,14 +791,13 @@ class KolmogorovSmirnovTestTest {
             if (p == 1) {
                 break;
             }
-            //TestUtils.printf("%s", p);
             double x = dnm / ((double) n * m);
             final double en = ((double) m * n) / ((double) m + n);
             final double p1 = KolmogorovSmirnovDistribution.Two.sf(x, (int) Math.round(en));
             final double e1 = Math.abs(p - p1) / Math.max(p, p1);
             x *= Math.sqrt(en);
             // From wikipedia:
-            //x = x + 1.0 / (6 * Math.sqrt(en)) + (x - 1) / (4 * en);
+            //x = x + 1.0 / (6 * Math.sqrt(en)) + (x - 1) / (4 * en)
             final double p2 = KolmogorovSmirnovDistribution.ksSum(x);
             final double e2 = Math.abs(p - p2) / Math.max(p, p2);
             if (e1 > maxe1) {


(commons-statistics) 03/11: Sonar fix: assert throws lambda to have one invocation under test

Posted by ah...@apache.org.
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 fdad1f807822ce81a6d95d881bae62cc3629861f
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Mar 24 15:32:36 2025 +0000

    Sonar fix: assert throws lambda to have one invocation under test
---
 .../org/apache/commons/statistics/descriptive/MedianTest.java  |  6 ++++--
 .../apache/commons/statistics/descriptive/QuantileTest.java    | 10 ++++++----
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MedianTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MedianTest.java
index dfc4423..68f5204 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MedianTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MedianTest.java
@@ -191,8 +191,9 @@ class MedianTest {
     @MethodSource(value = {"org.apache.commons.statistics.descriptive.TestData#arrayRangeTestData"})
     final void testDoubleMedianRangeThrows(int from, int to, int length) {
         final double[] values = new double[length];
+        final Median m = Median.withDefaults();
         Assertions.assertThrows(IndexOutOfBoundsException.class,
-            () -> Median.withDefaults().evaluateRange(values, from, to),
+            () -> m.evaluateRange(values, from, to),
             () -> String.format("range [%d, %d) in length %d", from, to, length));
     }
 
@@ -339,8 +340,9 @@ class MedianTest {
     @MethodSource(value = {"org.apache.commons.statistics.descriptive.TestData#arrayRangeTestData"})
     final void testIntMedianRangeThrows(int from, int to, int length) {
         final int[] values = new int[length];
+        final Median m = Median.withDefaults();
         Assertions.assertThrows(IndexOutOfBoundsException.class,
-            () -> Median.withDefaults().evaluateRange(values, from, to),
+            () -> m.evaluateRange(values, from, to),
             () -> String.format("range [%d, %d) in length %d", from, to, length));
     }
 
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/QuantileTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/QuantileTest.java
index ebd8faf..06ea4cf 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/QuantileTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/QuantileTest.java
@@ -430,10 +430,11 @@ class QuantileTest {
     final void testDoubleQuantileRangeThrows(int from, int to, int length) {
         final double[] values = new double[length];
         final Supplier<String> msg = () -> String.format("range [%d, %d) in length %d", from, to, length);
+        final Quantile q = Quantile.withDefaults();
         Assertions.assertThrows(IndexOutOfBoundsException.class,
-            () -> Quantile.withDefaults().evaluateRange(values, from, to, 0.5), msg);
+            () -> q.evaluateRange(values, from, to, 0.5), msg);
         Assertions.assertThrows(IndexOutOfBoundsException.class,
-            () -> Quantile.withDefaults().evaluateRange(values, from, to, 0.25, 0.5), msg);
+            () -> q.evaluateRange(values, from, to, 0.25, 0.5), msg);
     }
 
     /**
@@ -718,10 +719,11 @@ class QuantileTest {
     final void testIntQuantileRangeThrows(int from, int to, int length) {
         final int[] values = new int[length];
         final Supplier<String> msg = () -> String.format("range [%d, %d) in length %d", from, to, length);
+        final Quantile q = Quantile.withDefaults();
         Assertions.assertThrows(IndexOutOfBoundsException.class,
-            () -> Quantile.withDefaults().evaluateRange(values, from, to, 0.5), msg);
+            () -> q.evaluateRange(values, from, to, 0.5), msg);
         Assertions.assertThrows(IndexOutOfBoundsException.class,
-            () -> Quantile.withDefaults().evaluateRange(values, from, to, 0.25, 0.5), msg);
+            () -> q.evaluateRange(values, from, to, 0.25, 0.5), msg);
     }
 
     /**


(commons-statistics) 09/11: Update comments to avoid Sonarcloud code detection

Posted by ah...@apache.org.
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 510579a524d2c252a2e943d803f67b19649e96d2
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Mar 24 15:57:09 2025 +0000

    Update comments to avoid Sonarcloud code detection
---
 .../statistics/inference/KolmogorovSmirnovDistributionTest.java     | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/commons-statistics-inference/src/test/java/org/apache/commons/statistics/inference/KolmogorovSmirnovDistributionTest.java b/commons-statistics-inference/src/test/java/org/apache/commons/statistics/inference/KolmogorovSmirnovDistributionTest.java
index cfd4f0a..18c09bd 100644
--- a/commons-statistics-inference/src/test/java/org/apache/commons/statistics/inference/KolmogorovSmirnovDistributionTest.java
+++ b/commons-statistics-inference/src/test/java/org/apache/commons/statistics/inference/KolmogorovSmirnovDistributionTest.java
@@ -218,20 +218,20 @@ class KolmogorovSmirnovDistributionTest {
     @CsvSource({
         // Note: f = n*x - floor(n*x). 3 cases are {f = 0, 0 < f <= 0.5, 0.5 < f}.
         // 1/n < n*x < 1 - 1/n; 0.754693 < n*x*x < 4
-        // Values of x for n=10 create f of {0.75, 0, 0.25, 0, 0.5, 0.320}
+        // Values of x for n=10 create f of: 0.75, 0, 0.25, 0, 0.5, 0.320
         "0.275, 10, 0.36721918274907195, 2e-16",
         "0.3, 10, 0.27053557479999946, 5e-16",
         "0.325, 10, 0.19329796645948394, 2e-15",
         "0.5, 10, 0.00777741, 2e-13",
         "0.55, 10, 0.0022805103214843725, 4e-13",
         "0.632, 10, 0.00021216261775257054, 8e-14",
-        // Values of x for n=100 create f of {0.690, 0, 0.5, 0.050, 0.90}
+        // Values of x for n=100 create f of: 0.690, 0, 0.5, 0.050, 0.90
         "0.0869, 100, 0.41345306880916205, 5e-16",
         "0.12, 100, 0.10330374901819939, 9e-15",
         "0.125, 100, 0.08050040280210224, 9e-15",
         "0.1605, 100, 0.010204399956967765, 3e-14",
         "0.199, 100, 0.0006024947156633567, 2e-12",
-        // Values of x for n=140 create f of {0.2899, 0.599, 0.40, 0, 0.660}
+        // Values of x for n=140 create f of: 0.2899, 0.599, 0.40, 0, 0.660
         "0.0735, 140, 0.41601087723723057, 5e-16",
         "0.09, 140, 0.1946946629845738, 2e-16",
         "0.11, 140, 0.06252511429470399, 7e-15",


(commons-statistics) 01/11: Sonar fix: Replace lambda with function reference

Posted by ah...@apache.org.
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 e23ed4f00634cb307fcc3a0b2b3427ebbf512e1a
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Mar 24 15:27:55 2025 +0000

    Sonar fix: Replace lambda with function reference
---
 .../apache/commons/statistics/descriptive/BaseDoubleStatisticTest.java  | 2 +-
 .../org/apache/commons/statistics/descriptive/BaseIntStatisticTest.java | 2 +-
 .../apache/commons/statistics/descriptive/BaseLongStatisticTest.java    | 2 +-
 .../org/apache/commons/statistics/descriptive/DoubleStatisticsTest.java | 2 +-
 .../org/apache/commons/statistics/descriptive/IntStatisticsTest.java    | 2 +-
 .../org/apache/commons/statistics/descriptive/LongStatisticsTest.java   | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseDoubleStatisticTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseDoubleStatisticTest.java
index ad99f2a..4deda62 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseDoubleStatisticTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseDoubleStatisticTest.java
@@ -1282,7 +1282,7 @@ abstract class BaseDoubleStatisticTest<S extends DoubleStatistic & StatisticAccu
         final S empty = create();
         assertStatistic(v ->
             Arrays.stream(values)
-                  .mapToObj(x -> create(x))
+                  .mapToObj(this::create)
                   .reduce(empty, this::assertCombine),
             values, expected, tol);
     }
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseIntStatisticTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseIntStatisticTest.java
index 56e826e..b2a7276 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseIntStatisticTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseIntStatisticTest.java
@@ -1171,7 +1171,7 @@ abstract class BaseIntStatisticTest<S extends IntStatistic & StatisticAccumulato
         final S empty = create();
         assertStatistic(v ->
             Arrays.stream(values)
-                  .mapToObj(x -> create(x))
+                  .mapToObj(this::create)
                   .reduce(empty, this::assertCombine),
             values, expected, tol);
     }
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseLongStatisticTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseLongStatisticTest.java
index 5072007..73fa565 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseLongStatisticTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseLongStatisticTest.java
@@ -1170,7 +1170,7 @@ abstract class BaseLongStatisticTest<S extends LongStatistic & StatisticAccumula
         final S empty = create();
         assertStatistic(v ->
             Arrays.stream(values)
-                  .mapToObj(x -> create(x))
+                  .mapToObj(this::create)
                   .reduce(empty, this::assertCombine),
             values, expected, tol);
     }
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/DoubleStatisticsTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/DoubleStatisticsTest.java
index 57255bc..9820b85 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/DoubleStatisticsTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/DoubleStatisticsTest.java
@@ -561,7 +561,7 @@ class DoubleStatisticsTest {
         for (final Statistic s : stat1) {
             final double expected = statistics1.getAsDouble(s);
             assertFinite(expected, s);
-            Assertions.assertEquals(expected, statistics2.getAsDouble(s), () -> s.toString());
+            Assertions.assertEquals(expected, statistics2.getAsDouble(s), s::toString);
         }
     }
 
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntStatisticsTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntStatisticsTest.java
index f52081a..4eedd6f 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntStatisticsTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntStatisticsTest.java
@@ -615,7 +615,7 @@ class IntStatisticsTest {
         for (final Statistic s : stat1) {
             final double expected = statistics1.getAsDouble(s);
             assertFinite(expected, s);
-            Assertions.assertEquals(expected, statistics2.getAsDouble(s), () -> s.toString());
+            Assertions.assertEquals(expected, statistics2.getAsDouble(s), s::toString);
         }
     }
 
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongStatisticsTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongStatisticsTest.java
index e7192f2..8c390de 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongStatisticsTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongStatisticsTest.java
@@ -615,7 +615,7 @@ class LongStatisticsTest {
         for (final Statistic s : stat1) {
             final double expected = statistics1.getAsDouble(s);
             assertFinite(expected, s);
-            Assertions.assertEquals(expected, statistics2.getAsDouble(s), () -> s.toString());
+            Assertions.assertEquals(expected, statistics2.getAsDouble(s), s::toString);
         }
     }
 


(commons-statistics) 06/11: Sonar fix: replace lambda with method reference

Posted by ah...@apache.org.
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 84e42ef5073e81a7421a2ad3f833bab033f52e98
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Mar 24 15:44:53 2025 +0000

    Sonar fix: replace lambda with method reference
---
 .../commons/statistics/descriptive/Int128Test.java     |  4 ++--
 .../commons/statistics/descriptive/TestHelper.java     |  8 ++++----
 .../commons/statistics/descriptive/UInt128Test.java    | 10 +++++-----
 .../commons/statistics/descriptive/UInt192Test.java    | 18 +++++++++---------
 4 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/Int128Test.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/Int128Test.java
index a6aab0a..b445474 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/Int128Test.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/Int128Test.java
@@ -186,7 +186,7 @@ class Int128Test {
         Assertions.assertEquals(x, v.toIntExact());
         final int y = x < 0 ? -1 : 1;
         v.add(y);
-        Assertions.assertThrows(ArithmeticException.class, () -> v.toIntExact());
+        Assertions.assertThrows(ArithmeticException.class, v::toIntExact);
         v.add(-y);
         Assertions.assertEquals(x, v.toIntExact());
     }
@@ -198,7 +198,7 @@ class Int128Test {
         Assertions.assertEquals(x, v.toLongExact());
         final int y = x < 0 ? -1 : 1;
         v.add(y);
-        Assertions.assertThrows(ArithmeticException.class, () -> v.toLongExact());
+        Assertions.assertThrows(ArithmeticException.class, v::toLongExact);
         v.add(-y);
         Assertions.assertEquals(x, v.toLongExact());
     }
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 aa080d1..31289a8 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
@@ -301,7 +301,7 @@ final class TestHelper {
         try {
             i = expected.getAsInt();
         } catch (final Throwable t) {
-            Assertions.assertThrowsExactly(t.getClass(), () -> actual.getAsInt(), intMsg);
+            Assertions.assertThrowsExactly(t.getClass(), actual::getAsInt, intMsg);
         }
         if (i != null) {
             Assertions.assertEquals(i.intValue(), actual.getAsInt(), intMsg);
@@ -325,7 +325,7 @@ final class TestHelper {
         try {
             l = expected.getAsLong();
         } catch (final Throwable t) {
-            Assertions.assertThrowsExactly(t.getClass(), () -> actual.getAsLong(), longMsg);
+            Assertions.assertThrowsExactly(t.getClass(), actual::getAsLong, longMsg);
         }
         if (l != null) {
             Assertions.assertEquals(l.longValue(), actual.getAsLong(), longMsg);
@@ -355,7 +355,7 @@ final class TestHelper {
         try {
             d = expected.getAsDouble();
         } catch (final Throwable t) {
-            Assertions.assertThrowsExactly(t.getClass(), () -> actual.getAsDouble(), doubleMsg);
+            Assertions.assertThrowsExactly(t.getClass(), actual::getAsDouble, doubleMsg);
         }
         if (d != null) {
             if (tol == null) {
@@ -391,7 +391,7 @@ final class TestHelper {
         try {
             b = expected.getAsBigInteger();
         } catch (final Throwable t) {
-            Assertions.assertThrowsExactly(t.getClass(), () -> actual.get(), bigMsg);
+            Assertions.assertThrowsExactly(t.getClass(), actual::get, bigMsg);
         }
         if (b != null) {
             if (tol == null) {
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/UInt128Test.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/UInt128Test.java
index 0c24df2..5fab650 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/UInt128Test.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/UInt128Test.java
@@ -243,17 +243,17 @@ class UInt128Test {
         final UInt128 v = new UInt128(0, x);
         Assertions.assertEquals(x, v.toIntExact());
         v.addPositive(1);
-        Assertions.assertThrows(ArithmeticException.class, () -> v.toIntExact());
+        Assertions.assertThrows(ArithmeticException.class, v::toIntExact);
         Assertions.assertEquals(0x1.0p31, v.toDouble());
         Assertions.assertEquals(y, v.toLongExact());
         // 2^32 has no low bits - check the result is not returned as zero
         final UInt128 v2 = new UInt128(0, 2 * y);
-        Assertions.assertThrows(ArithmeticException.class, () -> v2.toIntExact());
+        Assertions.assertThrows(ArithmeticException.class, v2::toIntExact);
         Assertions.assertEquals(0x1.0p32, v2.toDouble());
         Assertions.assertEquals(2 * y, v2.toLongExact());
         // 2^64 has no low bits - check the result is not returned as zero
         final UInt128 v3 = new UInt128(1, 0);
-        Assertions.assertThrows(ArithmeticException.class, () -> v3.toIntExact());
+        Assertions.assertThrows(ArithmeticException.class, v3::toIntExact);
         Assertions.assertEquals(0x1.0p64, v3.toDouble());
     }
 
@@ -263,11 +263,11 @@ class UInt128Test {
         final UInt128 v = new UInt128(0, x);
         Assertions.assertEquals(x, v.toLongExact());
         v.addPositive(1);
-        Assertions.assertThrows(ArithmeticException.class, () -> v.toLongExact());
+        Assertions.assertThrows(ArithmeticException.class, v::toLongExact);
         Assertions.assertEquals(0x1.0p63, v.toDouble());
         // 2^64 has no low bits - check the result is not returned as zero
         final UInt128 v3 = new UInt128(1, 0);
-        Assertions.assertThrows(ArithmeticException.class, () -> v3.toLongExact());
+        Assertions.assertThrows(ArithmeticException.class, v3::toLongExact);
         Assertions.assertEquals(0x1.0p64, v3.toDouble());
     }
 }
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/UInt192Test.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/UInt192Test.java
index 0edf578..435e9d7 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/UInt192Test.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/UInt192Test.java
@@ -212,25 +212,25 @@ class UInt192Test {
         final UInt192 v = new UInt192(0, 0, x);
         Assertions.assertEquals(x, v.toIntExact());
         v.addSquare(1);
-        Assertions.assertThrows(ArithmeticException.class, () -> v.toIntExact());
+        Assertions.assertThrows(ArithmeticException.class, v::toIntExact);
         Assertions.assertEquals(0x1.0p31, v.toDouble());
         Assertions.assertEquals(y, v.toLongExact());
         // 2^32 has no low bits - check the result is not returned as zero
         final UInt192 v2 = new UInt192(0, 0, 2 * y);
-        Assertions.assertThrows(ArithmeticException.class, () -> v2.toIntExact());
+        Assertions.assertThrows(ArithmeticException.class, v2::toIntExact);
         Assertions.assertEquals(0x1.0p32, v2.toDouble());
         Assertions.assertEquals(2 * y, v2.toLongExact());
         // 2^64 has no low bits - check the result is not returned as zero
         final UInt192 v3 = new UInt192(0, 1, 0);
-        Assertions.assertThrows(ArithmeticException.class, () -> v3.toIntExact());
+        Assertions.assertThrows(ArithmeticException.class, v3::toIntExact);
         Assertions.assertEquals(0x1.0p64, v3.toDouble());
         // 2^96 has no low bits - check the result is not returned as zero
         final UInt192 v4 = new UInt192(0, 1L << 32, 0);
-        Assertions.assertThrows(ArithmeticException.class, () -> v4.toIntExact());
+        Assertions.assertThrows(ArithmeticException.class, v4::toIntExact);
         Assertions.assertEquals(0x1.0p96, v4.toDouble());
         // 2^128 has no low bits - check the result is not returned as zero
         final UInt192 v5 = new UInt192(1, 0, 0);
-        Assertions.assertThrows(ArithmeticException.class, () -> v5.toIntExact());
+        Assertions.assertThrows(ArithmeticException.class, v5::toIntExact);
         Assertions.assertEquals(0x1.0p128, v5.toDouble());
     }
 
@@ -240,19 +240,19 @@ class UInt192Test {
         final UInt192 v = new UInt192(0, 0, x);
         Assertions.assertEquals(x, v.toLongExact());
         v.addSquare(1);
-        Assertions.assertThrows(ArithmeticException.class, () -> v.toLongExact());
+        Assertions.assertThrows(ArithmeticException.class, v::toLongExact);
         Assertions.assertEquals(0x1.0p63, v.toDouble());
         // 2^64 has no low bits - check the result is not returned as zero
         final UInt192 v3 = new UInt192(0, 1, 0);
-        Assertions.assertThrows(ArithmeticException.class, () -> v3.toLongExact());
+        Assertions.assertThrows(ArithmeticException.class, v3::toLongExact);
         Assertions.assertEquals(0x1.0p64, v3.toDouble());
         // 2^96 has no low bits - check the result is not returned as zero
         final UInt192 v4 = new UInt192(0, 1L << 32, 0);
-        Assertions.assertThrows(ArithmeticException.class, () -> v4.toLongExact());
+        Assertions.assertThrows(ArithmeticException.class, v4::toLongExact);
         Assertions.assertEquals(0x1.0p96, v4.toDouble());
         // 2^128 has no low bits - check the result is not returned as zero
         final UInt192 v5 = new UInt192(1, 0, 0);
-        Assertions.assertThrows(ArithmeticException.class, () -> v5.toLongExact());
+        Assertions.assertThrows(ArithmeticException.class, v5::toLongExact);
         Assertions.assertEquals(0x1.0p128, v5.toDouble());
     }
 


(commons-statistics) 05/11: Correct comment

Posted by ah...@apache.org.
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 f7f262385a3f4b979420d86d296b665b320f9ccc
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Mar 24 15:36:56 2025 +0000

    Correct comment
---
 .../test/java/org/apache/commons/statistics/descriptive/TestData.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestData.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestData.java
index 2c81820..ad8b3c1 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestData.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestData.java
@@ -40,7 +40,7 @@ final class TestData {
             new double[] {10E-50, 5E-100, 25E-200, 35.345E-50},
             // Small numbers
             new double[] {0.001, 0.0002, 0.00003, 10000.11, 0.000004},
-            // Overflow of the sum which prevents using the sum for the mean}
+            // Overflow of the sum which prevents using the sum for the mean
             new double[] {max, max},
             new double[] {-max, -max},
             new double[] {max, max, max, max},


(commons-statistics) 04/11: Sonar fix: replace lambda with method reference

Posted by ah...@apache.org.
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 ef2a76908042bf9d69ae53447874978042c05cc9
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Mar 24 15:36:44 2025 +0000

    Sonar fix: replace lambda with method reference
---
 .../commons/statistics/descriptive/QuantileTest.java     | 16 ++++++++--------
 .../statistics/descriptive/StatisticResultTest.java      | 12 ++++++------
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/QuantileTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/QuantileTest.java
index 06ea4cf..47c62fd 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/QuantileTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/QuantileTest.java
@@ -211,18 +211,18 @@ class QuantileTest {
             for (int j = 0; j < p.length; j++) {
                 if (f1 != null) {
                     assertEqualsOrExactlyEqual(expected[i][j], f1.evaluate(m, values.clone(), p[j]), delta,
-                        () -> type.toString());
+                        type::toString);
                 }
                 assertEqualsOrExactlyEqual(expected[i][j], fn.evaluate(m, values.clone(), new double[] {p[j]})[0], delta,
-                    () -> type.toString());
+                    type::toString);
             }
             // Bulk quantiles
             if (delta < 0) {
                 Assertions.assertArrayEquals(expected[i], fn.evaluate(m, values.clone(), p),
-                    () -> type.toString());
+                    type::toString);
             } else {
                 Assertions.assertArrayEquals(expected[i], fn.evaluate(m, values.clone(), p), delta,
-                    () -> type.toString());
+                    type::toString);
             }
         }
     }
@@ -557,18 +557,18 @@ class QuantileTest {
             for (int j = 0; j < p.length; j++) {
                 if (f1 != null) {
                     assertEqualsOrExactlyEqual(expected[i][j], f1.evaluate(m, values.clone(), p[j]), delta,
-                        () -> type.toString());
+                        type::toString);
                 }
                 assertEqualsOrExactlyEqual(expected[i][j], fn.evaluate(m, values.clone(), new double[] {p[j]})[0], delta,
-                    () -> type.toString());
+                    type::toString);
             }
             // Bulk quantiles
             if (delta < 0) {
                 Assertions.assertArrayEquals(expected[i], fn.evaluate(m, values.clone(), p),
-                    () -> type.toString());
+                    type::toString);
             } else {
                 Assertions.assertArrayEquals(expected[i], fn.evaluate(m, values.clone(), p), delta,
-                    () -> type.toString());
+                    type::toString);
             }
         }
     }
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/StatisticResultTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/StatisticResultTest.java
index a6a13af..87638f2 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/StatisticResultTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/StatisticResultTest.java
@@ -57,9 +57,9 @@ final class StatisticResultTest {
     @ValueSource(doubles = {Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY})
     void testNonFinite(double x) {
         final StatisticResult r = () -> x;
-        Assertions.assertThrows(ArithmeticException.class, () -> r.getAsInt(), "int result: " + x);
-        Assertions.assertThrows(ArithmeticException.class, () -> r.getAsLong(), "long result: " + x);
-        Assertions.assertThrows(ArithmeticException.class, () -> r.getAsBigInteger(), "BigInteger result: " + x);
+        Assertions.assertThrows(ArithmeticException.class, r::getAsInt, "int result: " + x);
+        Assertions.assertThrows(ArithmeticException.class, r::getAsLong, "long result: " + x);
+        Assertions.assertThrows(ArithmeticException.class, r::getAsBigInteger, "BigInteger result: " + x);
     }
 
     @ParameterizedTest
@@ -92,7 +92,7 @@ final class StatisticResultTest {
     void testNonRepresentableInt(double x) {
         final StatisticResult r = () -> x;
         final BigDecimal expected = round(x);
-        Assertions.assertThrows(ArithmeticException.class, () -> r.getAsInt(), () -> "int result: " + x);
+        Assertions.assertThrows(ArithmeticException.class, r::getAsInt, () -> "int result: " + x);
         Assertions.assertEquals(expected.longValue(), r.getAsLong(), () -> "long result: " + x);
         Assertions.assertEquals(expected.toBigInteger(), r.getAsBigInteger(), () -> "BigInteger result: " + x);
     }
@@ -108,8 +108,8 @@ final class StatisticResultTest {
     void testNonRepresentableLong(double x) {
         final StatisticResult r = () -> x;
         final BigDecimal expected = round(x);
-        Assertions.assertThrows(ArithmeticException.class, () -> r.getAsInt(), () -> "int result: " + x);
-        Assertions.assertThrows(ArithmeticException.class, () -> r.getAsLong(), () -> "long result: " + x);
+        Assertions.assertThrows(ArithmeticException.class, r::getAsInt, () -> "int result: " + x);
+        Assertions.assertThrows(ArithmeticException.class, r::getAsLong, () -> "long result: " + x);
         Assertions.assertEquals(expected.toBigInteger(), r.getAsBigInteger(), () -> "BigInteger result: " + x);
     }
 


(commons-statistics) 10/11: Comment out timing code

Posted by ah...@apache.org.
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 5174f56ee06e2dc6f3631f284da9384fd8eabd3b
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Mar 24 16:05:13 2025 +0000

    Comment out timing code
---
 .../inference/KolmogorovSmirnovDistributionTest.java    | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/commons-statistics-inference/src/test/java/org/apache/commons/statistics/inference/KolmogorovSmirnovDistributionTest.java b/commons-statistics-inference/src/test/java/org/apache/commons/statistics/inference/KolmogorovSmirnovDistributionTest.java
index 18c09bd..cbce2c7 100644
--- a/commons-statistics-inference/src/test/java/org/apache/commons/statistics/inference/KolmogorovSmirnovDistributionTest.java
+++ b/commons-statistics-inference/src/test/java/org/apache/commons/statistics/inference/KolmogorovSmirnovDistributionTest.java
@@ -128,8 +128,7 @@ class KolmogorovSmirnovDistributionTest {
         "0.000922, 50000, 0.999999999996305, 2e-16",
     })
     void testDurbinMTW(double x, int n, double p, double eps) {
-        final double p2 = KolmogorovSmirnovDistribution.Two.sf(x, n);
-        TestUtils.assertProbability(p, p2, eps, "sf");
+        testTwoSf(x, n, p, eps);
     }
 
     /**
@@ -239,6 +238,10 @@ class KolmogorovSmirnovDistributionTest {
         "0.169, 140, 0.0005778682806183945, 2e-13",
     })
     void testPomeranz(double x, int n, double p, double eps) {
+        testTwoSf(x, n, p, eps);
+    }
+
+    private void testTwoSf(double x, int n, double p, double eps) {
         final double p2 = KolmogorovSmirnovDistribution.Two.sf(x, n);
         TestUtils.assertProbability(p, p2, eps, "sf");
     }
@@ -307,8 +310,7 @@ class KolmogorovSmirnovDistributionTest {
         "0.00044, 150000, 1, 0",
     })
     void testPelzGood(double x, int n, double p, double eps) {
-        final double p2 = KolmogorovSmirnovDistribution.Two.sf(x, n);
-        TestUtils.assertProbability(p, p2, eps, "sf");
+        testTwoSf(x, n, p, eps);
     }
 
     /**
@@ -348,8 +350,7 @@ class KolmogorovSmirnovDistributionTest {
         "0.1, 10000, 1.6633113315950355e-87, 2e-16",
     })
     void testMillerApproximation(double x, int n, double p, double eps) {
-        final double p2 = KolmogorovSmirnovDistribution.Two.sf(x, n);
-        TestUtils.assertProbability(p, p2, eps, "sf");
+        testTwoSf(x, n, p, eps);
     }
 
     /**
@@ -1008,7 +1009,7 @@ class KolmogorovSmirnovDistributionTest {
             return x;
         }
         // Debugging
-        final long start = System.nanoTime();
+        //final long start = System.nanoTime();
         final double p = KolmogorovSmirnovDistribution.One.sf(x, n, power);
         //TestUtils.printf("\"%s, %d, %s\", // %.6fs%n", x, n, p, (System.nanoTime() - start) * 1e-9);
         return p;
@@ -1043,7 +1044,7 @@ class KolmogorovSmirnovDistributionTest {
             return x;
         }
         // Debugging
-        final long start = System.nanoTime();
+        //final long start = System.nanoTime();
         final double p = sf(x, n, mc);
         //TestUtils.printf("\"%s, %d, %s\", // %.6fs%n", x, n, p, (System.nanoTime() - start) * 1e-9);
         return p;


(commons-statistics) 02/11: Update comments to avoid Sonarcloud false positive

Posted by ah...@apache.org.
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 c4257cd46bcc2b7bd3d5cbefc2aee818df14de7a
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Mar 24 15:29:04 2025 +0000

    Update comments to avoid Sonarcloud false positive
---
 .../test/java/org/apache/commons/statistics/descriptive/MeanTest.java | 4 ++--
 .../java/org/apache/commons/statistics/descriptive/VarianceTest.java  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MeanTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MeanTest.java
index 0d89001..080edd1 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MeanTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MeanTest.java
@@ -65,8 +65,8 @@ final class MeanTest extends BaseDoubleStatisticTest<Mean> {
             .average().orElse(getEmptyValue());
     }
 
-    // The full-array method should be more accurate on average;
-    // however the tolerance is for the max error which is similar
+    // The full-array method should be more accurate on average.
+    // However the tolerance is for the max error which is similar
 
     @Override
     protected DoubleTolerance getToleranceAccept() {
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/VarianceTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/VarianceTest.java
index 1391f48..cd99a55 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/VarianceTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/VarianceTest.java
@@ -65,8 +65,8 @@ final class VarianceTest extends BaseDoubleStatisticTest<Variance> {
         return Double.NaN;
     }
 
-    // The full-array method should be more accurate on average;
-    // however the tolerance is for the max error which is similar
+    // The full-array method should be more accurate on average.
+    // However the tolerance is for the max error which is similar
 
     @Override
     protected DoubleTolerance getToleranceAccept() {


(commons-statistics) 07/11: Sonar fix: remove useless assignment

Posted by ah...@apache.org.
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 070d92844bd1197a5de35a3c472a8e1a328544fe
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Mar 24 15:50:42 2025 +0000

    Sonar fix: remove useless assignment
---
 .../commons/statistics/distribution/PoissonDistributionTest.java       | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/PoissonDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/PoissonDistributionTest.java
index ed548b0..93f0424 100644
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/PoissonDistributionTest.java
+++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/PoissonDistributionTest.java
@@ -63,11 +63,10 @@ class PoissonDistributionTest extends BaseDiscreteDistributionTest {
 
             double x = mean * 2.0;
             final double dx = x / 10.0;
-            double p = Double.NaN;
             final double sigma = Math.sqrt(mean);
             while (x >= 0) {
                 try {
-                    p = dist.cumulativeProbability((int) x);
+                    final double p = dist.cumulativeProbability((int) x);
                     Assertions.assertFalse(Double.isNaN(p), "NaN cumulative probability");
                     if (x > mean - 2 * sigma) {
                         Assertions.assertTrue(p > 0, "Zero cumulative probaility");