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 2022/05/04 15:46:14 UTC

[commons-rng] 01/03: Sonar fix: Use @ParameterizedTest

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-rng.git

commit ee10ce308798b7df8b811031c52dfdc9754c22d4
Author: aherbert <ah...@apache.org>
AuthorDate: Wed May 4 16:21:39 2022 +0100

    Sonar fix: Use @ParameterizedTest
---
 .../GuideTableDiscreteSamplerTest.java             | 30 +++++-----------------
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GuideTableDiscreteSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GuideTableDiscreteSamplerTest.java
index f715476b..0f518367 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GuideTableDiscreteSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GuideTableDiscreteSamplerTest.java
@@ -24,6 +24,8 @@ import org.apache.commons.rng.sampling.RandomAssert;
 import org.apache.commons.rng.simple.RandomSource;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 /**
  * Test for the {@link GuideTableDiscreteSampler}.
@@ -126,31 +128,13 @@ class GuideTableDiscreteSamplerTest {
 
     /**
      * Test sampling from a non-uniform distribution of probabilities (these sum to 1).
+     * The alpha used in the default (1.0) or a smaller or larger value than the default.
      */
-    @Test
-    void testNonUniformSamplesWithProbabilities() {
-        final double[] expected = {0.1, 0.2, 0.3, 0.1, 0.3};
-        checkSamples(expected, 1.0);
-    }
-
-    /**
-     * Test sampling from a non-uniform distribution of probabilities with an alpha smaller than
-     * the default.
-     */
-    @Test
-    void testNonUniformSamplesWithProbabilitiesWithSmallAlpha() {
-        final double[] expected = {0.1, 0.2, 0.3, 0.1, 0.3};
-        checkSamples(expected, 0.1);
-    }
-
-    /**
-     * Test sampling from a non-uniform distribution of probabilities with an alpha larger than
-     * the default.
-     */
-    @Test
-    void testNonUniformSamplesWithProbabilitiesWithLargeAlpha() {
+    @ParameterizedTest
+    @ValueSource(doubles = {1.0, 0.1, 10.0})
+    void testNonUniformSamplesWithProbabilities(double alpha) {
         final double[] expected = {0.1, 0.2, 0.3, 0.1, 0.3};
-        checkSamples(expected, 10.0);
+        checkSamples(expected, alpha);
     }
 
     /**