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 2021/09/15 19:38:15 UTC

[commons-statistics] branch master updated: Update legacy test

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


The following commit(s) were added to refs/heads/master by this push:
     new 42ae7a4  Update legacy test
42ae7a4 is described below

commit 42ae7a45d48dc72184d9a6d97cb38a94a8bddc93
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Wed Sep 15 20:38:12 2021 +0100

    Update legacy test
    
    Correct path to the reference data Maxima script.
    
    Use try-with-resources.
    
    Remove unthrown exception from signature.
    
    Add notes on the test method parameters.
---
 .../distribution/GammaDistributionTest.java        | 39 ++++++++++++----------
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/GammaDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/GammaDistributionTest.java
index e463065..b1678d0 100644
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/GammaDistributionTest.java
+++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/GammaDistributionTest.java
@@ -259,30 +259,35 @@ class GammaDistributionTest extends ContinuousDistributionAbstractTest {
                Math.exp(-x / scale) / Math.exp(logGamma(shape));
     }
 
-    /*
+    /**
      * MATH-753: large values of x or shape parameter cause density(double) to
      * overflow. Reference data is generated with the Maxima script
      * gamma-distribution.mac, which can be found in
-     * src/test/resources/org/apache/commons/math3/distribution.
+     * src/test/resources/org/apache/commons/statistics/distribution.
+     *
+     * @param shape Shape of gamma distribution (scale is assumed to be 1)
+     * @param meanNoOF Allowed mean ULP error when the computed value does not overflow using the old method
+     * @param sdNoOF Allowed SD ULP error when the computed value does not overflow using the old method
+     * @param meanOF Allowed mean ULP error when the computed value overflows using the old method
+     * @param sdOF Allowed SD ULP error when the computed value overflows using the old method
+     * @param resourceName Resource name containing a pair of comma separated values for the
+     * random variable x and the expected value of the gamma distribution: x, gamma(x; shape, scale=1)
      */
-
     private void doTestMath753(final double shape,
                                final double meanNoOF, final double sdNoOF,
                                final double meanOF, final double sdOF,
-                               final String resourceName)
-        throws IOException {
+                               final String resourceName) {
         final GammaDistribution distribution = new GammaDistribution(shape, 1.0);
         final SummaryStatistics statOld = new SummaryStatistics();
+        // statNewNoOF = No overflow of old function
+        // statNewOF   = Overflow of old function
         final SummaryStatistics statNewNoOF = new SummaryStatistics();
         final SummaryStatistics statNewOF = new SummaryStatistics();
 
-        final InputStream resourceAsStream;
-        resourceAsStream = this.getClass().getResourceAsStream(resourceName);
+        final InputStream resourceAsStream = this.getClass().getResourceAsStream(resourceName);
         Assertions.assertNotNull(resourceAsStream, () -> "Could not find resource " + resourceName);
-        final BufferedReader in;
-        in = new BufferedReader(new InputStreamReader(resourceAsStream));
 
-        try {
+        try (BufferedReader in = new BufferedReader(new InputStreamReader(resourceAsStream))) {
             for (String line = in.readLine(); line != null; line = in.readLine()) {
                 if (line.startsWith("#")) {
                     continue;
@@ -365,40 +370,38 @@ class GammaDistributionTest extends ContinuousDistributionAbstractTest {
             }
         } catch (final IOException e) {
             Assertions.fail(e.getMessage());
-        } finally {
-            in.close();
         }
     }
 
     @Test
-    void testMath753Shape1() throws IOException {
+    void testMath753Shape1() {
         doTestMath753(1.0, 1.5, 0.5, 0.0, 0.0, "gamma-distribution-shape-1.csv");
     }
 
     @Test
-    void testMath753Shape8() throws IOException {
+    void testMath753Shape8() {
         doTestMath753(8.0, 1.5, 1.0, 0.0, 0.0, "gamma-distribution-shape-8.csv");
     }
 
     @Test
-    void testMath753Shape10() throws IOException {
+    void testMath753Shape10() {
         doTestMath753(10.0, 1.0, 1.0, 0.0, 0.0, "gamma-distribution-shape-10.csv");
     }
 
     @Test
-    void testMath753Shape100() throws IOException {
+    void testMath753Shape100() {
         // XXX Increased tolerance ("1.5" -> "2.0") to make test pass with JDK "Math"
         // where CM used "FastMath" (cf. "XXX" comment in main source code).
         doTestMath753(100.0, 2.0, 1.0, 0.0, 0.0, "gamma-distribution-shape-100.csv");
     }
 
     @Test
-    void testMath753Shape142() throws IOException {
+    void testMath753Shape142() {
         doTestMath753(142.0, 3.3, 1.6, 40.0, 40.0, "gamma-distribution-shape-142.csv");
     }
 
     @Test
-    void testMath753Shape1000() throws IOException {
+    void testMath753Shape1000() {
         // XXX Increased tolerance ("220.0" -> "230.0") to make test pass with JDK "Math"
         // where CM used "FastMath" (cf. "XXX" comment in main source code).
         doTestMath753(1000.0, 1.0, 1.0, 160.0, 230.0, "gamma-distribution-shape-1000.csv");