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 2023/02/03 13:46:49 UTC
[commons-rng] branch master updated: Replace expected array with a single expected value
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
The following commit(s) were added to refs/heads/master by this push:
new f2cd7a2d Replace expected array with a single expected value
f2cd7a2d is described below
commit f2cd7a2d7e860745ca9bde4a2c6368b00153cf58
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Fri Feb 3 13:46:26 2023 +0000
Replace expected array with a single expected value
---
.../java/org/apache/commons/rng/UniformRandomProviderTest.java | 8 +++-----
.../apache/commons/rng/core/ProvidersCommonParametricTest.java | 8 +++-----
.../sampling/distribution/ContinuousSamplerParametricTest.java | 7 +++----
3 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/commons-rng-client-api/src/test/java/org/apache/commons/rng/UniformRandomProviderTest.java b/commons-rng-client-api/src/test/java/org/apache/commons/rng/UniformRandomProviderTest.java
index cfb40f96..48a80517 100644
--- a/commons-rng-client-api/src/test/java/org/apache/commons/rng/UniformRandomProviderTest.java
+++ b/commons-rng-client-api/src/test/java/org/apache/commons/rng/UniformRandomProviderTest.java
@@ -546,9 +546,7 @@ class UniformRandomProviderTest {
// Bins.
final long[] observed = new long[byteRange];
- final double[] expected = new double[byteRange];
-
- Arrays.fill(expected, sampleSize * (last - first) / (double) byteRange);
+ final double expected = (double) sampleSize * (last - first) / byteRange;
for (int k = 0; k < sampleSize; k++) {
nextMethod.run();
@@ -562,8 +560,8 @@ class UniformRandomProviderTest {
// Compute chi-square.
double chi2 = 0;
for (int k = 0; k < byteRange; k++) {
- final double diff = observed[k] - expected[k];
- chi2 += diff * diff / expected[k];
+ final double diff = observed[k] - expected;
+ chi2 += diff * diff / expected;
}
// Statistics check.
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/ProvidersCommonParametricTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/ProvidersCommonParametricTest.java
index 6749906d..674c7800 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/ProvidersCommonParametricTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/ProvidersCommonParametricTest.java
@@ -311,9 +311,7 @@ class ProvidersCommonParametricTest {
// Bins.
final long[] observed = new long[byteRange];
- final double[] expected = new double[byteRange];
-
- Arrays.fill(expected, sampleSize * (last - first) / (double) byteRange);
+ final double expected = (double) sampleSize * (last - first) / byteRange;
try {
for (int k = 0; k < sampleSize; k++) {
@@ -332,8 +330,8 @@ class ProvidersCommonParametricTest {
// Compute chi-square.
double chi2 = 0;
for (int k = 0; k < byteRange; k++) {
- final double diff = observed[k] - expected[k];
- chi2 += diff * diff / expected[k];
+ final double diff = observed[k] - expected;
+ chi2 += diff * diff / expected;
}
// Statistics check.
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousSamplerParametricTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousSamplerParametricTest.java
index d293b569..ecd4e6a6 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousSamplerParametricTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousSamplerParametricTest.java
@@ -59,8 +59,7 @@ class ContinuousSamplerParametricTest {
// Run the tests.
int numFailures = 0;
- final double[] expected = new double[numBins];
- Arrays.fill(expected, sampleSize / (double) numBins);
+ final double expected = sampleSize / (double) numBins;
final long[] observed = new long[numBins];
// Chi-square critical value with 9 degrees of freedom
@@ -88,8 +87,8 @@ class ContinuousSamplerParametricTest {
// Compute chi-square.
double chi2 = 0;
for (int k = 0; k < numBins; k++) {
- final double diff = observed[k] - expected[k];
- chi2 += diff * diff / expected[k];
+ final double diff = observed[k] - expected;
+ chi2 += diff * diff / expected;
}
// Statistics check.