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/08/17 07:08:11 UTC
[commons-rng] 03/13: RNG-163: Replace JUnit 4 Assert with JUnit 5
Assertions
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 07a6dc916a5ab71cc583727c43517cb668c81ad7
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Aug 15 13:55:25 2021 +0100
RNG-163: Replace JUnit 4 Assert with JUnit 5 Assertions
Tests for float equality with a delta of 0.0 have been updated to remove the delta.
Replace JUnit 4 Assume with JUnit 5 Assumptions
---
.../apache/commons/rng/core/BaseProviderTest.java | 18 +-
.../rng/core/JumpableProvidersParametricTest.java | 23 +-
.../rng/core/ProvidersCommonParametricTest.java | 35 +-
.../org/apache/commons/rng/core/RandomAssert.java | 94 +++---
.../rng/core/RandomProviderDefaultStateTest.java | 4 +-
.../commons/rng/core/source32/IntProviderTest.java | 8 +-
.../commons/rng/core/source32/JDKRandomTest.java | 25 +-
.../rng/core/source32/MersenneTwisterTest.java | 6 +-
.../source32/MiddleSquareWeylSequenceTest.java | 4 +-
.../rng/core/source64/LongProviderTest.java | 16 +-
.../rng/core/source64/MersenneTwister64Test.java | 6 +-
.../commons/rng/core/source64/TwoCmresTest.java | 14 +-
.../commons/rng/core/util/NumberFactoryTest.java | 80 ++---
.../commons/rng/examples/stress/HexTest.java | 6 +-
.../rng/examples/stress/RngDataOutputTest.java | 8 +-
.../rng/sampling/CollectionSamplerTest.java | 4 +-
.../rng/sampling/CombinationSamplerTest.java | 18 +-
.../rng/sampling/CompositeSamplersTest.java | 46 +--
.../DiscreteProbabilityCollectionSamplerTest.java | 14 +-
.../commons/rng/sampling/ListSamplerTest.java | 32 +-
.../rng/sampling/PermutationSamplerTest.java | 26 +-
.../apache/commons/rng/sampling/RandomAssert.java | 16 +-
.../rng/sampling/UnitSphereSamplerTest.java | 39 ++-
.../AhrensDieterExponentialSamplerTest.java | 6 +-
...AhrensDieterMarsagliaTsangGammaSamplerTest.java | 4 +-
.../AliasMethodDiscreteSamplerTest.java | 8 +-
.../distribution/ChengBetaSamplerTest.java | 4 +-
.../ContinuousSamplerParametricTest.java | 8 +-
.../distribution/ContinuousUniformSamplerTest.java | 22 +-
.../distribution/DirichletSamplerTest.java | 16 +-
.../DiscreteSamplerParametricTest.java | 8 +-
.../distribution/DiscreteUniformSamplerTest.java | 30 +-
.../distribution/GeometricSamplerTest.java | 14 +-
.../GuideTableDiscreteSamplerTest.java | 8 +-
.../sampling/distribution/InternalUtilsTest.java | 14 +-
.../KempSmallMeanPoissonSamplerTest.java | 14 +-
.../distribution/LargeMeanPoissonSamplerTest.java | 6 +-
.../rng/sampling/distribution/LevySamplerTest.java | 6 +-
.../MarsagliaNormalisedGaussianSamplerTest.java | 4 +-
.../MarsagliaTsangWangDiscreteSamplerTest.java | 42 +--
.../distribution/PoissonSamplerCacheTest.java | 94 +++---
.../sampling/distribution/PoissonSamplerTest.java | 4 +-
.../rng/sampling/distribution/SamplerBaseTest.java | 12 +-
.../distribution/SmallMeanPoissonSamplerTest.java | 4 +-
.../sampling/distribution/StableSamplerTest.java | 358 +++++++++++----------
.../distribution/UniformLongSamplerTest.java | 24 +-
.../sampling/distribution/ZigguratSamplerTest.java | 33 +-
.../commons/rng/sampling/shape/BoxSamplerTest.java | 28 +-
.../rng/sampling/shape/CoordinatesTest.java | 18 +-
.../rng/sampling/shape/LineSamplerTest.java | 30 +-
.../rng/sampling/shape/TetrahedronSamplerTest.java | 74 ++---
.../rng/sampling/shape/TriangleSamplerTest.java | 84 ++---
.../rng/sampling/shape/UnitBallSamplerTest.java | 12 +-
.../commons/rng/simple/JDKRandomBridgeTest.java | 39 ++-
.../commons/rng/simple/JDKRandomWrapperTest.java | 36 +--
.../rng/simple/ProvidersCommonParametricTest.java | 68 ++--
.../apache/commons/rng/simple/RandomAssert.java | 20 +-
.../commons/rng/simple/RandomSourceTest.java | 30 +-
.../rng/simple/ThreadLocalRandomSourceTest.java | 21 +-
.../simple/internal/ByteArray2IntArrayTest.java | 6 +-
.../simple/internal/ByteArray2LongArrayTest.java | 6 +-
.../simple/internal/IntArray2LongArrayTest.java | 6 +-
.../rng/simple/internal/Long2IntArrayTest.java | 6 +-
.../rng/simple/internal/Long2LongArrayTest.java | 4 +-
.../internal/NativeSeedTypeParametricTest.java | 31 +-
.../rng/simple/internal/NativeSeedTypeTest.java | 4 +-
.../rng/simple/internal/NoOpConverterTest.java | 6 +-
.../RandomSourceInternalParametricTest.java | 36 +--
.../simple/internal/SeedConverterComposerTest.java | 6 +-
.../rng/simple/internal/SeedFactoryTest.java | 50 +--
.../commons/rng/simple/internal/SeedUtilsTest.java | 16 +-
71 files changed, 961 insertions(+), 961 deletions(-)
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/BaseProviderTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/BaseProviderTest.java
index 4b07cea..070f4dc 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/BaseProviderTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/BaseProviderTest.java
@@ -17,8 +17,8 @@
package org.apache.commons.rng.core;
import org.junit.Test;
-import org.junit.Assert;
-import org.junit.Assume;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Assumptions;
/**
* Tests for {@link BaseProvider}.
@@ -33,7 +33,7 @@ public class BaseProviderTest {
public void testStateSizeTooSmall() {
final DummyGenerator dummy = new DummyGenerator();
final int size = dummy.getStateSize();
- Assume.assumeTrue(size > 0);
+ Assumptions.assumeTrue(size > 0);
dummy.restoreState(new RandomProviderDefaultState(new byte[size - 1]));
}
@@ -50,15 +50,15 @@ public class BaseProviderTest {
final int[] seed = {1, 2, 3};
for (int i = 0; i < state.length; i++) {
- Assert.assertEquals(0, state[i]);
+ Assertions.assertEquals(0, state[i]);
}
new DummyGenerator().fillState(state, seed);
for (int i = 0; i < seed.length; i++) {
- Assert.assertEquals(seed[i], state[i]);
+ Assertions.assertEquals(seed[i], state[i]);
}
for (int i = seed.length; i < state.length; i++) {
- Assert.assertNotEquals(0, state[i]);
+ Assertions.assertNotEquals(0, state[i]);
}
}
@@ -68,15 +68,15 @@ public class BaseProviderTest {
final long[] seed = {1, 2, 3};
for (int i = 0; i < state.length; i++) {
- Assert.assertEquals(0, state[i]);
+ Assertions.assertEquals(0, state[i]);
}
new DummyGenerator().fillState(state, seed);
for (int i = 0; i < seed.length; i++) {
- Assert.assertEquals(seed[i], state[i]);
+ Assertions.assertEquals(seed[i], state[i]);
}
for (int i = seed.length; i < state.length; i++) {
- Assert.assertNotEquals(0, state[i]);
+ Assertions.assertNotEquals(0, state[i]);
}
}
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/JumpableProvidersParametricTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/JumpableProvidersParametricTest.java
index 83a5da6..4793b42 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/JumpableProvidersParametricTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/JumpableProvidersParametricTest.java
@@ -16,8 +16,8 @@
*/
package org.apache.commons.rng.core;
-import org.junit.Assert;
-import org.junit.Assume;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Assumptions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -90,7 +90,7 @@ public class JumpableProvidersParametricTest {
* @return the jump function
*/
private TestJumpFunction getLongJumpFunction() {
- Assume.assumeTrue("No long jump function", generator instanceof LongJumpableUniformRandomProvider);
+ Assumptions.assumeTrue(generator instanceof LongJumpableUniformRandomProvider, "No long jump function");
final LongJumpableUniformRandomProvider rng = (LongJumpableUniformRandomProvider) generator;
return new TestJumpFunction() {
@@ -124,8 +124,8 @@ public class JumpableProvidersParametricTest {
*/
private void assertJumpReturnsACopy(TestJumpFunction jumpFunction) {
final UniformRandomProvider copy = jumpFunction.jump();
- Assert.assertNotSame("The copy instance should be a different object", generator, copy);
- Assert.assertEquals("The copy instance should be the same class", generator.getClass(), copy.getClass());
+ Assertions.assertNotSame(generator, copy, "The copy instance should be a different object");
+ Assertions.assertEquals(generator.getClass(), copy.getClass(), "The copy instance should be the same class");
}
/**
@@ -165,7 +165,7 @@ public class JumpableProvidersParametricTest {
* @param jumpFunction Jump function to test.
*/
private void assertCopyMatchesPreJumpState(TestJumpFunction jumpFunction) {
- Assume.assumeTrue("Not a restorable RNG", generator instanceof RestorableUniformRandomProvider);
+ Assumptions.assumeTrue(generator instanceof RestorableUniformRandomProvider, "Not a restorable RNG");
for (int repeats = 0; repeats < 2; repeats++) {
// Exercise the generator.
@@ -176,15 +176,15 @@ public class JumpableProvidersParametricTest {
generator.nextBoolean();
final RandomProviderState preJumpState = ((RestorableUniformRandomProvider) generator).saveState();
- Assume.assumeTrue("Not a recognised state", preJumpState instanceof RandomProviderDefaultState);
+ Assumptions.assumeTrue(preJumpState instanceof RandomProviderDefaultState, "Not a recognised state");
final UniformRandomProvider copy = jumpFunction.jump();
final RandomProviderState copyState = ((RestorableUniformRandomProvider) copy).saveState();
final RandomProviderDefaultState expected = (RandomProviderDefaultState) preJumpState;
final RandomProviderDefaultState actual = (RandomProviderDefaultState) copyState;
- Assert.assertArrayEquals("The copy instance state should match the state of the original",
- expected.getState(), actual.getState());
+ Assertions.assertArrayEquals(expected.getState(), actual.getState(),
+ "The copy instance state should match the state of the original");
}
}
@@ -240,12 +240,13 @@ public class JumpableProvidersParametricTest {
final RandomProviderState postJumpState = ((RestorableUniformRandomProvider) generator).saveState();
final byte[] actual = ((RandomProviderDefaultState) postJumpState).getState();
- Assume.assumeTrue("Implementation has removed default state", actual.length >= stateSize);
+ Assumptions.assumeTrue(actual.length >= stateSize, "Implementation has removed default state");
// The implementation requires that any sub-class state is prepended to the
// state thus the default state is at the end.
final byte[] defaultState = Arrays.copyOfRange(actual, actual.length - stateSize, actual.length);
- Assert.assertArrayEquals("The jump should reset the default state to zero", expected, defaultState);
+ Assertions.assertArrayEquals(expected, defaultState,
+ "The jump should reset the default state to zero");
}
}
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 7119282..8e07603 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
@@ -21,7 +21,7 @@ import java.util.List;
import java.util.ArrayList;
import java.util.concurrent.Callable;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -121,7 +121,7 @@ public class ProvidersCommonParametricTest {
}
};
- Assert.assertTrue(isUniformNextBytes(buffer, 0, size, nextMethod));
+ Assertions.assertTrue(isUniformNextBytes(buffer, 0, size, nextMethod));
}
@Test
@@ -140,11 +140,11 @@ public class ProvidersCommonParametricTest {
};
// Test should pass for the part of the buffer where values are put.
- Assert.assertTrue(isUniformNextBytes(buffer, offset, offset + size, nextMethod));
+ Assertions.assertTrue(isUniformNextBytes(buffer, offset, offset + size, nextMethod));
// Test must fail for the parts of the buffer where no values are put.
- Assert.assertFalse(isUniformNextBytes(buffer, 0, offset, nextMethod));
- Assert.assertFalse(isUniformNextBytes(buffer, offset + size, buffer.length, nextMethod));
+ Assertions.assertFalse(isUniformNextBytes(buffer, 0, offset, nextMethod));
+ Assertions.assertFalse(isUniformNextBytes(buffer, offset + size, buffer.length, nextMethod));
}
@Test
@@ -234,15 +234,15 @@ public class ProvidersCommonParametricTest {
final List<Number> listOrig = makeList(n);
// Discard a few more.
final List<Number> listDiscard = makeList(n);
- Assert.assertNotEquals(0, listDiscard.size());
- Assert.assertNotEquals(listOrig, listDiscard);
+ Assertions.assertNotEquals(0, listDiscard.size());
+ Assertions.assertNotEquals(listOrig, listDiscard);
// Reset.
generator.restoreState(state);
// Replay.
final List<Number> listReplay = makeList(n);
- Assert.assertNotSame(listOrig, listReplay);
+ Assertions.assertNotSame(listOrig, listReplay);
// Check that the restored state is the same as the original.
- Assert.assertEquals(listOrig, listReplay);
+ Assertions.assertEquals(listOrig, listReplay);
}
@Test(expected = IllegalStateException.class)
@@ -376,10 +376,9 @@ public class ProvidersCommonParametricTest {
final double actual = Math.abs(walk);
final double max = Math.sqrt(sampleSize) * 2.576;
- Assert.assertTrue(generator + ": Walked too far astray: " + actual +
- " > " + max +
- " (test will fail randomly about 1 in 100 times)",
- actual < max);
+ Assertions.assertTrue(actual < max,
+ () -> generator + ": Walked too far astray: " + actual + " > " + max +
+ " (test will fail randomly about 1 in 100 times)");
}
/**
@@ -516,7 +515,7 @@ public class ProvidersCommonParametricTest {
Arrays.fill(observed, 0);
for (int j = 0; j < sampleSize; j++) {
final long value = nextMethod.call().longValue();
- Assert.assertTrue("Range", value >= 0 && value < n);
+ Assertions.assertTrue(value >= 0 && value < n, "Range");
for (int k = 0; k < numBins; k++) {
if (value < binUpperBounds[k]) {
@@ -552,8 +551,8 @@ public class ProvidersCommonParametricTest {
// 12 0.00190
if (numFailures > 11) { // Test will fail with 0.5% probability
- Assert.fail(generator + ": Too many failures for n = " + n +
- " (" + numFailures + " out of " + numTests + " tests failed)");
+ Assertions.fail(generator + ": Too many failures for n = " + n +
+ " (" + numFailures + " out of " + numTests + " tests failed)");
}
}
@@ -586,8 +585,8 @@ public class ProvidersCommonParametricTest {
System.arraycopy(b1, b1.length - b3.length, b3, 0, b3.length);
// Sequence of calls must be the same.
- Assert.assertArrayEquals("chunkSize=" + chunkSize + " numChunks=" + numChunks,
- b2, b3);
+ Assertions.assertArrayEquals(b2, b3,
+ () -> "chunkSize=" + chunkSize + " numChunks=" + numChunks);
}
/**
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/RandomAssert.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/RandomAssert.java
index 7344455..e72b225 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/RandomAssert.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/RandomAssert.java
@@ -17,7 +17,7 @@
package org.apache.commons.rng.core;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -43,7 +43,7 @@ public final class RandomAssert {
* @param rng Random generator.
*/
public static void assertEquals(int[] expected, UniformRandomProvider rng) {
- assertEquals("Value at position ", expected, rng);
+ assertEquals(expected, rng, "Value at position ");
}
/**
@@ -54,7 +54,7 @@ public final class RandomAssert {
* @param rng Random generator.
*/
public static void assertEquals(long[] expected, UniformRandomProvider rng) {
- assertEquals("Value at position ", expected, rng);
+ assertEquals(expected, rng, "Value at position ");
}
/**
@@ -62,13 +62,14 @@ public final class RandomAssert {
* {@link UniformRandomProvider#nextInt()}.
* The message prefix is prepended to the array index for the assertion message.
*
- * @param messagePrefix Message prefix.
* @param expected Expected output.
* @param rng Random generator.
+ * @param messagePrefix Message prefix.
*/
- private static void assertEquals(String messagePrefix, int[] expected, UniformRandomProvider rng) {
+ private static void assertEquals(int[] expected, UniformRandomProvider rng, String messagePrefix) {
for (int i = 0; i < expected.length; i++) {
- Assert.assertEquals(messagePrefix + i, expected[i], rng.nextInt());
+ final int index = i;
+ Assertions.assertEquals(expected[i], rng.nextInt(), () -> messagePrefix + index);
}
}
@@ -77,13 +78,14 @@ public final class RandomAssert {
* {@link UniformRandomProvider#nextLong()}.
* The message prefix is prepended to the array index for the assertion message.
*
- * @param messagePrefix Message prefix.
* @param expected Expected output.
* @param rng Random generator.
+ * @param messagePrefix Message prefix.
*/
- private static void assertEquals(String messagePrefix, long[] expected, UniformRandomProvider rng) {
+ private static void assertEquals(long[] expected, UniformRandomProvider rng, String messagePrefix) {
for (int i = 0; i < expected.length; i++) {
- Assert.assertEquals(messagePrefix + i, expected[i], rng.nextLong());
+ final int index = i;
+ Assertions.assertEquals(expected[i], rng.nextLong(), () -> messagePrefix + index);
}
}
@@ -100,7 +102,7 @@ public final class RandomAssert {
return;
}
}
- Assert.fail("Expected a different nextLong output");
+ Assertions.fail("Expected a different nextLong output");
}
/**
@@ -124,10 +126,10 @@ public final class RandomAssert {
int[] expectedAfter,
JumpableUniformRandomProvider rng) {
final UniformRandomProvider copy = rng.jump();
- Assert.assertNotSame("The copy instance should be a different object", rng, copy);
- Assert.assertEquals("The copy instance should be the same class", rng.getClass(), copy.getClass());
- assertEquals("Pre-jump value at position ", expectedBefore, copy);
- assertEquals("Post-jump value at position ", expectedAfter, rng);
+ Assertions.assertNotSame(rng, copy, "The copy instance should be a different object");
+ Assertions.assertEquals(rng.getClass(), copy.getClass(), "The copy instance should be the same class");
+ assertEquals(expectedBefore, copy, "Pre-jump value at position ");
+ assertEquals(expectedAfter, rng, "Post-jump value at position ");
}
/**
@@ -151,10 +153,10 @@ public final class RandomAssert {
long[] expectedAfter,
JumpableUniformRandomProvider rng) {
final UniformRandomProvider copy = rng.jump();
- Assert.assertNotSame("The copy instance should be a different object", rng, copy);
- Assert.assertEquals("The copy instance should be the same class", rng.getClass(), copy.getClass());
- assertEquals("Pre-jump value at position ", expectedBefore, copy);
- assertEquals("Post-jump value at position ", expectedAfter, rng);
+ Assertions.assertNotSame(rng, copy, "The copy instance should be a different object");
+ Assertions.assertEquals(rng.getClass(), copy.getClass(), "The copy instance should be the same class");
+ assertEquals(expectedBefore, copy, "Pre-jump value at position ");
+ assertEquals(expectedAfter, rng, "Post-jump value at position ");
}
/**
@@ -178,10 +180,10 @@ public final class RandomAssert {
int[] expectedAfter,
LongJumpableUniformRandomProvider rng) {
final UniformRandomProvider copy = rng.longJump();
- Assert.assertNotSame("The copy instance should be a different object", rng, copy);
- Assert.assertEquals("The copy instance should be the same class", rng.getClass(), copy.getClass());
- assertEquals("Pre-jump value at position ", expectedBefore, copy);
- assertEquals("Post-jump value at position ", expectedAfter, rng);
+ Assertions.assertNotSame(rng, copy, "The copy instance should be a different object");
+ Assertions.assertEquals(rng.getClass(), copy.getClass(), "The copy instance should be the same class");
+ assertEquals(expectedBefore, copy, "Pre-jump value at position ");
+ assertEquals(expectedAfter, rng, "Post-jump value at position ");
}
/**
@@ -205,10 +207,10 @@ public final class RandomAssert {
long[] expectedAfter,
LongJumpableUniformRandomProvider rng) {
final UniformRandomProvider copy = rng.longJump();
- Assert.assertNotSame("The copy instance should be a different object", rng, copy);
- Assert.assertEquals("The copy instance should be the same class", rng.getClass(), copy.getClass());
- assertEquals("Pre-jump value at position ", expectedBefore, copy);
- assertEquals("Post-jump value at position ", expectedAfter, rng);
+ Assertions.assertNotSame(rng, copy, "The copy instance should be a different object");
+ Assertions.assertEquals(rng.getClass(), copy.getClass(), "The copy instance should be the same class");
+ assertEquals(expectedBefore, copy, "Pre-jump value at position ");
+ assertEquals(expectedAfter, rng, "Post-jump value at position ");
}
/**
@@ -221,7 +223,8 @@ public final class RandomAssert {
*/
public static void assertNextIntEquals(int cycles, UniformRandomProvider rng1, UniformRandomProvider rng2) {
for (int i = 0; i < cycles; i++) {
- Assert.assertEquals("Value at position " + i, rng1.nextInt(), rng2.nextInt());
+ final int index = i;
+ Assertions.assertEquals(rng1.nextInt(), rng2.nextInt(), () -> "Value at position " + index);
}
}
@@ -235,7 +238,8 @@ public final class RandomAssert {
*/
public static void assertNextLongEquals(int cycles, UniformRandomProvider rng1, UniformRandomProvider rng2) {
for (int i = 0; i < cycles; i++) {
- Assert.assertEquals("Value at position " + i, rng1.nextLong(), rng2.nextLong());
+ final int index = i;
+ Assertions.assertEquals(rng1.nextLong(), rng2.nextLong(), () -> "Value at position " + index);
}
}
@@ -249,7 +253,7 @@ public final class RandomAssert {
*/
public static void assertNextIntZeroOutput(UniformRandomProvider rng, int cycles) {
for (int i = 0; i < cycles; i++) {
- Assert.assertEquals("Expected the generator to output zeros", 0, rng.nextInt());
+ Assertions.assertEquals(0, rng.nextInt(), "Expected the generator to output zeros");
}
}
@@ -263,7 +267,7 @@ public final class RandomAssert {
*/
public static void assertNextLongZeroOutput(UniformRandomProvider rng, int cycles) {
for (int i = 0; i < cycles; i++) {
- Assert.assertEquals("Expected the generator to output zeros", 0, rng.nextLong());
+ Assertions.assertEquals(0, rng.nextLong(), "Expected the generator to output zeros");
}
}
@@ -287,7 +291,7 @@ public final class RandomAssert {
return;
}
}
- Assert.fail("No non-zero output after " + (warmupCycles + testCycles) + " cycles");
+ Assertions.fail("No non-zero output after " + (warmupCycles + testCycles) + " cycles");
}
/**
@@ -308,7 +312,7 @@ public final class RandomAssert {
try {
assertNextLongNonZeroOutput(rng, warmupCycles, testCycles);
} catch (AssertionError ex) {
- Assert.fail("No non-zero output after " + (warmupCycles + testCycles) + " cycles. " +
+ Assertions.fail("No non-zero output after " + (warmupCycles + testCycles) + " cycles. " +
"Seed element [" + seedElement + "], bit=" + bit);
}
}
@@ -360,16 +364,11 @@ public final class RandomAssert {
return;
}
}
- Assert.assertEquals("Seed element was not reset", 0, seed[i]);
+ Assertions.assertEquals(0, seed[i], "Seed element was not reset");
}
- } catch (IllegalAccessException ex) {
- Assert.fail(ex.getMessage());
- } catch (NoSuchMethodException ex) {
- Assert.fail(ex.getMessage());
- } catch (InstantiationException ex) {
- Assert.fail(ex.getMessage());
- } catch (InvocationTargetException ex) {
- Assert.fail(ex.getMessage());
+ } catch (IllegalAccessException | NoSuchMethodException | InstantiationException |
+ InvocationTargetException ex) {
+ Assertions.fail(ex.getMessage());
}
}
@@ -396,16 +395,11 @@ public final class RandomAssert {
// Eventually reset to zero
seed[i] >>>= 1;
}
- Assert.assertEquals("Seed element was not reset", 0L, seed[i]);
+ Assertions.assertEquals(0L, seed[i], "Seed element was not reset");
}
- } catch (IllegalAccessException ex) {
- Assert.fail(ex.getMessage());
- } catch (NoSuchMethodException ex) {
- Assert.fail(ex.getMessage());
- } catch (InstantiationException ex) {
- Assert.fail(ex.getMessage());
- } catch (InvocationTargetException ex) {
- Assert.fail(ex.getMessage());
+ } catch (IllegalAccessException | NoSuchMethodException | InstantiationException |
+ InvocationTargetException ex) {
+ Assertions.fail(ex.getMessage());
}
}
}
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/RandomProviderDefaultStateTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/RandomProviderDefaultStateTest.java
index 8e6737a..e13e4f9 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/RandomProviderDefaultStateTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/RandomProviderDefaultStateTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.rng.core;
import org.junit.Test;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
/**
* Tests for {@link RandomProviderDefaultState}.
@@ -29,6 +29,6 @@ public class RandomProviderDefaultStateTest {
final byte[] internalState = {1, 0, -23, 67, -128, 54, 100, 127};
final RandomProviderDefaultState state = new RandomProviderDefaultState(internalState);
- Assert.assertArrayEquals(internalState, state.getState());
+ Assertions.assertArrayEquals(internalState, state.getState());
}
}
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/IntProviderTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/IntProviderTest.java
index 7c01313..041b9fd 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/IntProviderTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/IntProviderTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.core.source32;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -64,12 +64,14 @@ public class IntProviderTest {
// Test the result for a single pass over the long
for (int j = 0; j < Integer.SIZE; j++) {
final boolean expected = i == j;
- Assert.assertEquals("Pass 1, bit " + j, expected, provider.nextBoolean());
+ final int index = j;
+ Assertions.assertEquals(expected, provider.nextBoolean(), () -> "Pass 1, bit " + index);
}
// The second pass should use the opposite bits
for (int j = 0; j < Integer.SIZE; j++) {
final boolean expected = i != j;
- Assert.assertEquals("Pass 2, bit " + j, expected, provider.nextBoolean());
+ final int index = j;
+ Assertions.assertEquals(expected, provider.nextBoolean(), () -> "Pass 2, bit " + index);
}
}
}
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/JDKRandomTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/JDKRandomTest.java
index 39baabd..5ba63dd 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/JDKRandomTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/JDKRandomTest.java
@@ -24,9 +24,10 @@ import java.io.Serializable;
import java.util.Random;
import org.apache.commons.rng.RandomProviderState;
+import org.apache.commons.rng.core.RandomAssert;
import org.apache.commons.rng.core.RandomProviderDefaultState;
import org.apache.commons.rng.core.util.NumberFactory;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
public class JDKRandomTest {
@@ -41,7 +42,7 @@ public class JDKRandomTest {
private int state0;
private double state1;
private long state2;
- private boolean stte3;
+ private boolean state3;
/**
* This simulates doing something malicious when deserializing.
@@ -53,7 +54,7 @@ public class JDKRandomTest {
private void readObject(ObjectInputStream input)
throws IOException,
ClassNotFoundException {
- Assert.fail("This should not be run during the test");
+ Assertions.fail("*** Malicious code ***. This should not be run during the test");
}
}
@@ -66,8 +67,8 @@ public class JDKRandomTest {
// This is a trivial test since "JDKRandom" delegates to "Random".
final int numRepeats = 1000;
- for (int r = 0; r < numRepeats; r++) {
- Assert.assertEquals(r + " nextInt", jdk.nextInt(), rng.nextInt());
+ for (int[] r = {0}; r[0] < numRepeats; r[0]++) {
+ Assertions.assertEquals(jdk.nextInt(), rng.nextInt(), () -> r[0] + " nextInt");
}
}
@@ -83,8 +84,8 @@ public class JDKRandomTest {
// Ensure different
final int numRepeats = 10;
- for (int r = 0; r < numRepeats; r++) {
- Assert.assertNotEquals(r + " nextInt", rng1.nextInt(), rng2.nextInt());
+ for (int[] r = {0}; r[0] < numRepeats; r[0]++) {
+ Assertions.assertNotEquals(rng1.nextInt(), rng2.nextInt(), () -> r[0] + " nextInt");
}
final RandomProviderState state = rng1.saveState();
@@ -94,9 +95,7 @@ public class JDKRandomTest {
rng2.restoreState(state);
// Ensure the same
- for (int r = 0; r < numRepeats; r++) {
- Assert.assertEquals(r + " nextInt", rng1.nextInt(), rng2.nextInt());
- }
+ RandomAssert.assertNextIntEquals(numRepeats, rng1, rng2);
}
/**
@@ -109,9 +108,9 @@ public class JDKRandomTest {
public void testRestoreWithInvalidClass() throws IOException {
// Serialize something
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- final ObjectOutputStream oos = new ObjectOutputStream(bos);
- oos.writeObject(new SerializableTestObject());
- oos.close();
+ try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
+ oos.writeObject(new SerializableTestObject());
+ }
// Compose the size with the state.
// This is what is expected by the JDKRandom class.
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MersenneTwisterTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MersenneTwisterTest.java
index 04f382e..3d356c7 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MersenneTwisterTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MersenneTwisterTest.java
@@ -17,7 +17,7 @@
package org.apache.commons.rng.core.source32;
import org.apache.commons.rng.core.RandomAssert;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
public class MersenneTwisterTest {
@@ -166,7 +166,7 @@ public class MersenneTwisterTest {
// An empty seed is allowed
final MersenneTwister rng = new MersenneTwister(new int[0]);
// It should be functional so check it returns different values.
- Assert.assertNotEquals("Empty seed creates sequence with same values",
- rng.nextInt(), rng.nextInt());
+ Assertions.assertNotEquals(rng.nextInt(), rng.nextInt(),
+ "Empty seed creates sequence with same values");
}
}
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequenceTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequenceTest.java
index fcb4d81..50f842b 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequenceTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequenceTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.rng.core.source32;
import org.apache.commons.rng.core.RandomAssert;
import org.apache.commons.rng.core.util.NumberFactory;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
public class MiddleSquareWeylSequenceTest {
@@ -93,7 +93,7 @@ public class MiddleSquareWeylSequenceTest {
final MiddleSquareWeylSequence rng1 = new MiddleSquareWeylSequence(seed);
final MiddleSquareWeylSequence rng2 = new MiddleSquareWeylSequence(seed);
for (int i = 0; i < 50; i++) {
- Assert.assertEquals(NumberFactory.makeLong(rng1.nextInt(), rng1.nextInt()),
+ Assertions.assertEquals(NumberFactory.makeLong(rng1.nextInt(), rng1.nextInt()),
rng2.nextLong());
}
}
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/LongProviderTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/LongProviderTest.java
index 21e16ae..356efda 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/LongProviderTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/LongProviderTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.core.source64;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -82,10 +82,10 @@ public class LongProviderTest {
// Pack into upper then lower bits
final long value = (((long) i) << 32) | (j & 0xffffffffL);
final LongProvider provider = new FixedLongProvider(value);
- Assert.assertEquals("1st call not the upper 32-bits", i, provider.nextInt());
- Assert.assertEquals("2nd call not the lower 32-bits", j, provider.nextInt());
- Assert.assertEquals("3rd call not the upper 32-bits", i, provider.nextInt());
- Assert.assertEquals("4th call not the lower 32-bits", j, provider.nextInt());
+ Assertions.assertEquals(i, provider.nextInt(), "1st call not the upper 32-bits");
+ Assertions.assertEquals(j, provider.nextInt(), "2nd call not the lower 32-bits");
+ Assertions.assertEquals(i, provider.nextInt(), "3rd call not the upper 32-bits");
+ Assertions.assertEquals(j, provider.nextInt(), "4th call not the lower 32-bits");
}
}
}
@@ -105,12 +105,14 @@ public class LongProviderTest {
// Test the result for a single pass over the long
for (int j = 0; j < Long.SIZE; j++) {
final boolean expected = i == j;
- Assert.assertEquals("Pass 1, bit " + j, expected, provider.nextBoolean());
+ final int index = j;
+ Assertions.assertEquals(expected, provider.nextBoolean(), () -> "Pass 1, bit " + index);
}
// The second pass should use the opposite bits
for (int j = 0; j < Long.SIZE; j++) {
final boolean expected = i != j;
- Assert.assertEquals("Pass 2, bit " + j, expected, provider.nextBoolean());
+ final int index = j;
+ Assertions.assertEquals(expected, provider.nextBoolean(), () -> "Pass 2, bit " + index);
}
}
}
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/MersenneTwister64Test.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/MersenneTwister64Test.java
index 0381f48..a7b8662 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/MersenneTwister64Test.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/MersenneTwister64Test.java
@@ -17,7 +17,7 @@
package org.apache.commons.rng.core.source64;
import org.apache.commons.rng.core.RandomAssert;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
public class MersenneTwister64Test {
@@ -291,7 +291,7 @@ public class MersenneTwister64Test {
// An empty seed is allowed
final MersenneTwister64 rng = new MersenneTwister64(new long[0]);
// It should be functional so check it returns different values.
- Assert.assertNotEquals("Empty seed creates sequence with same values",
- rng.nextLong(), rng.nextLong());
+ Assertions.assertNotEquals(rng.nextLong(), rng.nextLong(),
+ "Empty seed creates sequence with same values");
}
}
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/TwoCmresTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/TwoCmresTest.java
index f14d8d2..19dd1f5 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/TwoCmresTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/TwoCmresTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.rng.core.source64;
import org.apache.commons.rng.core.RandomAssert;
import org.apache.commons.rng.core.source64.TwoCmres.Cmres;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import java.util.ArrayList;
@@ -36,8 +36,8 @@ public class TwoCmresTest {
// Try a few values.
final int n = 1000;
- for (int i = 0; i < n; i++) {
- Assert.assertNotEquals("i=" + i, rng1.nextLong(), rng2.nextLong());
+ for (int[] i = {0}; i[0] < n; i[0]++) {
+ Assertions.assertNotEquals(rng1.nextLong(), rng2.nextLong(), () -> "i=" + i[0]);
}
}
@@ -70,7 +70,7 @@ public class TwoCmresTest {
for (int i = 0; i < max; i++) {
try {
new TwoCmres(-97845, i, i);
- Assert.fail("Exception expected");
+ Assertions.fail("Exception expected");
} catch (IllegalArgumentException e) {
// Expected.
}
@@ -96,14 +96,14 @@ public class TwoCmresTest {
for (int wrongIndex : new int[] {-1, max}) {
try {
new TwoCmres(seed, wrongIndex, 1);
- Assert.fail("Exception expected for index=" + wrongIndex);
+ Assertions.fail("Exception expected for index=" + wrongIndex);
} catch (IndexOutOfBoundsException e) {
// Expected.
}
try {
new TwoCmres(seed, 1, wrongIndex);
- Assert.fail("Exception expected for index=" + wrongIndex);
+ Assertions.fail("Exception expected for index=" + wrongIndex);
} catch (IndexOutOfBoundsException e) {
// Expected.
}
@@ -123,7 +123,7 @@ public class TwoCmresTest {
try {
Cmres.Factory.checkUnique(list, nextMultiply);
} catch (IllegalStateException ex) {
- Assert.fail("The next multiply should be unique: " + nextMultiply);
+ Assertions.fail("The next multiply should be unique: " + nextMultiply);
}
list.add(new Cmres(nextMultiply, rotate, start));
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/util/NumberFactoryTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/util/NumberFactoryTest.java
index 8d959eb..5bf1eea 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/util/NumberFactoryTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/util/NumberFactoryTest.java
@@ -17,7 +17,7 @@
package org.apache.commons.rng.core.util;
import org.apache.commons.math3.util.Precision;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -42,7 +42,7 @@ public class NumberFactoryTest {
// Test if the bit is set differently then the booleans are opposite
final boolean b1 = NumberFactory.makeBoolean(0);
final boolean b2 = NumberFactory.makeBoolean(0xffffffff);
- Assert.assertNotEquals(b1, b2);
+ Assertions.assertNotEquals(b1, b2);
}
@Test
@@ -50,20 +50,20 @@ public class NumberFactoryTest {
// Test if the bit is set differently then the booleans are opposite
final boolean b1 = NumberFactory.makeBoolean(0L);
final boolean b2 = NumberFactory.makeBoolean(0xffffffffffffffffL);
- Assert.assertNotEquals(b1, b2);
+ Assertions.assertNotEquals(b1, b2);
}
@Test
public void testMakeIntFromLong() {
// Test the high order bits and low order bits are xor'd together
- Assert.assertEquals(0xffffffff, NumberFactory.makeInt(0xffffffff00000000L));
- Assert.assertEquals(0x00000000, NumberFactory.makeInt(0xffffffffffffffffL));
- Assert.assertEquals(0xffffffff, NumberFactory.makeInt(0x00000000ffffffffL));
- Assert.assertEquals(0x00000000, NumberFactory.makeInt(0x0000000000000000L));
- Assert.assertEquals(0x0f0f0f0f, NumberFactory.makeInt(0x0f0f0f0f00000000L));
- Assert.assertEquals(0xf0f0f0f0, NumberFactory.makeInt(0x00000000f0f0f0f0L));
- Assert.assertEquals(0x00000000, NumberFactory.makeInt(0x0f0f0f0f0f0f0f0fL));
- Assert.assertEquals(0xffffffff, NumberFactory.makeInt(0x0f0f0f0ff0f0f0f0L));
+ Assertions.assertEquals(0xffffffff, NumberFactory.makeInt(0xffffffff00000000L));
+ Assertions.assertEquals(0x00000000, NumberFactory.makeInt(0xffffffffffffffffL));
+ Assertions.assertEquals(0xffffffff, NumberFactory.makeInt(0x00000000ffffffffL));
+ Assertions.assertEquals(0x00000000, NumberFactory.makeInt(0x0000000000000000L));
+ Assertions.assertEquals(0x0f0f0f0f, NumberFactory.makeInt(0x0f0f0f0f00000000L));
+ Assertions.assertEquals(0xf0f0f0f0, NumberFactory.makeInt(0x00000000f0f0f0f0L));
+ Assertions.assertEquals(0x00000000, NumberFactory.makeInt(0x0f0f0f0f0f0f0f0fL));
+ Assertions.assertEquals(0xffffffff, NumberFactory.makeInt(0x0f0f0f0ff0f0f0f0L));
}
@Test
@@ -73,7 +73,7 @@ public class NumberFactoryTest {
final int vH = NumberFactory.extractHi(v);
final long actual = (((long) vH) << 32) | (vL & 0xffffffffL);
- Assert.assertEquals(v, actual);
+ Assertions.assertEquals(v, actual);
}
}
@@ -83,7 +83,7 @@ public class NumberFactoryTest {
final int vL = NumberFactory.extractLo(v);
final int vH = NumberFactory.extractHi(v);
- Assert.assertEquals(v, NumberFactory.makeLong(vH, vL));
+ Assertions.assertEquals(v, NumberFactory.makeLong(vH, vL));
}
}
@@ -95,7 +95,7 @@ public class NumberFactoryTest {
final byte[] b = NumberFactory.makeByteArray(value);
for (int j = 0; j < LONG_SIZE; j++) {
// Only one byte should be non zero
- Assert.assertEquals(b[j] != 0, j == i);
+ Assertions.assertEquals(b[j] != 0, j == i);
}
// Shift to the next byte
value <<= 8;
@@ -106,14 +106,14 @@ public class NumberFactoryTest {
public void testLongFromByteArray2Long() {
for (long expected : LONG_TEST_VALUES) {
final byte[] b = NumberFactory.makeByteArray(expected);
- Assert.assertEquals(expected, NumberFactory.makeLong(b));
+ Assertions.assertEquals(expected, NumberFactory.makeLong(b));
}
}
@Test
public void testLongArrayFromByteArray2LongArray() {
final byte[] b = NumberFactory.makeByteArray(LONG_TEST_VALUES);
- Assert.assertArrayEquals(LONG_TEST_VALUES, NumberFactory.makeLongArray(b));
+ Assertions.assertArrayEquals(LONG_TEST_VALUES, NumberFactory.makeLongArray(b));
}
@Test
@@ -122,7 +122,7 @@ public class NumberFactoryTest {
for (int i = 0; i < LONG_TEST_VALUES.length; i++) {
final byte[] b1 = NumberFactory.makeByteArray(LONG_TEST_VALUES[i]);
final byte[] b2 = NumberFactory.makeByteArray(new long[] {LONG_TEST_VALUES[i]});
- Assert.assertArrayEquals(b1, b2);
+ Assertions.assertArrayEquals(b1, b2);
}
}
@@ -134,7 +134,7 @@ public class NumberFactoryTest {
final byte[] b = NumberFactory.makeByteArray(value);
for (int j = 0; j < INT_SIZE; j++) {
// Only one byte should be non zero
- Assert.assertEquals(b[j] != 0, j == i);
+ Assertions.assertEquals(b[j] != 0, j == i);
}
// Shift to the next byte
value <<= 8;
@@ -145,14 +145,14 @@ public class NumberFactoryTest {
public void testIntFromByteArray2Int() {
for (int expected : INT_TEST_VALUES) {
final byte[] b = NumberFactory.makeByteArray(expected);
- Assert.assertEquals(expected, NumberFactory.makeInt(b));
+ Assertions.assertEquals(expected, NumberFactory.makeInt(b));
}
}
@Test
public void testIntArrayFromByteArray2IntArray() {
final byte[] b = NumberFactory.makeByteArray(INT_TEST_VALUES);
- Assert.assertArrayEquals(INT_TEST_VALUES, NumberFactory.makeIntArray(b));
+ Assertions.assertArrayEquals(INT_TEST_VALUES, NumberFactory.makeIntArray(b));
}
@Test
@@ -161,7 +161,7 @@ public class NumberFactoryTest {
for (int i = 0; i < INT_TEST_VALUES.length; i++) {
final byte[] b1 = NumberFactory.makeByteArray(INT_TEST_VALUES[i]);
final byte[] b2 = NumberFactory.makeByteArray(new int[] {INT_TEST_VALUES[i]});
- Assert.assertArrayEquals(b1, b2);
+ Assertions.assertArrayEquals(b1, b2);
}
}
@@ -171,7 +171,7 @@ public class NumberFactoryTest {
try {
NumberFactory.makeInt(new byte[i]);
if (i != INT_SIZE) {
- Assert.fail("Exception expected");
+ Assertions.fail("Exception expected");
}
} catch (IllegalArgumentException e) {
// Expected.
@@ -185,7 +185,7 @@ public class NumberFactoryTest {
try {
NumberFactory.makeIntArray(new byte[i]);
if (i != 0 && i % INT_SIZE != 0) {
- Assert.fail("Exception expected");
+ Assertions.fail("Exception expected");
}
} catch (IllegalArgumentException e) {
// Expected.
@@ -199,7 +199,7 @@ public class NumberFactoryTest {
try {
NumberFactory.makeLong(new byte[i]);
if (i != LONG_SIZE) {
- Assert.fail("Exception expected");
+ Assertions.fail("Exception expected");
}
} catch (IllegalArgumentException e) {
// Expected.
@@ -213,7 +213,7 @@ public class NumberFactoryTest {
try {
NumberFactory.makeLongArray(new byte[i]);
if (i != 0 && i % LONG_SIZE != 0) {
- Assert.fail("Exception expected");
+ Assertions.fail("Exception expected");
}
} catch (IllegalArgumentException e) {
// Expected.
@@ -235,9 +235,9 @@ public class NumberFactoryTest {
assertCloseToNotAbove1(Float.intBitsToFloat(0x7f << 23 | allBits >>> 9) - 1.0f, 2);
final int noBits = 0;
- Assert.assertEquals(0.0f, (noBits >>> 9) * 0x1.0p-23f, 0);
- Assert.assertEquals(0.0f, (noBits >>> 8) * 0x1.0p-24f, 0);
- Assert.assertEquals(0.0f, Float.intBitsToFloat(0x7f << 23 | noBits >>> 9) - 1.0f, 0);
+ Assertions.assertEquals(0.0f, (noBits >>> 9) * 0x1.0p-23f);
+ Assertions.assertEquals(0.0f, (noBits >>> 8) * 0x1.0p-24f);
+ Assertions.assertEquals(0.0f, Float.intBitsToFloat(0x7f << 23 | noBits >>> 9) - 1.0f);
}
/**
@@ -254,9 +254,9 @@ public class NumberFactoryTest {
assertCloseToNotAbove1(Double.longBitsToDouble(0x3ffL << 52 | allBits >>> 12) - 1.0, 2);
final long noBits = 0;
- Assert.assertEquals(0.0, (noBits >>> 12) * 0x1.0p-52d, 0);
- Assert.assertEquals(0.0, (noBits >>> 11) * 0x1.0p-53d, 0);
- Assert.assertEquals(0.0, Double.longBitsToDouble(0x3ffL << 52 | noBits >>> 12) - 1.0, 0);
+ Assertions.assertEquals(0.0, (noBits >>> 12) * 0x1.0p-52d);
+ Assertions.assertEquals(0.0, (noBits >>> 11) * 0x1.0p-53d);
+ Assertions.assertEquals(0.0, Double.longBitsToDouble(0x3ffL << 52 | noBits >>> 12) - 1.0);
}
@Test
@@ -265,7 +265,7 @@ public class NumberFactoryTest {
final long noBits = 0;
// Within 1 ULP of 1.0
assertCloseToNotAbove1(NumberFactory.makeDouble(allBits), 1);
- Assert.assertEquals(0.0, NumberFactory.makeDouble(noBits), 0);
+ Assertions.assertEquals(0.0, NumberFactory.makeDouble(noBits));
}
@Test
@@ -274,7 +274,7 @@ public class NumberFactoryTest {
final int noBits = 0;
// Within 1 ULP of 1.0
assertCloseToNotAbove1(NumberFactory.makeDouble(allBits, allBits), 1);
- Assert.assertEquals(0.0, NumberFactory.makeDouble(noBits, noBits), 0);
+ Assertions.assertEquals(0.0, NumberFactory.makeDouble(noBits, noBits));
}
@Test
@@ -283,7 +283,7 @@ public class NumberFactoryTest {
final int noBits = 0;
// Within 1 ULP of 1.0f
assertCloseToNotAbove1(NumberFactory.makeFloat(allBits), 1);
- Assert.assertEquals(0.0f, NumberFactory.makeFloat(noBits), 0);
+ Assertions.assertEquals(0.0f, NumberFactory.makeFloat(noBits), 0);
}
/**
@@ -296,9 +296,9 @@ public class NumberFactoryTest {
* @see Precision#equals(float, float, int)
*/
private static void assertCloseToNotAbove1(float value, int maxUlps) {
- Assert.assertTrue("Not <= 1.0f", value <= 1.0f);
- Assert.assertTrue("Not equal to 1.0f within units of least precision: " + maxUlps,
- Precision.equals(1.0f, value, maxUlps));
+ Assertions.assertTrue(value <= 1.0f, "Not <= 1.0f");
+ Assertions.assertTrue(Precision.equals(1.0f, value, maxUlps),
+ () -> "Not equal to 1.0f within units of least precision: " + maxUlps);
}
/**
@@ -311,8 +311,8 @@ public class NumberFactoryTest {
* @see Precision#equals(double, double, int)
*/
private static void assertCloseToNotAbove1(double value, int maxUlps) {
- Assert.assertTrue("Not <= 1.0", value <= 1.0);
- Assert.assertTrue("Not equal to 1.0 within units of least precision: " + maxUlps,
- Precision.equals(1.0, value, maxUlps));
+ Assertions.assertTrue(value <= 1.0, "Not <= 1.0");
+ Assertions.assertTrue(Precision.equals(1.0, value, maxUlps),
+ () -> "Not equal to 1.0 within units of least precision: " + maxUlps);
}
}
diff --git a/commons-rng-examples/examples-stress/src/test/java/org/apache/commons/rng/examples/stress/HexTest.java b/commons-rng-examples/examples-stress/src/test/java/org/apache/commons/rng/examples/stress/HexTest.java
index 1fe5c58..24b118f 100644
--- a/commons-rng-examples/examples-stress/src/test/java/org/apache/commons/rng/examples/stress/HexTest.java
+++ b/commons-rng-examples/examples-stress/src/test/java/org/apache/commons/rng/examples/stress/HexTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.examples.stress;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import java.util.Arrays;
@@ -64,7 +64,7 @@ public class HexTest {
final StringBuilder sb = new StringBuilder();
sb.append(Hex.encodeHex(bytes));
final byte[] decoded = Hex.decodeHex(sb);
- Assert.assertArrayEquals(bytes, decoded);
+ Assertions.assertArrayEquals(bytes, decoded);
}
/**
@@ -104,7 +104,7 @@ public class HexTest {
final String text = String.valueOf(chars);
final byte[] decoded = Hex.decodeHex(text);
// Test the encoding is lower case
- Assert.assertArrayEquals(text.toLowerCase(Locale.US).toCharArray(), Hex.encodeHex(decoded));
+ Assertions.assertArrayEquals(text.toLowerCase(Locale.US).toCharArray(), Hex.encodeHex(decoded));
}
@Test(expected = IllegalArgumentException.class)
diff --git a/commons-rng-examples/examples-stress/src/test/java/org/apache/commons/rng/examples/stress/RngDataOutputTest.java b/commons-rng-examples/examples-stress/src/test/java/org/apache/commons/rng/examples/stress/RngDataOutputTest.java
index 4115a85..90619a4 100644
--- a/commons-rng-examples/examples-stress/src/test/java/org/apache/commons/rng/examples/stress/RngDataOutputTest.java
+++ b/commons-rng-examples/examples-stress/src/test/java/org/apache/commons/rng/examples/stress/RngDataOutputTest.java
@@ -21,7 +21,7 @@ import org.apache.commons.rng.core.source32.IntProvider;
import org.apache.commons.rng.core.source32.RandomIntSource;
import org.apache.commons.rng.core.source64.RandomLongSource;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
@@ -117,7 +117,7 @@ public class RngDataOutputTest {
try {
sink.writeInt(rng.nextInt());
} catch (IOException e) {
- Assert.fail();
+ Assertions.fail();
}
}
@@ -125,7 +125,7 @@ public class RngDataOutputTest {
try {
sink.writeLong(rng.nextLong());
} catch (IOException e) {
- Assert.fail();
+ Assertions.fail();
}
}
@@ -157,7 +157,7 @@ public class RngDataOutputTest {
for (int repeats = 1; repeats <= 2; repeats++) {
byte[] expected = createBytes(rng1, size, repeats, rngConverter, pipe);
byte[] actual = writeRngOutput(rng2, size, repeats, byteOrder, factory);
- Assert.assertArrayEquals(expected, actual);
+ Assertions.assertArrayEquals(expected, actual);
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/CollectionSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/CollectionSamplerTest.java
index c2d66c4..90a5a3b 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/CollectionSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/CollectionSamplerTest.java
@@ -20,7 +20,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.simple.RandomSource;
@@ -46,7 +46,7 @@ public class CollectionSamplerTest {
return;
}
}
- Assert.fail(word + " not in list");
+ Assertions.fail(word + " not in list");
}
@Test(expected = IllegalArgumentException.class)
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/CombinationSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/CombinationSamplerTest.java
index 853f011..ba2f707 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/CombinationSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/CombinationSamplerTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.rng.sampling;
import java.util.Arrays;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.apache.commons.math3.stat.inference.ChiSquareTest;
@@ -66,9 +66,9 @@ public class CombinationSamplerTest {
final int k = n;
final CombinationSampler sampler = new CombinationSampler(rng, n, k);
final int[] sample = sampler.sample();
- Assert.assertEquals("Incorrect sample length", n, sample.length);
+ Assertions.assertEquals(n, sample.length, "Incorrect sample length");
for (int i = 0; i < n; i++) {
- Assert.assertEquals("Sample was shuffled", i, sample[i]);
+ Assertions.assertEquals(i, sample[i], "Sample was shuffled");
}
}
}
@@ -138,7 +138,7 @@ public class CombinationSamplerTest {
*/
private static void assertIsInDomain(int n, int value) {
if (value < 0 || value >= n) {
- Assert.fail("sample " + value + " not in the domain " + n);
+ Assertions.fail("sample " + value + " not in the domain " + n);
}
}
@@ -160,8 +160,8 @@ public class CombinationSamplerTest {
}
// The number of combinations C(n, k) is the binomial coefficient
- Assert.assertEquals("Incorrect number of combination codes",
- CombinatoricsUtils.binomialCoefficient(n, k), codes);
+ Assertions.assertEquals(CombinatoricsUtils.binomialCoefficient(n, k), codes,
+ "Incorrect number of combination codes");
final long[] observed = new long[codes];
final int numSamples = 6000;
@@ -177,7 +177,7 @@ public class CombinationSamplerTest {
Arrays.fill(expected, numExpected);
final ChiSquareTest chiSquareTest = new ChiSquareTest();
// Pass if we cannot reject null hypothesis that distributions are the same.
- Assert.assertFalse(chiSquareTest.chiSquareTest(expected, observed, 0.001));
+ Assertions.assertFalse(chiSquareTest.chiSquareTest(expected, observed, 0.001));
}
private static int findCode(int[] codeLookup, int[] sample) {
@@ -190,11 +190,11 @@ public class CombinationSamplerTest {
bits |= 1 << s;
}
if (bits >= codeLookup.length) {
- Assert.fail("Bad bit combination: " + Arrays.toString(sample));
+ Assertions.fail("Bad bit combination: " + Arrays.toString(sample));
}
final int code = codeLookup[bits];
if (code < 0) {
- Assert.fail("Bad bit code: " + Arrays.toString(sample));
+ Assertions.fail("Bad bit code: " + Arrays.toString(sample));
}
return code;
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/CompositeSamplersTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/CompositeSamplersTest.java
index e5f06c4..0224ee9 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/CompositeSamplersTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/CompositeSamplersTest.java
@@ -19,7 +19,7 @@ package org.apache.commons.rng.sampling;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.apache.commons.math3.stat.inference.ChiSquareTest;
@@ -56,7 +56,7 @@ public class CompositeSamplersTest {
for (int i = 0; i < n; i++) {
sum += sampler.sample();
}
- Assert.assertEquals(item.name(), mean, (double) sum / n, 1e-3);
+ Assertions.assertEquals(mean, (double) sum / n, 1e-3, item::name);
}
}
@@ -68,7 +68,7 @@ public class CompositeSamplersTest {
final UniformRandomProvider rng = RandomSource.SPLIT_MIX_64.create(0L);
final Builder<SharedStateObjectSampler<Integer>> builder = CompositeSamplers
.newSharedStateObjectSamplerBuilder();
- Assert.assertEquals(0, builder.size());
+ Assertions.assertEquals(0, builder.size());
builder.build(rng);
}
@@ -92,15 +92,15 @@ public class CompositeSamplersTest {
.newSharedStateObjectSamplerBuilder();
final RangeSampler sampler = new RangeSampler(45, 63, rng);
// Zero weight is ignored
- Assert.assertEquals(0, builder.size());
+ Assertions.assertEquals(0, builder.size());
builder.add(sampler, 0.0);
- Assert.assertEquals(0, builder.size());
+ Assertions.assertEquals(0, builder.size());
final double[] bad = {-1, Double.NaN, Double.POSITIVE_INFINITY};
for (final double weight : bad) {
try {
builder.add(sampler, weight);
- Assert.fail("Did not detect invalid weight: " + weight);
+ Assertions.fail("Did not detect invalid weight: " + weight);
} catch (final IllegalArgumentException ex) {
// Expected
}
@@ -117,9 +117,9 @@ public class CompositeSamplersTest {
.newSharedStateObjectSamplerBuilder();
final RangeSampler sampler = new RangeSampler(45, 63, rng);
builder.add(sampler, 1.0);
- Assert.assertEquals(1, builder.size());
+ Assertions.assertEquals(1, builder.size());
final SharedStateObjectSampler<Integer> composite = builder.build(rng);
- Assert.assertSame(sampler, composite);
+ Assertions.assertSame(sampler, composite);
}
/**
@@ -180,7 +180,7 @@ public class CompositeSamplersTest {
final UniformRandomProvider rng1 = RandomSource.XO_SHI_RO_256_PLUS.create(0x1f2e3d);
assertObjectSamplerSamples(builder.build(rng).withUniformRandomProvider(rng1), min, max);
- Assert.assertEquals("Factory should not be used to create the shared state sampler", 1, factoryCount.get());
+ Assertions.assertEquals(1, factoryCount.get(), "Factory should not be used to create the shared state sampler");
}
/**
@@ -219,7 +219,7 @@ public class CompositeSamplersTest {
final UniformRandomProvider rng1 = RandomSource.XO_SHI_RO_256_PLUS.create(0x8c7b6a);
assertObjectSamplerSamples(builder.build(rng).withUniformRandomProvider(rng1), min, max);
- Assert.assertEquals("Factory should be used to create the shared state sampler", 2, factoryCount.get());
+ Assertions.assertEquals(2, factoryCount.get(), "Factory should be used to create the shared state sampler");
}
/**
@@ -254,7 +254,7 @@ public class CompositeSamplersTest {
final double w4 = 0x1.0p1023;
final double w2 = 0x1.0p1022;
final double w1 = 0x1.0p1021;
- Assert.assertEquals(Double.POSITIVE_INFINITY, w4 + w4 + w2 + w1, 0.0);
+ Assertions.assertEquals(Double.POSITIVE_INFINITY, w4 + w4 + w2 + w1);
builder.add(new RangeSampler(0, 40, rng), w4);
builder.add(new RangeSampler(40, 80, rng), w4);
builder.add(new RangeSampler(80, 100, rng), w2);
@@ -279,11 +279,11 @@ public class CompositeSamplersTest {
final double w1 = Double.MIN_VALUE;
final double sum = w4 + w4 + w2 + w1;
// Cannot do a divide by multiplying by the reciprocal
- Assert.assertEquals(Double.POSITIVE_INFINITY, 1.0 / sum, 0.0);
+ Assertions.assertEquals(Double.POSITIVE_INFINITY, 1.0 / sum);
// A divide works so the sampler should work
- Assert.assertEquals(4.0 / 11, w4 / sum, 0.0);
- Assert.assertEquals(2.0 / 11, w2 / sum, 0.0);
- Assert.assertEquals(1.0 / 11, w1 / sum, 0.0);
+ Assertions.assertEquals(4.0 / 11, w4 / sum);
+ Assertions.assertEquals(2.0 / 11, w2 / sum);
+ Assertions.assertEquals(1.0 / 11, w1 / sum);
builder.add(new RangeSampler(0, 40, rng), w4);
builder.add(new RangeSampler(40, 80, rng), w4);
builder.add(new RangeSampler(80, 100, rng), w2);
@@ -334,7 +334,7 @@ public class CompositeSamplersTest {
builder.add(sampler, sampler.range);
}
- Assert.assertEquals("Failed to add the correct number of samplers", n, builder.size() - before);
+ Assertions.assertEquals(n, builder.size() - before, "Failed to add the correct number of samplers");
}
/**
@@ -354,7 +354,7 @@ public class CompositeSamplersTest {
final double[] expected = new double[observed.length];
Arrays.fill(expected, (double) n / expected.length);
final double p = new ChiSquareTest().chiSquareTest(expected, observed);
- Assert.assertFalse("p-value too small: " + p, p < 0.001);
+ Assertions.assertFalse(p < 0.001, () -> "p-value too small: " + p);
}
/**
@@ -428,7 +428,7 @@ public class CompositeSamplersTest {
builder.add(sampler, sampler.range);
}
- Assert.assertEquals("Failed to add the correct number of samplers", n, builder.size() - before);
+ Assertions.assertEquals(n, builder.size() - before, "Failed to add the correct number of samplers");
}
/**
@@ -448,7 +448,7 @@ public class CompositeSamplersTest {
final double[] expected = new double[observed.length];
Arrays.fill(expected, (double) n / expected.length);
final double p = new ChiSquareTest().chiSquareTest(expected, observed);
- Assert.assertFalse("p-value too small: " + p, p < 0.001);
+ Assertions.assertFalse(p < 0.001, () -> "p-value too small: " + p);
}
/**
@@ -521,7 +521,7 @@ public class CompositeSamplersTest {
builder.add(sampler, sampler.range());
}
- Assert.assertEquals("Failed to add the correct number of samplers", n, builder.size() - before);
+ Assertions.assertEquals(n, builder.size() - before, "Failed to add the correct number of samplers");
}
/**
@@ -545,7 +545,7 @@ public class CompositeSamplersTest {
final double[] expected = new double[observed.length];
Arrays.fill(expected, (double) n / expected.length);
final double p = new ChiSquareTest().chiSquareTest(expected, observed);
- Assert.assertFalse("p-value too small: " + p, p < 0.001);
+ Assertions.assertFalse(p < 0.001, () -> "p-value too small: " + p);
}
/**
@@ -618,7 +618,7 @@ public class CompositeSamplersTest {
builder.add(sampler, sampler.range);
}
- Assert.assertEquals("Failed to add the correct number of samplers", n, builder.size() - before);
+ Assertions.assertEquals(n, builder.size() - before, "Failed to add the correct number of samplers");
}
/**
@@ -641,7 +641,7 @@ public class CompositeSamplersTest {
final double[] expected = new double[observed.length];
Arrays.fill(expected, (double) n / expected.length);
final double p = new ChiSquareTest().chiSquareTest(expected, observed);
- Assert.assertFalse("p-value too small: " + p, p < 0.001);
+ Assertions.assertFalse(p < 0.001, () -> "p-value too small: " + p);
}
/**
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/DiscreteProbabilityCollectionSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/DiscreteProbabilityCollectionSamplerTest.java
index 8a5225f..ed72e7d 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/DiscreteProbabilityCollectionSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/DiscreteProbabilityCollectionSamplerTest.java
@@ -24,7 +24,7 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.simple.RandomSource;
@@ -104,9 +104,9 @@ public class DiscreteProbabilityCollectionSamplerTest {
}
final double mean = sum / n;
- Assert.assertEquals(expectedMean, mean, 1e-3);
+ Assertions.assertEquals(expectedMean, mean, 1e-3);
final double variance = sumOfSquares / n - mean * mean;
- Assert.assertEquals(expectedVariance, variance, 2e-3);
+ Assertions.assertEquals(expectedVariance, variance, 2e-3);
}
@@ -128,7 +128,7 @@ public class DiscreteProbabilityCollectionSamplerTest {
new DiscreteProbabilityCollectionSampler<Integer>(rng2, map);
for (int i = 0; i < 50; i++) {
- Assert.assertEquals(sampler1.sample(), sampler2.sample());
+ Assertions.assertEquals(sampler1.sample(), sampler2.sample());
}
}
@@ -165,10 +165,10 @@ public class DiscreteProbabilityCollectionSamplerTest {
final Double item1 = sampler.sample();
final Double item2 = sampler.sample();
// Check they are in the list
- Assert.assertTrue("Sample item1 is not from the list", items.contains(item1));
- Assert.assertTrue("Sample item2 is not from the list", items.contains(item2));
+ Assertions.assertTrue(items.contains(item1), "Sample item1 is not from the list");
+ Assertions.assertTrue(items.contains(item2), "Sample item2 is not from the list");
// Test the two samples are different items
- Assert.assertNotSame("Item1 and 2 should be different", item1, item2);
+ Assertions.assertNotSame(item1, item2, "Item1 and 2 should be different");
}
/**
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/ListSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/ListSamplerTest.java
index 095dd3b..c4788d9 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/ListSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/ListSamplerTest.java
@@ -17,6 +17,7 @@
package org.apache.commons.rng.sampling;
import java.util.Set;
+import java.util.function.Supplier;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
@@ -24,7 +25,7 @@ import java.util.ListIterator;
import java.util.ArrayList;
import java.util.Collection;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.apache.commons.math3.stat.inference.ChiSquareTest;
@@ -66,7 +67,7 @@ public class ListSamplerTest {
}
// Pass if we cannot reject null hypothesis that distributions are the same.
- Assert.assertFalse(chiSquareTest.chiSquareTest(expected, observed, 0.001));
+ Assertions.assertFalse(chiSquareTest.chiSquareTest(expected, observed, 0.001));
}
@Test
@@ -76,8 +77,8 @@ public class ListSamplerTest {
list.add("one");
final List<String> one = ListSampler.sample(rng, list, 1);
- Assert.assertEquals(1, one.size());
- Assert.assertTrue(one.contains("one"));
+ Assertions.assertEquals(1, one.size());
+ Assertions.assertTrue(one.contains("one"));
}
@Test(expected = IllegalArgumentException.class)
@@ -106,13 +107,13 @@ public class ListSamplerTest {
ListSampler.shuffle(rng, arrayList);
// Ensure that at least one entry has moved.
- Assert.assertTrue("ArrayList", compare(orig, arrayList, 0, orig.size(), false));
+ Assertions.assertTrue(compare(orig, arrayList, 0, orig.size(), false), "ArrayList");
final List<Integer> linkedList = new LinkedList<Integer>(orig);
ListSampler.shuffle(rng, linkedList);
// Ensure that at least one entry has moved.
- Assert.assertTrue("LinkedList", compare(orig, linkedList, 0, orig.size(), false));
+ Assertions.assertTrue(compare(orig, linkedList, 0, orig.size(), false), "LinkedList");
}
@Test
@@ -127,10 +128,10 @@ public class ListSamplerTest {
ListSampler.shuffle(rng, list, start, false);
// Ensure that all entries below index "start" did not move.
- Assert.assertTrue(compare(orig, list, 0, start, true));
+ Assertions.assertTrue(compare(orig, list, 0, start, true));
// Ensure that at least one entry has moved.
- Assert.assertTrue(compare(orig, list, start, orig.size(), false));
+ Assertions.assertTrue(compare(orig, list, start, orig.size(), false));
}
@Test
@@ -145,10 +146,10 @@ public class ListSamplerTest {
ListSampler.shuffle(rng, list, start, true);
// Ensure that all entries above index "start" did not move.
- Assert.assertTrue(compare(orig, list, start + 1, orig.size(), true));
+ Assertions.assertTrue(compare(orig, list, start + 1, orig.size(), true));
// Ensure that at least one entry has moved.
- Assert.assertTrue(compare(orig, list, 0, start + 1, false));
+ Assertions.assertTrue(compare(orig, list, 0, start + 1, false));
}
/**
@@ -240,8 +241,7 @@ public class ListSamplerTest {
}
}
- Assert.fail("Sample not found: { " +
- samp[0] + ", " + samp[1] + " }");
+ Assertions.fail("Sample not found: { " + samp[0] + ", " + samp[1] + " }");
return -1;
}
@@ -265,10 +265,10 @@ public class ListSamplerTest {
ListSampler.shuffle(rng1, list);
PermutationSampler.shuffle(rng2, array);
- final String msg = "Type=" + list.getClass().getSimpleName();
+ final Supplier<String> msg = () -> "Type=" + list.getClass().getSimpleName();
it = list.listIterator();
for (int i = 0; i < array.length; i++) {
- Assert.assertEquals(msg, array[i], it.next().intValue());
+ Assertions.assertEquals(array[i], it.next().intValue(), msg);
}
}
/**
@@ -297,11 +297,11 @@ public class ListSamplerTest {
ListSampler.shuffle(rng1, list, start, towardHead);
PermutationSampler.shuffle(rng2, array, start, towardHead);
- final String msg = String.format("Type=%s start=%d towardHead=%b",
+ final Supplier<String> msg = () -> String.format("Type=%s start=%d towardHead=%b",
list.getClass().getSimpleName(), start, towardHead);
it = list.listIterator();
for (int i = 0; i < array.length; i++) {
- Assert.assertEquals(msg, array[i], it.next().intValue());
+ Assertions.assertEquals(array[i], it.next().intValue(), msg);
}
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/PermutationSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/PermutationSamplerTest.java
index 6f0739f..06d9631 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/PermutationSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/PermutationSamplerTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.rng.sampling;
import java.util.Arrays;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.apache.commons.math3.stat.inference.ChiSquareTest;
@@ -46,7 +46,7 @@ public class PermutationSamplerTest {
continue SAMPLE;
}
}
- Assert.fail("number " + s + " not in array");
+ Assertions.fail("number " + s + " not in array");
}
}
@@ -78,8 +78,8 @@ public class PermutationSamplerTest {
// Check size = 1 boundary case.
final PermutationSampler sampler = new PermutationSampler(rng, 1, 1);
final int[] perm = sampler.sample();
- Assert.assertEquals(1, perm.length);
- Assert.assertEquals(0, perm[0]);
+ Assertions.assertEquals(1, perm.length);
+ Assertions.assertEquals(0, perm[0]);
}
@Test(expected = IllegalArgumentException.class)
@@ -113,14 +113,14 @@ public class PermutationSamplerTest {
final int[] natural = PermutationSampler.natural(n);
for (int i = 0; i < n; i++) {
- Assert.assertEquals(expected[i], natural[i]);
+ Assertions.assertEquals(expected[i], natural[i]);
}
}
@Test
public void testNaturalZero() {
final int[] natural = PermutationSampler.natural(0);
- Assert.assertEquals(0, natural.length);
+ Assertions.assertEquals(0, natural.length);
}
@Test
@@ -136,7 +136,7 @@ public class PermutationSamplerTest {
}
for (int i = 0; i < n; i++) {
- Assert.assertEquals(1, count[i]);
+ Assertions.assertEquals(1, count[i]);
}
}
@@ -149,7 +149,7 @@ public class PermutationSamplerTest {
// Ensure that all entries below index "start" did not move.
for (int i = 0; i < start; i++) {
- Assert.assertEquals(orig[i], list[i]);
+ Assertions.assertEquals(orig[i], list[i]);
}
// Ensure that at least one entry has moved.
@@ -160,7 +160,7 @@ public class PermutationSamplerTest {
break;
}
}
- Assert.assertTrue(ok);
+ Assertions.assertTrue(ok);
}
@Test
@@ -172,7 +172,7 @@ public class PermutationSamplerTest {
// Ensure that all entries above index "start" did not move.
for (int i = start + 1; i < orig.length; i++) {
- Assert.assertEquals(orig[i], list[i]);
+ Assertions.assertEquals(orig[i], list[i]);
}
// Ensure that at least one entry has moved.
@@ -183,7 +183,7 @@ public class PermutationSamplerTest {
break;
}
}
- Assert.assertTrue(ok);
+ Assertions.assertTrue(ok);
}
/**
@@ -219,7 +219,7 @@ public class PermutationSamplerTest {
}
// Pass if we cannot reject null hypothesis that distributions are the same.
- Assert.assertFalse(chiSquareTest.chiSquareTest(expected, observed, 0.001));
+ Assertions.assertFalse(chiSquareTest.chiSquareTest(expected, observed, 0.001));
}
private static int findPerm(int[][] p,
@@ -229,7 +229,7 @@ public class PermutationSamplerTest {
return i;
}
}
- Assert.fail("Permutation not found");
+ Assertions.fail("Permutation not found");
return -1;
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/RandomAssert.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/RandomAssert.java
index 085f84e..0ea4a6d 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/RandomAssert.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/RandomAssert.java
@@ -17,7 +17,7 @@
package org.apache.commons.rng.sampling;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.apache.commons.rng.sampling.distribution.ContinuousSampler;
import org.apache.commons.rng.sampling.distribution.DiscreteSampler;
@@ -45,7 +45,7 @@ public final class RandomAssert {
public static void assertProduceSameSequence(ContinuousSampler sampler1,
ContinuousSampler sampler2) {
for (int i = 0; i < SAMPLES; i++) {
- Assert.assertEquals(sampler1.sample(), sampler2.sample(), 0.0);
+ Assertions.assertEquals(sampler1.sample(), sampler2.sample());
}
}
@@ -59,7 +59,7 @@ public final class RandomAssert {
public static void assertProduceSameSequence(DiscreteSampler sampler1,
DiscreteSampler sampler2) {
for (int i = 0; i < SAMPLES; i++) {
- Assert.assertEquals(sampler1.sample(), sampler2.sample());
+ Assertions.assertEquals(sampler1.sample(), sampler2.sample());
}
}
@@ -73,7 +73,7 @@ public final class RandomAssert {
public static void assertProduceSameSequence(LongSampler sampler1,
LongSampler sampler2) {
for (int i = 0; i < SAMPLES; i++) {
- Assert.assertEquals(sampler1.sample(), sampler2.sample());
+ Assertions.assertEquals(sampler1.sample(), sampler2.sample());
}
}
@@ -81,9 +81,9 @@ public final class RandomAssert {
* Exercise the {@link ObjectSampler} interface, and
* ensure that the two samplers produce the same sequence.
*
- * <p>Arrays are tested using {@link Assert#assertArrayEquals(Object[], Object[])}
+ * <p>Arrays are tested using {@link Assertions#assertArrayEquals(Object[], Object[])}
* which handles primitive arrays using exact equality and objects using
- * {@link Object#equals(Object)}. Otherwise {@link Assert#assertEquals(Object, Object)}
+ * {@link Object#equals(Object)}. Otherwise {@link Assertions#assertEquals(Object, Object)}
* is used which makes use of {@link Object#equals(Object)}.</p>
*
* <p>This should be used to test samplers of any type by wrapping the sample method
@@ -99,9 +99,9 @@ public final class RandomAssert {
final T value2 = sampler2.sample();
if (isArray(value1) && isArray(value2)) {
// JUnit assertArrayEquals will handle nested primitive arrays
- Assert.assertArrayEquals(new Object[] {value1}, new Object[] {value2});
+ Assertions.assertArrayEquals(new Object[] {value1}, new Object[] {value2});
} else {
- Assert.assertEquals(value1, value2);
+ Assertions.assertEquals(value1, value2);
}
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java
index d731a98..8ff8679 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.sampling;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.apache.commons.rng.simple.RandomSource;
import java.util.Arrays;
@@ -78,13 +78,13 @@ public class UnitSphereSamplerTest {
// Test the deprecated method once in the test suite.
@SuppressWarnings("deprecation")
final double[] v = generator.nextVector();
- Assert.assertEquals(1, v.length);
+ Assertions.assertEquals(1, v.length);
final double d = v[0];
if (d == -1.0) {
count++;
} else if (d != 1.0) {
// RNG-130: All samples should be 1 or -1.
- Assert.fail("Invalid unit length: " + d);
+ Assertions.fail("Invalid unit length: " + d);
}
}
// Test the number of negatives is approximately 50%
@@ -114,10 +114,9 @@ public class UnitSphereSamplerTest {
// the p-value requires the complimentary error function.
final double absSum = Math.abs(sum);
final double max = Math.sqrt(numberOfBits) * 2.576;
- Assert.assertTrue(
- "Walked too far astray: " + absSum + " > " + max +
- " (test will fail randomly about 1 in 100 times)",
- absSum <= max);
+ Assertions.assertTrue(absSum <= max,
+ () -> "Walked too far astray: " + absSum + " > " + max +
+ " (test will fail randomly about 1 in 100 times)");
}
/**
@@ -150,8 +149,8 @@ public class UnitSphereSamplerTest {
final int steps = 100000;
for (int i = 0; i < steps; ++i) {
final double[] v = generator.sample();
- Assert.assertEquals(2, v.length);
- Assert.assertEquals(1.0, length(v), 1e-10);
+ Assertions.assertEquals(2, v.length);
+ Assertions.assertEquals(1.0, length(v), 1e-10);
// Get the polar angle bin from xy
final int angleBin = angleBin(angleBins, v[0], v[1]);
observed[angleBin]++;
@@ -160,7 +159,7 @@ public class UnitSphereSamplerTest {
final double[] expected = new double[observed.length];
Arrays.fill(expected, (double) steps / observed.length);
final double p = new ChiSquareTest().chiSquareTest(expected, observed);
- Assert.assertFalse("p-value too small: " + p, p < 0.01);
+ Assertions.assertFalse(p < 0.01, () -> "p-value too small: " + p);
}
/**
@@ -200,8 +199,8 @@ public class UnitSphereSamplerTest {
final int steps = 1000000;
for (int i = 0; i < steps; ++i) {
final double[] v = generator.sample();
- Assert.assertEquals(3, v.length);
- Assert.assertEquals(1.0, length(v), 1e-10);
+ Assertions.assertEquals(3, v.length);
+ Assertions.assertEquals(1.0, length(v), 1e-10);
// Get the polar angle bin from xy
final int angleBin = angleBin(angleBins, v[0], v[1]);
// Map cos(phi) = z from [-1, 1) to [0, 1) then assign a bin
@@ -212,7 +211,7 @@ public class UnitSphereSamplerTest {
final double[] expected = new double[observed.length];
Arrays.fill(expected, (double) steps / observed.length);
final double p = new ChiSquareTest().chiSquareTest(expected, observed);
- Assert.assertFalse("p-value too small: " + p, p < 0.01);
+ Assertions.assertFalse(p < 0.01, () -> "p-value too small: " + p);
}
/**
@@ -271,8 +270,8 @@ public class UnitSphereSamplerTest {
final int steps = 1000000;
for (int i = 0; i < steps; ++i) {
final double[] v = generator.sample();
- Assert.assertEquals(4, v.length);
- Assert.assertEquals(1.0, length(v), 1e-10);
+ Assertions.assertEquals(4, v.length);
+ Assertions.assertEquals(1.0, length(v), 1e-10);
// Circle 1
observed1[circleBin(angleBins, r, v[0], v[1])]++;
// Circle 2
@@ -283,9 +282,9 @@ public class UnitSphereSamplerTest {
Arrays.fill(expected, (double) steps / observed1.length);
final ChiSquareTest chi = new ChiSquareTest();
final double p1 = chi.chiSquareTest(expected, observed1);
- Assert.assertFalse("Circle 1 p-value too small: " + p1, p1 < 0.01);
+ Assertions.assertFalse(p1 < 0.01, () -> "Circle 1 p-value too small: " + p1);
final double p2 = chi.chiSquareTest(expected, observed2);
- Assert.assertFalse("Circle 2 p-value too small: " + p2, p2 < 0.01);
+ Assertions.assertFalse(p2 < 0.01, () -> "Circle 2 p-value too small: " + p2);
}
/**
@@ -431,8 +430,8 @@ public class UnitSphereSamplerTest {
};
final double[] vector = UnitSphereSampler.of(bad, dimension).sample();
- Assert.assertEquals(dimension, vector.length);
- Assert.assertEquals(1.0, length(vector), 1e-10);
+ Assertions.assertEquals(dimension, vector.length);
+ Assertions.assertEquals(1.0, length(vector), 1e-10);
}
/**
@@ -447,7 +446,7 @@ public class UnitSphereSamplerTest {
// Map to the scaling factor
final double f = 1 / Math.sqrt(normSq);
// As long as this is finite positive then the sampler is valid
- Assert.assertTrue(f > 0 && f <= Double.MAX_VALUE);
+ Assertions.assertTrue(f > 0 && f <= Double.MAX_VALUE);
}
/**
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/AhrensDieterExponentialSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/AhrensDieterExponentialSamplerTest.java
index 10fd206..24e474f 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/AhrensDieterExponentialSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/AhrensDieterExponentialSamplerTest.java
@@ -22,7 +22,7 @@ import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.core.source64.SplitMix64;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
@@ -77,7 +77,7 @@ public class AhrensDieterExponentialSamplerTest {
final SharedStateContinuousSampler sampler = AhrensDieterExponentialSampler.of(rng, 1);
// This should not infinite loop
final double x = sampler.sample();
- Assert.assertTrue(x >= 0);
+ Assertions.assertTrue(x >= 0);
}
/**
@@ -96,6 +96,6 @@ public class AhrensDieterExponentialSamplerTest {
};
final SharedStateContinuousSampler sampler = AhrensDieterExponentialSampler.of(rng, 1);
final double x = sampler.sample();
- Assert.assertTrue(x >= 0);
+ Assertions.assertTrue(x >= 0);
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSamplerTest.java
index cb03418..718ecf9 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSamplerTest.java
@@ -20,7 +20,7 @@ import org.apache.commons.rng.RestorableUniformRandomProvider;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -90,7 +90,7 @@ public class AhrensDieterMarsagliaTsangGammaSamplerTest {
@Test
public void testToString() {
final UniformRandomProvider rng = RandomSource.SPLIT_MIX_64.create(0L);
- Assert.assertTrue(new AhrensDieterMarsagliaTsangGammaSampler(rng, 1.0, 2.0).toString()
+ Assertions.assertTrue(new AhrensDieterMarsagliaTsangGammaSampler(rng, 1.0, 2.0).toString()
.toLowerCase().contains("gamma"));
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/AliasMethodDiscreteSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/AliasMethodDiscreteSamplerTest.java
index e259f21..6a01e74 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/AliasMethodDiscreteSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/AliasMethodDiscreteSamplerTest.java
@@ -22,7 +22,7 @@ import org.apache.commons.math3.stat.inference.ChiSquareTest;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import java.util.Arrays;
@@ -69,7 +69,7 @@ public class AliasMethodDiscreteSamplerTest {
@Test
public void testToString() {
final SharedStateDiscreteSampler sampler = createSampler(new double[] {0.5, 0.5});
- Assert.assertTrue(sampler.toString().toLowerCase().contains("alias method"));
+ Assertions.assertTrue(sampler.toString().toLowerCase().contains("alias method"));
}
/**
@@ -241,13 +241,13 @@ public class AliasMethodDiscreteSamplerTest {
expected[mapSize] = probabilies[i];
observed[mapSize] = samples[i];
} else {
- Assert.assertEquals("No samples expected from zero probability", 0, samples[i]);
+ Assertions.assertEquals(0, samples[i], "No samples expected from zero probability");
}
}
final ChiSquareTest chiSquareTest = new ChiSquareTest();
// Pass if we cannot reject null hypothesis that the distributions are the same.
- Assert.assertFalse(chiSquareTest.chiSquareTest(expected, observed, 0.001));
+ Assertions.assertFalse(chiSquareTest.chiSquareTest(expected, observed, 0.001));
}
/**
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ChengBetaSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ChengBetaSamplerTest.java
index a058bf7..4daa16e 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ChengBetaSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ChengBetaSamplerTest.java
@@ -20,7 +20,7 @@ import org.apache.commons.rng.RestorableUniformRandomProvider;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -106,7 +106,7 @@ public class ChengBetaSamplerTest {
@Test
public void testToString() {
final UniformRandomProvider rng = RandomSource.SPLIT_MIX_64.create(0L);
- Assert.assertTrue(new ChengBetaSampler(rng, 1.0, 2.0).toString()
+ Assertions.assertTrue(new ChengBetaSampler(rng, 1.0, 2.0).toString()
.toLowerCase().contains("beta"));
}
}
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 199e504..4ad40e3 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
@@ -20,7 +20,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -129,9 +129,9 @@ public class ContinuousSamplerParametricTest {
// 3 0.0016
if (numFailures > 3) { // Test will fail with 0.16% probability
- Assert.fail(sampler + ": Too many failures for sample size = " + sampleSize +
- " (" + numFailures + " out of " + numTests + " tests failed, " +
- "chi2=" + Arrays.toString(failedStat.toArray(new Double[0])) + ")");
+ Assertions.fail(sampler + ": Too many failures for sample size = " + sampleSize +
+ " (" + numFailures + " out of " + numTests + " tests failed, " +
+ "chi2=" + Arrays.toString(failedStat.toArray(new Double[0])) + ")");
}
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousUniformSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousUniformSamplerTest.java
index 9db2c6e..2a55ca1 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousUniformSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousUniformSamplerTest.java
@@ -20,7 +20,7 @@ import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.core.source64.SplitMix64;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -46,7 +46,7 @@ public class ContinuousUniformSamplerTest {
final double max = Math.max(low, high);
for (int i = 0; i < 10; i++) {
final double value = sampler.sample();
- Assert.assertTrue("Value not in range", value >= min && value <= max);
+ Assertions.assertTrue(value >= min && value <= max, () -> "Value not in range: " + value);
}
}
@@ -84,7 +84,7 @@ public class ContinuousUniformSamplerTest {
// Test the sampler excludes the end points
for (int i = 0; i < 10; i++) {
final double value = sampler.sample();
- Assert.assertTrue("Value not in range: " + value, value > low && value < high);
+ Assertions.assertTrue(value > low && value < high, () -> "Value not in range: " + value);
}
}
@@ -114,13 +114,13 @@ public class ContinuousUniformSamplerTest {
final double high = interval[1];
try {
ContinuousUniformSampler.of(rng, low, high, true);
- Assert.fail("(" + low + "," + high + ")");
+ Assertions.fail("(" + low + "," + high + ")");
} catch (IllegalArgumentException ex) {
// Expected
}
try {
ContinuousUniformSampler.of(rng, high, low, true);
- Assert.fail("(" + high + "," + low + ")");
+ Assertions.fail("(" + high + "," + low + ")");
} catch (IllegalArgumentException ex) {
// Expected
}
@@ -147,18 +147,18 @@ public class ContinuousUniformSamplerTest {
}) {
final double low = Math.nextUp(expected);
final double high = Math.nextDown(expected);
- Assert.assertEquals(expected, ContinuousUniformSampler.of(rng, low, high, true).sample(), 0.0);
- Assert.assertEquals(expected, ContinuousUniformSampler.of(rng, high, low, true).sample(), 0.0);
- Assert.assertEquals(-expected, ContinuousUniformSampler.of(rng, -low, -high, true).sample(), 0.0);
- Assert.assertEquals(-expected, ContinuousUniformSampler.of(rng, -high, -low, true).sample(), 0.0);
+ Assertions.assertEquals(expected, ContinuousUniformSampler.of(rng, low, high, true).sample());
+ Assertions.assertEquals(expected, ContinuousUniformSampler.of(rng, high, low, true).sample());
+ Assertions.assertEquals(-expected, ContinuousUniformSampler.of(rng, -low, -high, true).sample());
+ Assertions.assertEquals(-expected, ContinuousUniformSampler.of(rng, -high, -low, true).sample());
}
// Special case of sampling around zero.
// Requires 2 doubles inside the range.
final double y = ContinuousUniformSampler.of(rng, -x, 2 * x, true).sample();
- Assert.assertTrue(-x < y && y < 2 * x);
+ Assertions.assertTrue(-x < y && y < 2 * x);
final double z = ContinuousUniformSampler.of(rng, -2 * x, x, true).sample();
- Assert.assertTrue(-2 * x < z && z < x);
+ Assertions.assertTrue(-2 * x < z && z < x);
}
/**
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/DirichletSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/DirichletSamplerTest.java
index 53b440b..cc1ae0a 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/DirichletSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/DirichletSamplerTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.sampling.distribution;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import java.util.Arrays;
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
@@ -148,8 +148,8 @@ public class DirichletSamplerTest {
final UniformRandomProvider rng = RandomSource.SPLIT_MIX_64.create(0L);
final DirichletSampler sampler1 = DirichletSampler.symmetric(rng, 2, 1.0);
final DirichletSampler sampler2 = DirichletSampler.of(rng, 0.5, 1, 1.5);
- Assert.assertTrue(sampler1.toString().toLowerCase().contains("dirichlet"));
- Assert.assertTrue(sampler2.toString().toLowerCase().contains("dirichlet"));
+ Assertions.assertTrue(sampler1.toString().toLowerCase().contains("dirichlet"));
+ Assertions.assertTrue(sampler2.toString().toLowerCase().contains("dirichlet"));
}
@Test
@@ -212,7 +212,7 @@ public class DirichletSamplerTest {
final double[] means = getColumnMeans(samples);
for (int i = 0; i < k; i++) {
final double mean = alpha[i] / alpha0;
- Assert.assertEquals("Mean", mean, means[i], mean * relativeTolerance);
+ Assertions.assertEquals(mean, means[i], mean * relativeTolerance, "Mean");
}
// Variance = alpha_i (alpha_0 - alpha_i) / alpha_0^2 (alpha_0 + 1)
@@ -221,10 +221,10 @@ public class DirichletSamplerTest {
final double denom = alpha0 * alpha0 * (alpha0 + 1);
for (int i = 0; i < k; i++) {
final double var = alpha[i] * (alpha0 - alpha[i]) / denom;
- Assert.assertEquals("Variance", var, covars[i][i], var * relativeTolerance);
+ Assertions.assertEquals(var, covars[i][i], var * relativeTolerance, "Variance");
for (int j = i + 1; j < k; j++) {
final double covar = -alpha[i] * alpha[j] / denom;
- Assert.assertEquals("Covariance", covar, covars[i][j], Math.abs(covar) * relativeTolerance);
+ Assertions.assertEquals(covar, covars[i][j], Math.abs(covar) * relativeTolerance, "Covariance");
}
}
}
@@ -236,14 +236,14 @@ public class DirichletSamplerTest {
* @param x Sample.
*/
private static void assertSample(int k, double[] x) {
- Assert.assertEquals("Number of categories", k, x.length);
+ Assertions.assertEquals(k, x.length, "Number of categories");
// There are always at least 2 categories
double sum = x[0] + x[1];
// Sum the rest
for (int i = 2; i < x.length; i++) {
sum += x[i];
}
- Assert.assertEquals("Invalid sum", 1.0, sum, 1e-10);
+ Assertions.assertEquals(1.0, sum, 1e-10, "Invalid sum");
}
/**
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/DiscreteSamplerParametricTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/DiscreteSamplerParametricTest.java
index 379c914..8ad84d1 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/DiscreteSamplerParametricTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/DiscreteSamplerParametricTest.java
@@ -20,7 +20,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -125,9 +125,9 @@ public class DiscreteSamplerParametricTest {
// 3 0.0016
if (numFailures > 3) { // Test will fail with 0.16% probability
- Assert.fail(sampler + ": Too many failures for sample size = " + sampleSize +
- " (" + numFailures + " out of " + numTests + " tests failed, " +
- "chi2=" + Arrays.toString(failedStat.toArray(new Double[0])));
+ Assertions.fail(sampler + ": Too many failures for sample size = " + sampleSize +
+ " (" + numFailures + " out of " + numTests + " tests failed, " +
+ "chi2=" + Arrays.toString(failedStat.toArray(new Double[0])));
}
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/DiscreteUniformSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/DiscreteUniformSamplerTest.java
index 98bdfa3..a16bf0b 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/DiscreteUniformSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/DiscreteUniformSamplerTest.java
@@ -20,7 +20,7 @@ import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.core.source32.IntProvider;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import java.util.Locale;
@@ -48,7 +48,7 @@ public class DiscreteUniformSamplerTest {
final UniformRandomProvider rng = RandomSource.SPLIT_MIX_64.create();
final SharedStateDiscreteSampler sampler = DiscreteUniformSampler.of(rng, lower, upper);
for (int i = 0; i < 5; i++) {
- Assert.assertEquals(lower, sampler.sample());
+ Assertions.assertEquals(lower, sampler.sample());
}
}
@@ -64,7 +64,7 @@ public class DiscreteUniformSamplerTest {
final UniformRandomProvider rng2 = RandomSource.SPLIT_MIX_64.create(0L);
final SharedStateDiscreteSampler sampler = DiscreteUniformSampler.of(rng2, lower, upper);
for (int i = 0; i < 10; i++) {
- Assert.assertEquals(rng1.nextInt(), sampler.sample());
+ Assertions.assertEquals(rng1.nextInt(), sampler.sample());
}
}
@@ -83,7 +83,7 @@ public class DiscreteUniformSamplerTest {
final UniformRandomProvider rng2 = RandomSource.SPLIT_MIX_64.create(0L);
final SharedStateDiscreteSampler sampler = DiscreteUniformSampler.of(rng2, lower, upper);
for (int i = 0; i < 10; i++) {
- Assert.assertEquals(lower + rng1.nextInt(n), sampler.sample());
+ Assertions.assertEquals(lower + rng1.nextInt(n), sampler.sample());
}
}
}
@@ -118,9 +118,9 @@ public class DiscreteUniformSamplerTest {
final int range = 1 << i;
final int upper = lower + range - 1;
sampler = new DiscreteUniformSampler(rngZeroBits, lower, upper);
- Assert.assertEquals("Zero bits sample", lower, sampler.sample());
+ Assertions.assertEquals(lower, sampler.sample(), "Zero bits sample");
sampler = new DiscreteUniformSampler(rngAllBits, lower, upper);
- Assert.assertEquals("All bits sample", upper, sampler.sample());
+ Assertions.assertEquals(upper, sampler.sample(), "All bits sample");
}
}
@@ -141,7 +141,7 @@ public class DiscreteUniformSamplerTest {
final UniformRandomProvider rng2 = RandomSource.SPLIT_MIX_64.create(0L);
sampler = DiscreteUniformSampler.of(rng2, lower, upper);
for (int j = 0; j < 10; j++) {
- Assert.assertEquals(rng1.nextInt() >>> shift, sampler.sample());
+ Assertions.assertEquals(rng1.nextInt() >>> shift, sampler.sample());
}
}
}
@@ -164,7 +164,7 @@ public class DiscreteUniformSamplerTest {
do {
expected = rng1.nextInt();
} while (expected < lower || expected > upper);
- Assert.assertEquals(expected, sampler.sample());
+ Assertions.assertEquals(expected, sampler.sample());
}
}
@@ -200,8 +200,8 @@ public class DiscreteUniformSamplerTest {
final int sample1 = sampler.sample();
final int sample2 = samplerLo.sample();
final int sample3 = samplerHi.sample();
- Assert.assertEquals("Incorrect negative offset sample", sample1 + offsetLo, sample2);
- Assert.assertEquals("Incorrect positive offset sample", sample1 + offsetHi, sample3);
+ Assertions.assertEquals(sample1 + offsetLo, sample2, "Incorrect negative offset sample");
+ Assertions.assertEquals(sample1 + offsetHi, sample3, "Incorrect positive offset sample");
}
}
@@ -258,7 +258,7 @@ public class DiscreteUniformSamplerTest {
min = Math.min(min, value);
max = Math.max(max, value);
}
- Assert.assertTrue("Not uniform, max = " + max + ", min=" + min, max - min <= 1);
+ Assertions.assertTrue(max - min <= 1, "Not uniform, max = " + max + ", min=" + min);
}
/**
@@ -295,7 +295,7 @@ public class DiscreteUniformSamplerTest {
// This should be even across the entire range
for (int value : histogram) {
- Assert.assertEquals(expected, value);
+ Assertions.assertEquals(expected, value);
}
}
@@ -327,8 +327,8 @@ public class DiscreteUniformSamplerTest {
final int sample = sampler.sample();
- Assert.assertEquals("Sample is incorrect", 0, sample);
- Assert.assertEquals("Sample should be produced from 2nd value", 2, value[0]);
+ Assertions.assertEquals(0, sample, "Sample is incorrect");
+ Assertions.assertEquals(2, value[0], "Sample should be produced from 2nd value");
}
@Test
@@ -399,6 +399,6 @@ public class DiscreteUniformSamplerTest {
private static void assertToString(int lower, int upper) {
final UniformRandomProvider rng = RandomSource.SPLIT_MIX_64.create(0L);
final DiscreteUniformSampler sampler = new DiscreteUniformSampler(rng, lower, upper);
- Assert.assertTrue(sampler.toString().toLowerCase(Locale.US).contains("uniform"));
+ Assertions.assertTrue(sampler.toString().toLowerCase(Locale.US).contains("uniform"));
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GeometricSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GeometricSamplerTest.java
index 53f0585..d31f25c 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GeometricSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GeometricSamplerTest.java
@@ -19,7 +19,7 @@ package org.apache.commons.rng.sampling.distribution;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -36,7 +36,7 @@ public class GeometricSamplerTest {
final SharedStateDiscreteSampler sampler = GeometricSampler.of(rng, 1);
// All samples should be 0
for (int i = 0; i < 10; i++) {
- Assert.assertEquals("p=1 should have 0 for all samples", 0, sampler.sample());
+ Assertions.assertEquals(0, sampler.sample(), "p=1 should have 0 for all samples");
}
}
@@ -52,7 +52,7 @@ public class GeometricSamplerTest {
// Map to the mean
final double exponentialMean = 1.0 / (-Math.log1p(-probabilityOfSuccess));
// As long as this is finite positive then the sampler is valid
- Assert.assertTrue(exponentialMean > 0 && exponentialMean <= Double.MAX_VALUE);
+ Assertions.assertTrue(exponentialMean > 0 && exponentialMean <= Double.MAX_VALUE);
// The internal exponential sampler validates the mean so demonstrate creating a
// geometric sampler does not throw.
final UniformRandomProvider rng = RandomSource.SPLIT_MIX_64.create(0L);
@@ -67,8 +67,8 @@ public class GeometricSamplerTest {
public void testProbabilityOfSuccessIsOneSamplerToString() {
final UniformRandomProvider unusedRng = RandomSource.SPLIT_MIX_64.create(0L);
final SharedStateDiscreteSampler sampler = GeometricSampler.of(unusedRng, 1);
- Assert.assertTrue("Missing 'Geometric' from toString",
- sampler.toString().contains("Geometric"));
+ Assertions.assertTrue(sampler.toString().contains("Geometric"),
+ "Missing 'Geometric' from toString");
}
/**
@@ -86,8 +86,8 @@ public class GeometricSamplerTest {
final SharedStateDiscreteSampler sampler = GeometricSampler.of(rng, Double.MIN_VALUE);
// All samples should be max value
for (int i = 0; i < 10; i++) {
- Assert.assertEquals("p=(almost 0) should have Integer.MAX_VALUE for all samples",
- Integer.MAX_VALUE, sampler.sample());
+ Assertions.assertEquals(Integer.MAX_VALUE, sampler.sample(),
+ "p=(almost 0) should have Integer.MAX_VALUE for all samples");
}
}
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 7cfd85b..9ce205f 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
@@ -22,7 +22,7 @@ import org.apache.commons.math3.stat.inference.ChiSquareTest;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -77,7 +77,7 @@ public class GuideTableDiscreteSamplerTest {
@Test
public void testToString() {
final SharedStateDiscreteSampler sampler = createSampler(new double[] {0.5, 0.5}, 1.0);
- Assert.assertTrue(sampler.toString().toLowerCase().contains("guide table"));
+ Assertions.assertTrue(sampler.toString().toLowerCase().contains("guide table"));
}
/**
@@ -222,7 +222,7 @@ public class GuideTableDiscreteSamplerTest {
final long[] observed = new long[mapSize];
for (int i = 0; i < probabilies.length; i++) {
if (probabilies[i] == 0) {
- Assert.assertEquals("No samples expected from zero probability", 0, samples[i]);
+ Assertions.assertEquals(0, samples[i], "No samples expected from zero probability");
} else {
// This can be added for the Chi-square test
--mapSize;
@@ -233,7 +233,7 @@ public class GuideTableDiscreteSamplerTest {
final ChiSquareTest chiSquareTest = new ChiSquareTest();
// Pass if we cannot reject null hypothesis that the distributions are the same.
- Assert.assertFalse(chiSquareTest.chiSquareTest(expected, observed, 0.001));
+ Assertions.assertFalse(chiSquareTest.chiSquareTest(expected, observed, 0.001));
}
/**
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/InternalUtilsTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/InternalUtilsTest.java
index f91a7c4..8505efc 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/InternalUtilsTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/InternalUtilsTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.rng.sampling.distribution;
import org.apache.commons.math3.special.Gamma;
import org.apache.commons.rng.sampling.distribution.InternalUtils.FactorialLog;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -30,11 +30,11 @@ public class InternalUtilsTest {
@Test
public void testFactorial() {
- Assert.assertEquals(1L, InternalUtils.factorial(0));
+ Assertions.assertEquals(1L, InternalUtils.factorial(0));
long result = 1;
for (int n = 1; n <= MAX_REPRESENTABLE; n++) {
result *= n;
- Assert.assertEquals(result, InternalUtils.factorial(n));
+ Assertions.assertEquals(result, InternalUtils.factorial(n));
}
}
@@ -53,11 +53,11 @@ public class InternalUtilsTest {
// Cache size allows some of the factorials to be cached and some
// to be under the precomputed factorials.
FactorialLog factorialLog = FactorialLog.create().withCache(MAX_REPRESENTABLE / 2);
- Assert.assertEquals(0, factorialLog.value(0), 1e-10);
+ Assertions.assertEquals(0, factorialLog.value(0), 1e-10);
for (int n = 1; n <= MAX_REPRESENTABLE + 5; n++) {
// Use Commons math to compute logGamma(1 + n);
double expected = Gamma.logGamma(1 + n);
- Assert.assertEquals(expected, factorialLog.value(n), 1e-10);
+ Assertions.assertEquals(expected, factorialLog.value(n), 1e-10);
}
}
@@ -68,7 +68,7 @@ public class InternalUtilsTest {
for (int n = MAX_REPRESENTABLE; n <= limit; n++) {
// Use Commons math to compute logGamma(1 + n);
double expected = Gamma.logGamma(1 + n);
- Assert.assertEquals(expected, factorialLog.value(n), 1e-10);
+ Assertions.assertEquals(expected, factorialLog.value(n), 1e-10);
}
}
@@ -88,7 +88,7 @@ public class InternalUtilsTest {
for (int n = 1; n <= 5; n++) {
// Use Commons math to compute logGamma(1 + n);
double expected = Gamma.logGamma(1 + n);
- Assert.assertEquals(expected, factorialLog.value(n), 1e-10);
+ Assertions.assertEquals(expected, factorialLog.value(n), 1e-10);
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/KempSmallMeanPoissonSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/KempSmallMeanPoissonSamplerTest.java
index 802b976..cec759b 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/KempSmallMeanPoissonSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/KempSmallMeanPoissonSamplerTest.java
@@ -20,7 +20,7 @@ import org.apache.commons.math3.distribution.PoissonDistribution;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -94,8 +94,8 @@ public class KempSmallMeanPoissonSamplerTest {
x = x + 1;
p = p * mean / x;
}
- Assert.assertEquals("Summation is not zero", 0, u, 1e-3);
- Assert.assertTrue("Summation is not greater than zero", u > 0);
+ Assertions.assertEquals(0, u, 1e-3, "Summation is not zero");
+ Assertions.assertTrue(u > 0, "Summation is not greater than zero");
}
/**
@@ -113,8 +113,8 @@ public class KempSmallMeanPoissonSamplerTest {
x = x + 1;
p = p * mean / x;
}
- Assert.assertEquals("Summation is not one", 1, u, 1e-3);
- Assert.assertTrue("Summation is not less than one", u < 1);
+ Assertions.assertEquals(1, u, 1e-3, "Summation is not one");
+ Assertions.assertTrue(u < 1, "Summation is not less than one");
}
/**
@@ -173,8 +173,8 @@ public class KempSmallMeanPoissonSamplerTest {
int lower, int upper) {
rng.setValue(cumulativeProbability);
final int sample = sampler.sample();
- Assert.assertTrue(sample + " sample is not above realistic lower limit: " + lower, sample >= lower);
- Assert.assertTrue(sample + " sample is not below realistic upper limit: " + upper, sample <= upper);
+ Assertions.assertTrue(sample >= lower, () -> sample + " sample is not above realistic lower limit: " + lower);
+ Assertions.assertTrue(sample <= upper, () -> sample + " sample is not below realistic upper limit: " + upper);
}
/**
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/LargeMeanPoissonSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/LargeMeanPoissonSamplerTest.java
index dbdfa6b..f3707e4 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/LargeMeanPoissonSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/LargeMeanPoissonSamplerTest.java
@@ -22,7 +22,7 @@ import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.sampling.distribution.LargeMeanPoissonSampler.LargeMeanPoissonSamplerState;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -135,8 +135,8 @@ public class LargeMeanPoissonSamplerTest {
final LargeMeanPoissonSamplerState state1 = s1.getState();
final LargeMeanPoissonSampler s2 = new LargeMeanPoissonSampler(rng2, state1, lambdaFractional);
final LargeMeanPoissonSamplerState state2 = s2.getState();
- Assert.assertEquals("State lambdas are not equal", state1.getLambda(), state2.getLambda());
- Assert.assertNotSame("States are the same object", state1, state2);
+ Assertions.assertEquals(state1.getLambda(), state2.getLambda(), "State lambdas are not equal");
+ Assertions.assertNotSame(state1, state2, "States are the same object");
RandomAssert.assertProduceSameSequence(s1, s2);
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/LevySamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/LevySamplerTest.java
index 0d32410..27cbc61 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/LevySamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/LevySamplerTest.java
@@ -21,7 +21,7 @@ import org.apache.commons.rng.core.source64.SplitMix64;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -79,7 +79,7 @@ public class LevySamplerTest {
return 0L;
}
}, location, scale);
- Assert.assertEquals(Double.POSITIVE_INFINITY, s1.sample(), 0.0);
+ Assertions.assertEquals(Double.POSITIVE_INFINITY, s1.sample());
// Force the underlying ZigguratSampler.NormalizedGaussian to create a large
// sample in the tail of the distribution.
@@ -117,6 +117,6 @@ public class LevySamplerTest {
// So the sampler never achieves the lower bound of zero.
// It requires an extreme deviate from the Gaussian.
final double expected = 1 / (s * s);
- Assert.assertEquals(expected, s2.sample(), 0.0);
+ Assertions.assertEquals(expected, s2.sample());
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/MarsagliaNormalisedGaussianSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/MarsagliaNormalisedGaussianSamplerTest.java
index fdf4732..f766d54 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/MarsagliaNormalisedGaussianSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/MarsagliaNormalisedGaussianSamplerTest.java
@@ -20,7 +20,7 @@ import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.core.source32.IntProvider;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -79,6 +79,6 @@ public class MarsagliaNormalisedGaussianSamplerTest {
final double x = 2 * value - 1;
final double r2 = x * x + x * x;
final double expected = x * Math.sqrt(-2 * Math.log(r2) / r2);
- Assert.assertEquals(expected, sampler.sample(), 0);
+ Assertions.assertEquals(expected, sampler.sample());
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/MarsagliaTsangWangDiscreteSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/MarsagliaTsangWangDiscreteSamplerTest.java
index 8e3573c..ffbaab3 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/MarsagliaTsangWangDiscreteSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/MarsagliaTsangWangDiscreteSamplerTest.java
@@ -22,7 +22,7 @@ import org.apache.commons.rng.core.source32.IntProvider;
import org.apache.commons.rng.core.source64.SplitMix64;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -75,7 +75,7 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
final DiscreteSampler sampler = createDiscreteDistributionSampler(new double[] {0.5, 0.5});
String text = sampler.toString();
for (String item : new String[] {"Marsaglia", "Tsang", "Wang"}) {
- Assert.assertTrue("toString missing: " + item, text.contains(item));
+ Assertions.assertTrue(text.contains(item), () -> "toString missing: " + item);
}
}
@@ -155,8 +155,8 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
final int s1 = sampler1.sample() - offset1;
final int s2 = sampler2.sample() - offset2;
final int s3 = sampler3.sample() - offset3;
- Assert.assertEquals("Offset sample 1 and 2 do not match", s1, s2);
- Assert.assertEquals("Offset Sample 1 and 3 do not match", s1, s3);
+ Assertions.assertEquals(s1, s2, "Offset sample 1 and 2 do not match");
+ Assertions.assertEquals(s1, s3, "Offset Sample 1 and 3 do not match");
}
}
@@ -204,7 +204,7 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
final ChiSquareTest chiSquareTest = new ChiSquareTest();
// Pass if we cannot reject null hypothesis that the distributions are the same.
- Assert.assertFalse(chiSquareTest.chiSquareTest(probabilities, samples, 0.001));
+ Assertions.assertFalse(chiSquareTest.chiSquareTest(probabilities, samples, 0.001));
}
/**
@@ -258,7 +258,7 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
// Check the sum is less than 2^30
final long sum = (long) maxSamples * m;
final int total = 1 << 30;
- Assert.assertTrue("Worst case uniform distribution is above 2^30", sum < total);
+ Assertions.assertTrue(sum < total, "Worst case uniform distribution is above 2^30");
// Get the digits as per the sampler and compute storage
final int d1 = getBase64Digit(m, 1);
@@ -276,9 +276,9 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
bytes = 4;
}
final double storageMB = bytes * 1e-6 * (d1 + d2 + d3 + d4 + d5) * maxSamples;
- Assert.assertTrue(
- "Worst case uniform distribution storage " + storageMB + "MB is above expected limit: " + expectedLimitMB,
- storageMB < expectedLimitMB);
+ Assertions.assertTrue(storageMB < expectedLimitMB,
+ () -> "Worst case uniform distribution storage " + storageMB +
+ "MB is above expected limit: " + expectedLimitMB);
}
/**
@@ -422,8 +422,8 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
final int trials = (int) Math.floor(Math.log(Double.MIN_VALUE) / Math.log(0.5));
final double p = 0.5;
// Validate set-up
- Assert.assertEquals("Invalid test set-up for p(0)", Double.MIN_VALUE, getBinomialP0(trials, p), 0);
- Assert.assertEquals("Invalid test set-up for p(0)", 0, getBinomialP0(trials + 1, p), 0);
+ Assertions.assertEquals(Double.MIN_VALUE, getBinomialP0(trials, p), 0, "Invalid test set-up for p(0)");
+ Assertions.assertEquals(0, getBinomialP0(trials + 1, p), 0, "Invalid test set-up for p(0)");
// This will throw if the table does not sum to 2^30
final DiscreteSampler sampler = MarsagliaTsangWangDiscreteSampler.Binomial.of(rng, trials, p);
@@ -441,7 +441,7 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
final int trials = 1 + (int) Math.floor(Math.log(Double.MIN_VALUE) / Math.log(0.5));
final double p = 0.5;
// Validate set-up
- Assert.assertEquals("Invalid test set-up for p(0)", 0, getBinomialP0(trials, p), 0);
+ Assertions.assertEquals(0, getBinomialP0(trials, p), 0, "Invalid test set-up for p(0)");
@SuppressWarnings("unused")
final DiscreteSampler sampler = MarsagliaTsangWangDiscreteSampler.Binomial.of(rng, trials, p);
}
@@ -465,11 +465,11 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
double p = 1 - Math.exp(Math.log(Double.MIN_VALUE) / trials);
// Validate set-up
- Assert.assertEquals("Invalid test set-up for p(0)", Double.MIN_VALUE, getBinomialP0(trials, p), 0);
+ Assertions.assertEquals(Double.MIN_VALUE, getBinomialP0(trials, p), 0, "Invalid test set-up for p(0)");
// Search for larger p until Math.nextUp(p) produces 0
double upper = p * 2;
- Assert.assertEquals("Invalid test set-up for p(0)", 0, getBinomialP0(trials, upper), 0);
+ Assertions.assertEquals(0, getBinomialP0(trials, upper), 0, "Invalid test set-up for p(0)");
double lower = p;
while (Double.doubleToRawLongBits(lower) + 1 < Double.doubleToRawLongBits(upper)) {
@@ -483,8 +483,8 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
p = lower;
// Re-validate
- Assert.assertEquals("Invalid test set-up for p(0)", Double.MIN_VALUE, getBinomialP0(trials, p), 0);
- Assert.assertEquals("Invalid test set-up for p(0)", 0, getBinomialP0(trials, Math.nextUp(p)), 0);
+ Assertions.assertEquals(Double.MIN_VALUE, getBinomialP0(trials, p), 0, "Invalid test set-up for p(0)");
+ Assertions.assertEquals(0, getBinomialP0(trials, Math.nextUp(p)), 0, "Invalid test set-up for p(0)");
final DiscreteSampler sampler = MarsagliaTsangWangDiscreteSampler.Binomial.of(rng, trials, p);
// This will throw if the table does not sum to 2^30
@@ -512,10 +512,10 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
final double p = 0;
final DiscreteSampler sampler = MarsagliaTsangWangDiscreteSampler.Binomial.of(rng, trials, p);
for (int i = 0; i < 5; i++) {
- Assert.assertEquals(0, sampler.sample());
+ Assertions.assertEquals(0, sampler.sample());
}
// Hit the toString() method
- Assert.assertTrue(sampler.toString().contains("Binomial"));
+ Assertions.assertTrue(sampler.toString().contains("Binomial"));
}
/**
@@ -529,10 +529,10 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
final double p = 1;
final DiscreteSampler sampler = MarsagliaTsangWangDiscreteSampler.Binomial.of(rng, trials, p);
for (int i = 0; i < 5; i++) {
- Assert.assertEquals(trials, sampler.sample());
+ Assertions.assertEquals(trials, sampler.sample());
}
// Hit the toString() method
- Assert.assertTrue(sampler.toString().contains("Binomial"));
+ Assertions.assertTrue(sampler.toString().contains("Binomial"));
}
/**
@@ -578,7 +578,7 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
final double p2 = 1 - p1;
final DiscreteSampler sampler1 = MarsagliaTsangWangDiscreteSampler.Binomial.of(rng, trials, p1);
final DiscreteSampler sampler2 = MarsagliaTsangWangDiscreteSampler.Binomial.of(rng, trials, p2);
- Assert.assertEquals(sampler1.toString(), sampler2.toString());
+ Assertions.assertEquals(sampler1.toString(), sampler2.toString());
}
/**
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/PoissonSamplerCacheTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/PoissonSamplerCacheTest.java
index 85490e9..a604199 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/PoissonSamplerCacheTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/PoissonSamplerCacheTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.rng.sampling.distribution;
import org.apache.commons.rng.RestorableUniformRandomProvider;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -43,7 +43,7 @@ public class PoissonSamplerCacheTest {
*/
@Test
public void testMinimumCachedMean() {
- Assert.assertEquals(PoissonSampler.PIVOT, PoissonSamplerCache.getMinimumCachedMean(), 0);
+ Assertions.assertEquals(PoissonSampler.PIVOT, PoissonSamplerCache.getMinimumCachedMean());
}
// Edge cases for construction
@@ -58,9 +58,9 @@ public class PoissonSamplerCacheTest {
final double min = 0;
final double max = PoissonSampler.PIVOT - 2;
final PoissonSamplerCache cache = createPoissonSamplerCache(min, max);
- Assert.assertFalse(cache.isValidRange());
- Assert.assertEquals(0, cache.getMinMean(), 0);
- Assert.assertEquals(0, cache.getMaxMean(), 0);
+ Assertions.assertFalse(cache.isValidRange());
+ Assertions.assertEquals(0, cache.getMinMean());
+ Assertions.assertEquals(0, cache.getMaxMean());
}
/**
@@ -73,10 +73,10 @@ public class PoissonSamplerCacheTest {
final double min = PoissonSampler.PIVOT + 2;
final double max = min;
final PoissonSamplerCache cache = createPoissonSamplerCache(min, max);
- Assert.assertTrue(cache.isValidRange());
- Assert.assertEquals(min, cache.getMinMean(), 0);
- Assert.assertEquals(Math.nextDown(Math.floor(max) + 1),
- cache.getMaxMean(), 0);
+ Assertions.assertTrue(cache.isValidRange());
+ Assertions.assertEquals(min, cache.getMinMean());
+ Assertions.assertEquals(Math.nextDown(Math.floor(max) + 1),
+ cache.getMaxMean());
}
/**
@@ -89,10 +89,10 @@ public class PoissonSamplerCacheTest {
final double min = PoissonSampler.PIVOT + 2;
final double max = min + 10;
final PoissonSamplerCache cache = createPoissonSamplerCache(min, max);
- Assert.assertTrue(cache.isValidRange());
- Assert.assertEquals(min, cache.getMinMean(), 0);
- Assert.assertEquals(Math.nextDown(Math.floor(max) + 1),
- cache.getMaxMean(), 0);
+ Assertions.assertTrue(cache.isValidRange());
+ Assertions.assertEquals(min, cache.getMinMean());
+ Assertions.assertEquals(Math.nextDown(Math.floor(max) + 1),
+ cache.getMaxMean());
}
/**
@@ -114,10 +114,10 @@ public class PoissonSamplerCacheTest {
final double min = -1;
final double max = PoissonSampler.PIVOT + 2;
final PoissonSamplerCache cache = createPoissonSamplerCache(min, max);
- Assert.assertTrue(cache.isValidRange());
- Assert.assertEquals(PoissonSampler.PIVOT, cache.getMinMean(), 0);
- Assert.assertEquals(Math.nextDown(Math.floor(max) + 1),
- cache.getMaxMean(), 0);
+ Assertions.assertTrue(cache.isValidRange());
+ Assertions.assertEquals(PoissonSampler.PIVOT, cache.getMinMean());
+ Assertions.assertEquals(Math.nextDown(Math.floor(max) + 1),
+ cache.getMaxMean());
}
/**
@@ -129,9 +129,9 @@ public class PoissonSamplerCacheTest {
final double min = -10;
final double max = -1;
final PoissonSamplerCache cache = createPoissonSamplerCache(min, max);
- Assert.assertFalse(cache.isValidRange());
- Assert.assertEquals(0, cache.getMinMean(), 0);
- Assert.assertEquals(0, cache.getMaxMean(), 0);
+ Assertions.assertFalse(cache.isValidRange());
+ Assertions.assertEquals(0, cache.getMinMean());
+ Assertions.assertEquals(0, cache.getMaxMean());
}
/**
@@ -144,9 +144,9 @@ public class PoissonSamplerCacheTest {
final double min = 0;
final double max = PoissonSampler.PIVOT - 2;
final PoissonSamplerCache cache = createPoissonSamplerCache().withRange(min, max);
- Assert.assertFalse(cache.isValidRange());
- Assert.assertEquals(0, cache.getMinMean(), 0);
- Assert.assertEquals(0, cache.getMaxMean(), 0);
+ Assertions.assertFalse(cache.isValidRange());
+ Assertions.assertEquals(0, cache.getMinMean());
+ Assertions.assertEquals(0, cache.getMaxMean());
}
/**
@@ -159,10 +159,10 @@ public class PoissonSamplerCacheTest {
final double min = PoissonSampler.PIVOT + 2;
final double max = min;
final PoissonSamplerCache cache = createPoissonSamplerCache().withRange(min, max);
- Assert.assertTrue(cache.isValidRange());
- Assert.assertEquals(min, cache.getMinMean(), 0);
- Assert.assertEquals(Math.nextDown(Math.floor(max) + 1),
- cache.getMaxMean(), 0);
+ Assertions.assertTrue(cache.isValidRange());
+ Assertions.assertEquals(min, cache.getMinMean());
+ Assertions.assertEquals(Math.nextDown(Math.floor(max) + 1),
+ cache.getMaxMean());
}
/**
@@ -175,10 +175,10 @@ public class PoissonSamplerCacheTest {
final double min = PoissonSampler.PIVOT + 2;
final double max = min + 10;
final PoissonSamplerCache cache = createPoissonSamplerCache().withRange(min, max);
- Assert.assertTrue(cache.isValidRange());
- Assert.assertEquals(min, cache.getMinMean(), 0);
- Assert.assertEquals(Math.nextDown(Math.floor(max) + 1),
- cache.getMaxMean(), 0);
+ Assertions.assertTrue(cache.isValidRange());
+ Assertions.assertEquals(min, cache.getMinMean());
+ Assertions.assertEquals(Math.nextDown(Math.floor(max) + 1),
+ cache.getMaxMean());
}
/**
@@ -200,10 +200,10 @@ public class PoissonSamplerCacheTest {
final double min = -1;
final double max = PoissonSampler.PIVOT + 2;
final PoissonSamplerCache cache = createPoissonSamplerCache().withRange(min, max);
- Assert.assertTrue(cache.isValidRange());
- Assert.assertEquals(PoissonSampler.PIVOT, cache.getMinMean(), 0);
- Assert.assertEquals(Math.nextDown(Math.floor(max) + 1),
- cache.getMaxMean(), 0);
+ Assertions.assertTrue(cache.isValidRange());
+ Assertions.assertEquals(PoissonSampler.PIVOT, cache.getMinMean());
+ Assertions.assertEquals(Math.nextDown(Math.floor(max) + 1),
+ cache.getMaxMean());
}
/**
@@ -214,10 +214,10 @@ public class PoissonSamplerCacheTest {
final double min = PoissonSampler.PIVOT + 2;
final double max = min + 10;
final PoissonSamplerCache cache = createPoissonSamplerCache(0, 0).withRange(min, max);
- Assert.assertTrue(cache.isValidRange());
- Assert.assertEquals(min, cache.getMinMean(), 0);
- Assert.assertEquals(Math.nextDown(Math.floor(max) + 1),
- cache.getMaxMean(), 0);
+ Assertions.assertTrue(cache.isValidRange());
+ Assertions.assertEquals(min, cache.getMinMean());
+ Assertions.assertEquals(Math.nextDown(Math.floor(max) + 1),
+ cache.getMaxMean());
}
/**
@@ -230,11 +230,11 @@ public class PoissonSamplerCacheTest {
final double max = PoissonSampler.PIVOT + 20;
final PoissonSamplerCache cache = createPoissonSamplerCache(min, max);
// Under the pivot point is always within range
- Assert.assertTrue(cache.withinRange(PoissonSampler.PIVOT - 1));
- Assert.assertFalse(cache.withinRange(min - 1));
- Assert.assertTrue(cache.withinRange(min));
- Assert.assertTrue(cache.withinRange(max));
- Assert.assertFalse(cache.withinRange(max + 10));
+ Assertions.assertTrue(cache.withinRange(PoissonSampler.PIVOT - 1));
+ Assertions.assertFalse(cache.withinRange(min - 1));
+ Assertions.assertTrue(cache.withinRange(min));
+ Assertions.assertTrue(cache.withinRange(max));
+ Assertions.assertFalse(cache.withinRange(max + 10));
}
// Edge cases for creating a Poisson sampler
@@ -384,7 +384,7 @@ public class PoissonSamplerCacheTest {
final DiscreteSampler s1 = PoissonSampler.of(rng1, mean);
final DiscreteSampler s2 = cache.createSharedStateSampler(rng2, mean);
for (int j = 0; j < 10; j++) {
- Assert.assertEquals(s1.sample(), s2.sample());
+ Assertions.assertEquals(s1.sample(), s2.sample());
}
}
@@ -468,7 +468,7 @@ public class PoissonSamplerCacheTest {
}
final PoissonSamplerCache cache2 = cache.withRange(minMean2, maxMean2);
- Assert.assertNotSame("WithRange cache is the same object", cache, cache2);
+ Assertions.assertNotSame(cache, cache2, "WithRange cache is the same object");
// Test all means in the test range (which may be different
// from the cache range).
@@ -489,6 +489,6 @@ public class PoissonSamplerCacheTest {
public void testCreatePoissonSampler() {
final PoissonSamplerCache cache = createPoissonSamplerCache(0, 100);
final DiscreteSampler s2 = cache.createPoissonSampler(null, 42);
- Assert.assertTrue(s2 instanceof LargeMeanPoissonSampler);
+ Assertions.assertTrue(s2 instanceof LargeMeanPoissonSampler);
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/PoissonSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/PoissonSamplerTest.java
index 4385633..63cc85b 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/PoissonSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/PoissonSamplerTest.java
@@ -19,7 +19,7 @@ package org.apache.commons.rng.sampling.distribution;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
@@ -66,6 +66,6 @@ public class PoissonSamplerTest {
@Test
public void testToString() {
final UniformRandomProvider rng = RandomSource.SPLIT_MIX_64.create(0L);
- Assert.assertTrue(new PoissonSampler(rng, 1.23).toString().toLowerCase().contains("poisson"));
+ Assertions.assertTrue(new PoissonSampler(rng, 1.23).toString().toLowerCase().contains("poisson"));
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/SamplerBaseTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/SamplerBaseTest.java
index af8db5b..e5e97cb 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/SamplerBaseTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/SamplerBaseTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.rng.sampling.distribution;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -63,10 +63,10 @@ public class SamplerBaseTest {
final SimpleSampler sampler = new SimpleSampler(rng2);
final int n = 256;
for (int i = 0; i < 3; i++) {
- Assert.assertEquals(rng1.nextDouble(), sampler.nextDouble(), 0);
- Assert.assertEquals(rng1.nextInt(), sampler.nextInt());
- Assert.assertEquals(rng1.nextInt(n), sampler.nextInt(n));
- Assert.assertEquals(rng1.nextLong(), sampler.nextLong());
+ Assertions.assertEquals(rng1.nextDouble(), sampler.nextDouble());
+ Assertions.assertEquals(rng1.nextInt(), sampler.nextInt());
+ Assertions.assertEquals(rng1.nextInt(n), sampler.nextInt(n));
+ Assertions.assertEquals(rng1.nextLong(), sampler.nextLong());
}
}
@@ -74,6 +74,6 @@ public class SamplerBaseTest {
public void testToString() {
final UniformRandomProvider rng = RandomSource.SPLIT_MIX_64.create(0L);
final SimpleSampler sampler = new SimpleSampler(rng);
- Assert.assertTrue(sampler.toString().contains("rng"));
+ Assertions.assertTrue(sampler.toString().contains("rng"));
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/SmallMeanPoissonSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/SmallMeanPoissonSamplerTest.java
index 57bd094..a1f9427 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/SmallMeanPoissonSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/SmallMeanPoissonSamplerTest.java
@@ -19,7 +19,7 @@ package org.apache.commons.rng.sampling.distribution;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -73,7 +73,7 @@ public class SmallMeanPoissonSamplerTest {
for (double mean : new double[] {0.5, 1, 1.5, 2.2}) {
final SharedStateDiscreteSampler sampler = SmallMeanPoissonSampler.of(rng, mean);
final int expected = (int) Math.ceil(1000 * mean);
- Assert.assertEquals(expected, sampler.sample());
+ Assertions.assertEquals(expected, sampler.sample());
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/StableSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/StableSamplerTest.java
index efe2c02..29ebe13 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/StableSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/StableSamplerTest.java
@@ -16,8 +16,9 @@
*/
package org.apache.commons.rng.sampling.distribution;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
+import java.util.function.Supplier;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.core.source64.SplitMix64;
import org.apache.commons.rng.sampling.RandomAssert;
@@ -88,12 +89,12 @@ public class StableSamplerTest {
// The number 1 - alpha must not be 1.
// This is valid
StableSampler s = createStableSampler(SMALLEST_ALPHA, VALID_BETA, VALID_GAMMA, VALID_DELTA);
- Assert.assertNotNull(s);
+ Assertions.assertNotNull(s);
// Smaller than this is still above zero but 1 - alpha == 1
final double alphaTooSmall = SMALLEST_ALPHA / 2;
- Assert.assertNotEquals("Expected alpha to be positive", 0.0, alphaTooSmall, 0.0);
- Assert.assertEquals("Expected rounding to 1", 1.0, 1 - alphaTooSmall, 0.0);
+ Assertions.assertNotEquals(0.0, alphaTooSmall, "Expected alpha to be positive");
+ Assertions.assertEquals(1.0, 1 - alphaTooSmall, "Expected rounding to 1");
// Because alpha is effectively zero this will throw
createStableSampler(alphaTooSmall, VALID_BETA, VALID_GAMMA, VALID_DELTA);
@@ -184,8 +185,8 @@ public class StableSamplerTest {
// alpha -> 2: tau -> 0
// alpha -> 0: tau -> 0
- Assert.assertEquals(0.0, CMSStableSampler.getTau(2, beta), 0.0);
- Assert.assertEquals(0.0, CMSStableSampler.getTau(0, beta), 0.0);
+ Assertions.assertEquals(0.0, CMSStableSampler.getTau(2, beta));
+ Assertions.assertEquals(0.0, CMSStableSampler.getTau(0, beta));
// Full range over 0 to 2.
for (int i = 0; i <= 512; i++) {
@@ -193,46 +194,46 @@ public class StableSamplerTest {
final double alpha = (double) i / 256;
final double tau = CMSStableSampler.getTau(alpha, beta);
final double expected = getTauOriginal(alpha, beta);
- Assert.assertEquals(expected, tau, 1e-15);
+ Assertions.assertEquals(expected, tau, 1e-15);
// Symmetric
- Assert.assertEquals(tau, CMSStableSampler.getTau(2 - alpha, beta), 0.0);
+ Assertions.assertEquals(tau, CMSStableSampler.getTau(2 - alpha, beta));
}
// alpha -> 1: tau -> beta / (pi / 2) = 0.6366
final double limit = beta / PI_2;
- Assert.assertEquals(limit, CMSStableSampler.getTau(1, beta), 0.0);
+ Assertions.assertEquals(limit, CMSStableSampler.getTau(1, beta));
for (double alpha : new double[] {1.01, 1 + 1e-6, 1, 1 - 1e-6, 0.99}) {
final double tau = CMSStableSampler.getTau(alpha, beta);
final double expected = getTauOriginal(alpha, beta);
- Assert.assertEquals(expected, tau, 1e-15);
+ Assertions.assertEquals(expected, tau, 1e-15);
// Approach the limit
- Assert.assertEquals(limit, tau, Math.abs(1 - alpha) + 1e-15);
+ Assertions.assertEquals(limit, tau, Math.abs(1 - alpha) + 1e-15);
}
// It can be zero if beta is zero or close to zero when alpha != 1.
// This requires we check tau==0 instead of beta==0 to switch to
// a beta = 0 sampler.
- Assert.assertEquals(0.0, CMSStableSampler.getTau(1.3, 0.0), 0.0);
- Assert.assertEquals(0.0, CMSStableSampler.getTau(1.5, Double.MIN_VALUE), 0.0);
- Assert.assertNotEquals(0.0, CMSStableSampler.getTau(1.0, Double.MIN_VALUE), 0.0);
+ Assertions.assertEquals(0.0, CMSStableSampler.getTau(1.3, 0.0));
+ Assertions.assertEquals(0.0, CMSStableSampler.getTau(1.5, Double.MIN_VALUE));
+ Assertions.assertNotEquals(0.0, CMSStableSampler.getTau(1.0, Double.MIN_VALUE));
// The sign of beta determines the sign of tau.
- Assert.assertEquals(0.5, CMSStableSampler.getTau(1.5, beta), 0.0);
- Assert.assertEquals(0.5, CMSStableSampler.getTau(0.5, beta), 0.0);
- Assert.assertEquals(-0.5, CMSStableSampler.getTau(1.5, -beta), 0.0);
- Assert.assertEquals(-0.5, CMSStableSampler.getTau(0.5, -beta), 0.0);
+ Assertions.assertEquals(0.5, CMSStableSampler.getTau(1.5, beta));
+ Assertions.assertEquals(0.5, CMSStableSampler.getTau(0.5, beta));
+ Assertions.assertEquals(-0.5, CMSStableSampler.getTau(1.5, -beta));
+ Assertions.assertEquals(-0.5, CMSStableSampler.getTau(0.5, -beta));
// Check monototic at the transition point to switch to a different computation.
final double tau1 = CMSStableSampler.getTau(Math.nextDown(1.5), 1);
final double tau2 = CMSStableSampler.getTau(1.5, 1);
final double tau3 = CMSStableSampler.getTau(Math.nextUp(1.5), 1);
- Assert.assertTrue(tau1 > tau2);
- Assert.assertTrue(tau2 > tau3);
+ Assertions.assertTrue(tau1 > tau2);
+ Assertions.assertTrue(tau2 > tau3);
// Test symmetry at the transition
- Assert.assertEquals(tau1, CMSStableSampler.getTau(2 - Math.nextDown(1.5), 1), 0.0);
- Assert.assertEquals(tau2, CMSStableSampler.getTau(0.5, 1), 0.0);
- Assert.assertEquals(tau3, CMSStableSampler.getTau(2 - Math.nextUp(1.5), 1), 0.0);
+ Assertions.assertEquals(tau1, CMSStableSampler.getTau(2 - Math.nextDown(1.5), 1));
+ Assertions.assertEquals(tau2, CMSStableSampler.getTau(0.5, 1));
+ Assertions.assertEquals(tau3, CMSStableSampler.getTau(2 - Math.nextUp(1.5), 1));
}
/**
@@ -278,27 +279,27 @@ public class StableSamplerTest {
// The extreme limit of the angle phiby2. This is ignored by the sampler
// as it can result in cancellation of terms and invalid results.
final double p0 = getU(Long.MIN_VALUE);
- Assert.assertEquals(-PI_4, p0, 0.0);
+ Assertions.assertEquals(-PI_4, p0);
// These are the limits to generate (-pi/4, pi/4)
final double p1 = getU(Long.MIN_VALUE + (1 << 10));
final double p2 = getU(Long.MAX_VALUE);
- Assert.assertNotEquals(-PI_4, p1, 0.0);
- Assert.assertNotEquals(PI_4, p2, 0.0);
- Assert.assertEquals(-PI_4 + PI_4 * DU, p1, 0.0);
- Assert.assertEquals(PI_4 - PI_4 * DU, p2, 0.0);
+ Assertions.assertNotEquals(-PI_4, p1);
+ Assertions.assertNotEquals(PI_4, p2);
+ Assertions.assertEquals(-PI_4 + PI_4 * DU, p1);
+ Assertions.assertEquals(PI_4 - PI_4 * DU, p2);
for (double phiby2 : new double[] {p1, p2}) {
// phiby2 in (-pi/4, pi/4)
// a in (-1, 1)
final double a = phiby2 * SpecialMath.tan2(phiby2);
- Assert.assertEquals(Math.copySign(Math.nextDown(1.0), phiby2), a, 0.0);
+ Assertions.assertEquals(Math.copySign(Math.nextDown(1.0), phiby2), a);
final double da = a * a;
final double a2 = 1 - da;
// The number is close to but not equal to zero
- Assert.assertNotEquals(0.0, a2, 0.0);
+ Assertions.assertNotEquals(0.0, a2);
// The minimum value of a2 is 2.220E-16 = 2^-52
- Assert.assertEquals(0x1.0p-52, a2, 0.0);
+ Assertions.assertEquals(0x1.0p-52, a2);
}
}
@@ -319,9 +320,9 @@ public class StableSamplerTest {
final long x00 = Long.MIN_VALUE;
final long x0 = Long.MIN_VALUE + (1 << 10);
final long x1 = Long.MAX_VALUE;
- Assert.assertEquals(-PI_4, getU(x00), 0.0);
- Assert.assertEquals(-PI_4 + DU * PI_4, getU(x0), 0.0);
- Assert.assertEquals(PI_4 - DU * PI_4, getU(x1), 0.0);
+ Assertions.assertEquals(-PI_4, getU(x00));
+ Assertions.assertEquals(-PI_4 + DU * PI_4, getU(x0));
+ Assertions.assertEquals(PI_4 - DU * PI_4, getU(x1));
// General case numerator:
// b2 + 2 * phiby2 * bb * tau
// To generate 0 numerator requires:
@@ -355,41 +356,41 @@ public class StableSamplerTest {
// This is not true due to floating-point
// error but the following cases are known to exhibit the result.
- Assert.assertEquals(0.0, computeNumerator(0.859375, 1, x00), 0.0);
+ Assertions.assertEquals(0.0, computeNumerator(0.859375, 1, x00));
// Even worse to have negative as the log(-ve) = nan
- Assert.assertTrue(0.0 > computeNumerator(0.9375, 1, x00));
- Assert.assertTrue(0.0 > computeNumerator(1.90625, 1, x00));
+ Assertions.assertTrue(0.0 > computeNumerator(0.9375, 1, x00));
+ Assertions.assertTrue(0.0 > computeNumerator(1.90625, 1, x00));
// As phi reduces in magnitude the equality fails.
// The numerator=0 can often be corrected
// with the next random variate from the range limit.
- Assert.assertTrue(0.0 < computeNumerator(0.859375, 1, x0));
- Assert.assertTrue(0.0 < computeNumerator(0.9375, 1, x0));
- Assert.assertTrue(0.0 < computeNumerator(1.90625, 1, x0));
+ Assertions.assertTrue(0.0 < computeNumerator(0.859375, 1, x0));
+ Assertions.assertTrue(0.0 < computeNumerator(0.9375, 1, x0));
+ Assertions.assertTrue(0.0 < computeNumerator(1.90625, 1, x0));
// WARNING:
// Even when u is not at the limit floating point error can still create
// a bad numerator. This is rare but shows we must still detect this edge
// case.
- Assert.assertTrue(0.0 > computeNumerator(0.828125, 1, x0));
- Assert.assertTrue(0.0 > computeNumerator(1.291015625, -1, x1));
+ Assertions.assertTrue(0.0 > computeNumerator(0.828125, 1, x0));
+ Assertions.assertTrue(0.0 > computeNumerator(1.291015625, -1, x1));
// beta=0 case the numerator reduces to b2:
// b2 = 1 - tan^2((1-alpha) * phi/2)
// requires tan(x)=1; x=pi/4.
// Note: tan(x) = x * SpecialMath.tan2(x) returns +/-1 for u = +/-pi/4.
- Assert.assertEquals(-1, SpecialMath.tan2(getU(x00)) * getU(x00), 0.0);
+ Assertions.assertEquals(-1, SpecialMath.tan2(getU(x00)) * getU(x00));
// Using the next value in the range this is not an issue.
// The beta=0 sampler does not have to check for z=0.
- Assert.assertTrue(-1 < SpecialMath.tan2(getU(x0)) * getU(x0));
- Assert.assertTrue(1 > SpecialMath.tan2(getU(x1)) * getU(x1));
+ Assertions.assertTrue(-1 < SpecialMath.tan2(getU(x0)) * getU(x0));
+ Assertions.assertTrue(1 > SpecialMath.tan2(getU(x1)) * getU(x1));
// Use alpha=2 so 1-alpha (eps) is at the limit
final double beta = 0;
- Assert.assertEquals(0.0, computeNumerator(2, beta, x00), 0.0);
- Assert.assertTrue(0.0 < computeNumerator(2, beta, x0));
- Assert.assertTrue(0.0 < computeNumerator(2, beta, x1));
- Assert.assertTrue(0.0 < computeNumerator(Math.nextDown(2), beta, x0));
- Assert.assertTrue(0.0 < computeNumerator(Math.nextDown(2), beta, x1));
+ Assertions.assertEquals(0.0, computeNumerator(2, beta, x00));
+ Assertions.assertTrue(0.0 < computeNumerator(2, beta, x0));
+ Assertions.assertTrue(0.0 < computeNumerator(2, beta, x1));
+ Assertions.assertTrue(0.0 < computeNumerator(Math.nextDown(2), beta, x0));
+ Assertions.assertTrue(0.0 < computeNumerator(Math.nextDown(2), beta, x1));
// alpha=1 case the numerator reduces to:
// 1 + 2 * phi/2 * tau
@@ -402,14 +403,14 @@ public class StableSamplerTest {
// beta = -1 => phiby2 = pi/4
// The alpha=1 sampler does not have to check for z=0 if phiby2 excludes -pi/4.
final double alpha = 1;
- Assert.assertEquals(0.0, computeNumerator(alpha, 1, x00), 0.0);
+ Assertions.assertEquals(0.0, computeNumerator(alpha, 1, x00));
// Next value of u computes above zero
- Assert.assertTrue(0.0 < computeNumerator(alpha, 1, x0));
- Assert.assertTrue(0.0 < computeNumerator(alpha, -1, x1));
+ Assertions.assertTrue(0.0 < computeNumerator(alpha, 1, x0));
+ Assertions.assertTrue(0.0 < computeNumerator(alpha, -1, x1));
// beta < 1 => u < 0
// beta > -1 => u > 1
// z=0 not possible with any other beta
- Assert.assertTrue(0.0 < computeNumerator(alpha, Math.nextUp(-1), x00));
+ Assertions.assertTrue(0.0 < computeNumerator(alpha, Math.nextUp(-1), x00));
}
/**
@@ -449,7 +450,7 @@ public class StableSamplerTest {
// Finite z
for (final double z : zs) {
// The result may be infinite, but not NaN
- Assert.assertNotEquals(Double.NaN, computeD(alpha, z), 0.0);
+ Assertions.assertNotEquals(Double.NaN, computeD(alpha, z));
}
// May be invalid with z=0 or z=inf as some combinations multiply the
@@ -459,28 +460,28 @@ public class StableSamplerTest {
final double d0 = computeD(alpha, 0);
if (alpha < 1) {
// d2(-inf) * -inf = 0 * -inf = NaN
- Assert.assertEquals(Double.NaN, d0, 0.0);
+ Assertions.assertEquals(Double.NaN, d0);
} else if (alpha == 1) {
// d2(0 * -inf) -> NaN
- Assert.assertEquals(Double.NaN, d0, 0.0);
+ Assertions.assertEquals(Double.NaN, d0);
} else {
// alpha > 1
// d2(inf) * -inf = -inf
- Assert.assertEquals(Double.NEGATIVE_INFINITY, d0, 0.0);
+ Assertions.assertEquals(Double.NEGATIVE_INFINITY, d0);
}
// When z=inf, log(z) = inf, d = d2(sign(1-alpha) * inf) * inf
final double di = computeD(alpha, Double.POSITIVE_INFINITY);
if (alpha < 1) {
// d2(inf) * inf = inf
- Assert.assertEquals(Double.POSITIVE_INFINITY, di, 0.0);
+ Assertions.assertEquals(Double.POSITIVE_INFINITY, di);
} else if (alpha == 1) {
// d2(0 * inf) -> NaN
- Assert.assertEquals(Double.NaN, di, 0.0);
+ Assertions.assertEquals(Double.NaN, di);
} else {
// alpha > 1
// d2(-inf) * inf = 0 * inf = NaN
- Assert.assertEquals(Double.NaN, di, 0.0);
+ Assertions.assertEquals(Double.NaN, di);
}
}
}
@@ -517,7 +518,7 @@ public class StableSamplerTest {
double beta = Math.tan(-alpha * phi) / Math.tan(alpha * PI_2);
double zeta = -beta * Math.tan(alpha * PI_2);
double atanZeta = Math.atan(-zeta);
- Assert.assertEquals(0.0, alpha * phi + atanZeta, 0.0);
+ Assertions.assertEquals(0.0, alpha * phi + atanZeta);
}
}
}
@@ -532,9 +533,9 @@ public class StableSamplerTest {
// This is the extreme of cos(x) that should be used
final double cosPi2 = Math.cos(PI_2);
// The function is symmetric
- Assert.assertEquals(cosPi2, Math.cos(-PI_2), 0.0);
+ Assertions.assertEquals(cosPi2, Math.cos(-PI_2));
// As pi is an approximation then the cos value is not exactly 0
- Assert.assertTrue(cosPi2 > 0);
+ Assertions.assertTrue(cosPi2 > 0);
final UniformRandomProvider rng = RandomSource.XO_SHI_RO_256_SS.create();
@@ -625,20 +626,20 @@ public class StableSamplerTest {
// Test it is in the interval (-pi/2, pi/2)
double phi = getU(x) * 2;
double value = eps * phi + alphaPi2;
- Assert.assertTrue(value <= PI_2);
- Assert.assertTrue(value >= -PI_2);
+ Assertions.assertTrue(value <= PI_2);
+ Assertions.assertTrue(value >= -PI_2);
value = eps * phi - alphaPi2;
- Assert.assertTrue(value <= PI_2);
- Assert.assertTrue(value >= -PI_2);
+ Assertions.assertTrue(value <= PI_2);
+ Assertions.assertTrue(value >= -PI_2);
// Mirror the deviate
phi = -phi;
value = eps * phi + alphaPi2;
- Assert.assertTrue(value <= PI_2);
- Assert.assertTrue(value >= -PI_2);
+ Assertions.assertTrue(value <= PI_2);
+ Assertions.assertTrue(value >= -PI_2);
value = eps * phi - alphaPi2;
- Assert.assertTrue(value <= PI_2);
- Assert.assertTrue(value >= -PI_2);
+ Assertions.assertTrue(value <= PI_2);
+ Assertions.assertTrue(value >= -PI_2);
}
/**
* Assumption test:
@@ -651,9 +652,9 @@ public class StableSamplerTest {
// getU creates in the domain (-pi/4, pi/4) so double the angle.
for (final double phi : new double[] {getU(-1) * 2, getU(1 << 10) * 2}) {
final double x = Math.sin(SMALLEST_ALPHA * phi);
- Assert.assertNotEquals(0.0, x, 0.0);
+ Assertions.assertNotEquals(0.0, x);
// Value is actually:
- Assert.assertEquals(1.9361559566769725E-32, Math.abs(x), 0.0);
+ Assertions.assertEquals(1.9361559566769725E-32, Math.abs(x));
}
}
@@ -666,15 +667,15 @@ public class StableSamplerTest {
@Test
public void testExpM1() {
// Test monotonic at the switch point
- Assert.assertEquals(d2(0.5), d2b(0.5), 0.0);
+ Assertions.assertEquals(d2(0.5), d2b(0.5));
// When positive x -> 0 the value smaller bigger.
- Assert.assertTrue(d2(Math.nextDown(0.5)) <= d2b(0.5));
- Assert.assertEquals(d2(-0.5), d2b(-0.5), 0.0);
+ Assertions.assertTrue(d2(Math.nextDown(0.5)) <= d2b(0.5));
+ Assertions.assertEquals(d2(-0.5), d2b(-0.5));
// When negative x -> 0 the value gets bigger.
- Assert.assertTrue(d2(-Math.nextDown(0.5)) >= d2b(-0.5));
+ Assertions.assertTrue(d2(-Math.nextDown(0.5)) >= d2b(-0.5));
// Potentially the next power of 2 could be used based on ULP errors but
// the switch is not monotonic.
- Assert.assertFalse(d2(Math.nextDown(0.25)) <= d2b(0.25));
+ Assertions.assertFalse(d2(Math.nextDown(0.25)) <= d2b(0.25));
}
/**
@@ -696,7 +697,7 @@ public class StableSamplerTest {
// Note:
// The point at which there *should* be no difference between the two is when
// exp(x) - 1 == exp(x). This will occur at exp(x)=2^54, x = ln(2^54) = 37.43.
- Assert.assertEquals(((double) (1L << 54)) - 1, (double) (1L << 54), 0.0);
+ Assertions.assertEquals(((double) (1L << 54)) - 1, (double) (1L << 54));
// However since expm1 and exp are only within 1 ULP of the exact result differences
// still occur above this threshold.
// 2^6 = 64; 2^-4 = 0.0625
@@ -704,8 +705,8 @@ public class StableSamplerTest {
// The exponent must be unsigned so + 1023 to the signed exponent
final long exp = (signedExp + 1023L) << 52;
// Test we are creating the correct numbers
- Assert.assertEquals(signedExp, Math.getExponent(Double.longBitsToDouble(exp)));
- Assert.assertEquals(signedExp, Math.getExponent(Double.longBitsToDouble((-1 & mask) | exp)));
+ Assertions.assertEquals(signedExp, Math.getExponent(Double.longBitsToDouble(exp)));
+ Assertions.assertEquals(signedExp, Math.getExponent(Double.longBitsToDouble((-1 & mask) | exp)));
// Get the average and max ulp
long sum1 = 0;
long sum2 = 0;
@@ -806,23 +807,23 @@ public class StableSamplerTest {
@Test
public void testD2() {
for (final double x : new double[] {Double.MAX_VALUE, Math.log(Double.MAX_VALUE), 10, 5, 1, 0.5, 0.1, 0.05, 0.01}) {
- Assert.assertEquals(Math.expm1(x) / x, SpecialMath.d2(x), 1e-15);
- Assert.assertEquals(Math.expm1(-x) / -x, SpecialMath.d2(-x), 1e-15);
+ Assertions.assertEquals(Math.expm1(x) / x, SpecialMath.d2(x), 1e-15);
+ Assertions.assertEquals(Math.expm1(-x) / -x, SpecialMath.d2(-x), 1e-15);
}
// Negative infinity computes without correction
- Assert.assertEquals(0.0, Math.expm1(Double.NEGATIVE_INFINITY) / Double.NEGATIVE_INFINITY, 0.0);
- Assert.assertEquals(0.0, SpecialMath.d2(Double.NEGATIVE_INFINITY), 0.0);
+ Assertions.assertEquals(0.0, Math.expm1(Double.NEGATIVE_INFINITY) / Double.NEGATIVE_INFINITY);
+ Assertions.assertEquals(0.0, SpecialMath.d2(Double.NEGATIVE_INFINITY));
// NaN is returned (i.e. no correction)
- Assert.assertEquals(Double.NaN, SpecialMath.d2(Double.NaN), 0.0);
+ Assertions.assertEquals(Double.NaN, SpecialMath.d2(Double.NaN));
// Edge cases for z=0 or z==inf require correction
- Assert.assertEquals(Double.NaN, Math.expm1(0) / 0.0, 0.0);
- Assert.assertEquals(Double.NaN, Math.expm1(Double.POSITIVE_INFINITY) / Double.POSITIVE_INFINITY, 0.0);
+ Assertions.assertEquals(Double.NaN, Math.expm1(0) / 0.0);
+ Assertions.assertEquals(Double.NaN, Math.expm1(Double.POSITIVE_INFINITY) / Double.POSITIVE_INFINITY);
// Corrected in the special function
- Assert.assertEquals(1.0, SpecialMath.d2(0.0), 0.0);
- Assert.assertEquals(Double.POSITIVE_INFINITY, SpecialMath.d2(Double.POSITIVE_INFINITY), 0.0);
+ Assertions.assertEquals(1.0, SpecialMath.d2(0.0));
+ Assertions.assertEquals(Double.POSITIVE_INFINITY, SpecialMath.d2(Double.POSITIVE_INFINITY));
}
/**
@@ -833,18 +834,18 @@ public class StableSamplerTest {
// Test the value of tan(x) when the angle is generated in the open interval (-pi/4, pi/4)
for (final long x : new long[] {Long.MIN_VALUE + (1 << 10), Long.MAX_VALUE}) {
final double phiby2 = getU(x);
- Assert.assertEquals(PI_4 - DU * PI_4, Math.abs(phiby2), 0.0);
+ Assertions.assertEquals(PI_4 - DU * PI_4, Math.abs(phiby2));
final double a = phiby2 * SpecialMath.tan2(phiby2);
// Check this is not 1
- Assert.assertNotEquals(1, Math.abs(a), 0.0);
- Assert.assertTrue(Math.abs(a) < 1.0);
+ Assertions.assertNotEquals(1, Math.abs(a));
+ Assertions.assertTrue(Math.abs(a) < 1.0);
}
// At pi/4 the function reverts to Math.tan(x) / x. Test through the transition.
final double pi = Math.PI;
for (final double x : new double[] {pi, pi / 2, pi / 3.99, pi / 4, pi / 4.01, pi / 8, pi / 16}) {
final double y = Math.tan(x) / x;
- Assert.assertEquals(y, SpecialMath.tan2(x), Math.ulp(y));
+ Assertions.assertEquals(y, SpecialMath.tan2(x), Math.ulp(y));
}
// Test this closely matches the JDK tan function.
@@ -872,7 +873,7 @@ public class StableSamplerTest {
ulp += u;
// Within 4 ulp. Note tan(x) is within 1 ulp of the result. So this
// is max 5 ulp from the result.
- Assert.assertEquals(tanx, y, 4 * Math.ulp(tanx));
+ Assertions.assertEquals(tanx, y, 4 * Math.ulp(tanx));
}
// Test tan(x) / x
y = tanx / x;
@@ -883,7 +884,7 @@ public class StableSamplerTest {
}
ulp2 += u;
// Within 3 ulp.
- Assert.assertEquals(y, tan2x, 3 * Math.ulp(y));
+ Assertions.assertEquals(y, tan2x, 3 * Math.ulp(y));
}
}
// Mean (max) ULP is very low
@@ -891,17 +892,17 @@ public class StableSamplerTest {
// tan(x) tan(x) / x
// tan4283 93436.25534446817 201185 : 68313.16171793547 128079
// tan4288c 0.5905972588807344 4 : 0.4047176940366626 3
- Assert.assertTrue("Mean ULP to tan(x) is too high", (double) ulp / count < 0.6);
- Assert.assertTrue("Mean ULP to tan(x) / x is too high", (double) ulp2 / count < 0.45);
+ Assertions.assertTrue((double) ulp / count < 0.6, "Mean ULP to tan(x) is too high");
+ Assertions.assertTrue((double) ulp2 / count < 0.45, "Mean ULP to tan(x) / x is too high");
// If the value is under 1 then the sampler will break due to cancellation errors.
- Assert.assertEquals("Must be exact tan(x) / x at x=0", 1.0, SpecialMath.tan2(0.0), 0.0);
- Assert.assertEquals(4 / Math.PI, SpecialMath.tan2(PI_4), Math.ulp(4 / Math.PI));
- Assert.assertEquals(1.0, PI_4 * SpecialMath.tan2(PI_4), Math.ulp(1.0));
+ Assertions.assertEquals(1.0, SpecialMath.tan2(0.0), "Must be exact tan(x) / x at x=0");
+ Assertions.assertEquals(4 / Math.PI, SpecialMath.tan2(PI_4), Math.ulp(4 / Math.PI));
+ Assertions.assertEquals(1.0, PI_4 * SpecialMath.tan2(PI_4), Math.ulp(1.0));
// If this is above 1 then the sampler will break. Test at the switch point pi/4.
- Assert.assertTrue(1.0 >= PI_4 * SpecialMath.tan2(PI_4));
- Assert.assertTrue(1.0 >= PI_4 * SpecialMath.tan2(Math.nextDown(PI_4)));
+ Assertions.assertTrue(1.0 >= PI_4 * SpecialMath.tan2(PI_4));
+ Assertions.assertTrue(1.0 >= PI_4 * SpecialMath.tan2(Math.nextDown(PI_4)));
// Monotonic function at the transition
- Assert.assertTrue(SpecialMath.tan2(Math.nextUp(PI_4)) >= SpecialMath.tan2(PI_4));
+ Assertions.assertTrue(SpecialMath.tan2(Math.nextUp(PI_4)) >= SpecialMath.tan2(PI_4));
}
/**
@@ -925,10 +926,10 @@ public class StableSamplerTest {
for (final double u : us) {
final double x = sampleCMS(alpha, beta, w, u);
final double y = sampleWeronAlphaNot1(alpha, beta, w, u);
- Assert.assertEquals(x, y, Math.max(absolute, Math.abs(x) * relative));
+ Assertions.assertEquals(x, y, Math.max(absolute, Math.abs(x) * relative));
// Test symmetry
final double z = sampleCMS(alpha, -beta, w, 1 - u);
- Assert.assertEquals(x, -z, 0);
+ Assertions.assertEquals(x, -z, 0.0);
}
}
}
@@ -955,10 +956,10 @@ public class StableSamplerTest {
for (final double u : us) {
final double x = sampleCMS(alpha, beta, w, u);
final double y = sampleWeronAlpha1(beta, w, u);
- Assert.assertEquals(x, y, Math.max(absolute, Math.abs(x) * relative));
+ Assertions.assertEquals(x, y, Math.max(absolute, Math.abs(x) * relative));
// Test symmetry
final double z = sampleCMS(alpha, -beta, w, 1 - u);
- Assert.assertEquals(x, -z, 0);
+ Assertions.assertEquals(x, -z, 0.0);
}
}
}
@@ -991,7 +992,7 @@ public class StableSamplerTest {
for (final double u : us) {
// CMS formulas
double x0 = sampleCMS(1, beta, w, u);
- Assert.assertTrue("Target must be finite", Double.isFinite(x0));
+ Assertions.assertTrue(Double.isFinite(x0), "Target must be finite");
// Sample should approach x0 as alpha approaches 1
double delta = deltaStart;
@@ -1007,7 +1008,7 @@ public class StableSamplerTest {
// Weron formulas
x0 = sampleWeronAlpha1(beta, w, u);
- Assert.assertTrue("Target must be finite", Double.isFinite(x0));
+ Assertions.assertTrue(Double.isFinite(x0), "Target must be finite");
// Sample should approach x0 as alpha approaches 1
delta = deltaStart;
@@ -1025,10 +1026,10 @@ public class StableSamplerTest {
}
// The CMS formala monotonically converges
- Assert.assertEquals(0, cmsCount);
+ Assertions.assertEquals(0, cmsCount);
// The weron formula does not monotonically converge
// (difference to the target can be bigger when alpha moves closer to 1).
- Assert.assertTrue(weronCount > 200);
+ Assertions.assertTrue(weronCount > 200);
}
}
@@ -1041,22 +1042,22 @@ public class StableSamplerTest {
@Test
public void testExtremeInputsToSample() {
// Demonstrate instability when w = 0
- Assert.assertEquals(Double.NaN, sampleCMS(1.3, 0.7, 0, 0.25), 0.0);
- Assert.assertTrue(Double.isFinite(sampleCMS(1.3, 0.7, SMALL_W, 0.25)));
+ Assertions.assertEquals(Double.NaN, sampleCMS(1.3, 0.7, 0, 0.25));
+ Assertions.assertTrue(Double.isFinite(sampleCMS(1.3, 0.7, SMALL_W, 0.25)));
// Demonstrate instability when u -> 0 or 1, and |beta| = 1
- Assert.assertEquals(Double.NaN, sampleCMS(1.1, 1.0, 0.1, 0), 0.0);
- Assert.assertTrue(Double.isFinite(sampleCMS(1.1, 1.0, 0.1, DU)));
+ Assertions.assertEquals(Double.NaN, sampleCMS(1.1, 1.0, 0.1, 0));
+ Assertions.assertTrue(Double.isFinite(sampleCMS(1.1, 1.0, 0.1, DU)));
// Demonstrate instability when alpha -> 0
// Small alpha does not tolerate very small w.
- Assert.assertEquals(Double.NaN, sampleCMS(0.01, 0.7, SMALL_W, 0.5), 0.0);
+ Assertions.assertEquals(Double.NaN, sampleCMS(0.01, 0.7, SMALL_W, 0.5));
// Very small alpha does not tolerate u approaching 0 or 1 (depending on the
// skew)
- Assert.assertEquals(Double.NaN, sampleCMS(1e-5, 0.7, 1.0, 1e-4), 0.0);
- Assert.assertEquals(Double.NaN, sampleCMS(1e-5, -0.7, 1.0, 1 - 1e-4), 0.0);
+ Assertions.assertEquals(Double.NaN, sampleCMS(1e-5, 0.7, 1.0, 1e-4));
+ Assertions.assertEquals(Double.NaN, sampleCMS(1e-5, -0.7, 1.0, 1 - 1e-4));
final double[] alphas = {Math.nextDown(2), 1.3, 1.1, Math.nextUp(1), 1, Math.nextDown(1), 0.7, 0.1, 0.05, 0.01, 0x1.0p-16};
final double[] betas = {1, 0.9, 0.001, 0};
@@ -1091,17 +1092,18 @@ public class StableSamplerTest {
nan1++;
}
// The edge-case corrected Weron formula should not fail
- Assert.assertNotEquals(Double.NaN, x2);
+ Assertions.assertNotEquals(Double.NaN, x2);
- // Check symmetry of each formula
- Assert.assertEquals(x1, -sampleCMS(alpha, -beta, w, 1 - u), 0.0);
- Assert.assertEquals(x2, -sampleWeron(alpha, -beta, w, 1 - u), 0.0);
+ // Check symmetry of each formula.
+ // Use a delta of zero to allow equality of 0.0 and -0.0.
+ Assertions.assertEquals(x1, 0.0 - sampleCMS(alpha, -beta, w, 1 - u), 0.0);
+ Assertions.assertEquals(x2, 0.0 - sampleWeron(alpha, -beta, w, 1 - u), 0.0);
if (Double.isInfinite(x1) && x1 != x2) {
// Check the Weron correction for extreme samples.
// The result should be at the correct *finite* support bounds.
// Note: This applies when alpha < 1 and beta = +/-1.
- Assert.assertTrue(lower <= x2 && x2 <= upper);
+ Assertions.assertTrue(lower <= x2 && x2 <= upper);
}
}
}
@@ -1109,7 +1111,7 @@ public class StableSamplerTest {
}
// The CMS algorithm is expected to fail some cases
- Assert.assertNotEquals(0, nan1);
+ Assertions.assertNotEquals(0, nan1);
}
/**
@@ -1355,7 +1357,7 @@ public class StableSamplerTest {
// See testZIsNotAlwaysAboveZero()
final double alpha = 1.291015625;
final double beta = -1;
- Assert.assertTrue(0.0 > computeNumerator(alpha, beta, Long.MAX_VALUE));
+ Assertions.assertTrue(0.0 > computeNumerator(alpha, beta, Long.MAX_VALUE));
// z will be negative. Repeat computation assumed to be performed by the sampler.
// This ensures the test should be updated if the sampler implementation changes.
@@ -1371,11 +1373,11 @@ public class StableSamplerTest {
final double b2 = 1 - db;
final double b2p = 1 + db;
final double z = a2p * (b2 + 2 * phiby2 * bb * tau) / (w * a2 * b2p);
- Assert.assertTrue(0.0 > z);
+ Assertions.assertTrue(0.0 > z);
final StableSampler sampler = StableSampler.of(createRngWithSequence(longs), alpha, beta);
// It should not be NaN or infinite
- Assert.assertTrue("Sampler did not recover", Double.isFinite(sampler.sample()));
+ Assertions.assertTrue(Double.isFinite(sampler.sample()), "Sampler did not recover");
}
/**
@@ -1401,17 +1403,17 @@ public class StableSamplerTest {
final StableSampler sampler = StableSampler.of(createRngWithSequence(longs), alpha, beta);
final double x = sampler.sample();
// It should not be NaN
- Assert.assertFalse("Sampler did not recover", Double.isNaN(x));
+ Assertions.assertFalse(Double.isNaN(x), "Sampler did not recover");
if (beta != 0) {
// The sample is extreme so should be at a limit of the support
if (alpha < 0) {
// Effectively +/- infinity
- Assert.assertEquals(Math.copySign(Double.POSITIVE_INFINITY, beta), x, 0.0);
+ Assertions.assertEquals(Math.copySign(Double.POSITIVE_INFINITY, beta), x);
} else if (alpha > 1) {
// At the distribution mean
final double[] support = getSupport(alpha, beta);
final double mu = support[2];
- Assert.assertEquals(mu, x, 0.0);
+ Assertions.assertEquals(mu, x);
}
}
}
@@ -1475,17 +1477,17 @@ public class StableSamplerTest {
final double x3 = sampler.sample();
// Expect the limit of the support (the direction is controlled by extreme phi)
final double max = Double.POSITIVE_INFINITY;
- Assert.assertEquals(-max, x1, 0.0);
- Assert.assertEquals(max, x2, 0.0);
+ Assertions.assertEquals(-max, x1);
+ Assertions.assertEquals(max, x2);
// Expect the sampler to avoid inf * 0
- Assert.assertNotEquals(Double.NaN, x3, 0.0);
+ Assertions.assertNotEquals(Double.NaN, x3);
// When f=0 the sample should be in the middle (beta=0) or skewed in the direction of beta
if (beta == 0) {
// In the middle
- Assert.assertEquals(0.0, x3, 0.0);
+ Assertions.assertEquals(0.0, x3);
} else {
// At the support limit
- Assert.assertEquals(Math.copySign(max, beta), x3, 0.0);
+ Assertions.assertEquals(Math.copySign(max, beta), x3);
}
}
@@ -1510,7 +1512,7 @@ public class StableSamplerTest {
}, longs1);
final StableSampler sampler1 = StableSampler.of(createRngWithSequence(longs1), 1.0, 1.0);
final double x1 = sampler1.sample();
- Assert.assertTrue("Sampler did not recover", Double.isFinite(x1));
+ Assertions.assertTrue(Double.isFinite(x1), "Sampler did not recover");
// u -> pi/4
final long[] longs2 = {Long.MAX_VALUE, 1446480648965178882L};
@@ -1519,10 +1521,10 @@ public class StableSamplerTest {
}, longs2);
final StableSampler sampler2 = StableSampler.of(createRngWithSequence(longs2), 1.0, -1.0);
final double x2 = sampler2.sample();
- Assert.assertTrue("Sampler did not recover", Double.isFinite(x2));
+ Assertions.assertTrue(Double.isFinite(x2), "Sampler did not recover");
// Sample should be a reflection
- Assert.assertEquals(x1, -x2, 0.0);
+ Assertions.assertEquals(x1, -x2);
}
/**
@@ -1657,7 +1659,7 @@ public class StableSamplerTest {
for (int i = 0; i < 100; i++) {
final double x = sampler.sample();
if (!(lower <= x && x <= upper)) {
- Assert.fail(String.format("Invalid sample. alpha=%s, beta=%s, gamma=%s, delta=%s [%s, %s] x=%s",
+ Assertions.fail(String.format("Invalid sample. alpha=%s, beta=%s, gamma=%s, delta=%s [%s, %s] x=%s",
alpha, beta, gamma, delta, lower, upper, x));
}
}
@@ -1722,27 +1724,27 @@ public class StableSamplerTest {
// Extremes of the uniform deviate generated using the same method as the sampler
final double d = DU * PI_4;
// Test in (-pi/4, pi/4)
- Assert.assertNotEquals(-PI_4, getU(createRngWithSequence(Long.MIN_VALUE)), 0.0);
- Assert.assertEquals(-PI_4 + d, getU(createRngWithSequence(Long.MIN_VALUE + (1 << 10))), 0.0);
- Assert.assertEquals(-PI_4 / 2, getU(createRngWithSequence(Long.MIN_VALUE >> 1)), 0.0);
- Assert.assertEquals(-d, getU(createRngWithSequence(-1)), 0.0);
- Assert.assertEquals(0.0, getU(createRngWithSequence(0)), 0.0);
- Assert.assertEquals(d, getU(createRngWithSequence(1 << 10)), 0.0);
- Assert.assertEquals(PI_4 / 2, getU(createRngWithSequence(Long.MIN_VALUE >>> 1)), 0.0);
- Assert.assertEquals(PI_4 - d, getU(createRngWithSequence(Long.MAX_VALUE)), 0.0);
+ Assertions.assertNotEquals(-PI_4, getU(createRngWithSequence(Long.MIN_VALUE)));
+ Assertions.assertEquals(-PI_4 + d, getU(createRngWithSequence(Long.MIN_VALUE + (1 << 10))));
+ Assertions.assertEquals(-PI_4 / 2, getU(createRngWithSequence(Long.MIN_VALUE >> 1)));
+ Assertions.assertEquals(-d, getU(createRngWithSequence(-1)));
+ Assertions.assertEquals(0.0, getU(createRngWithSequence(0)));
+ Assertions.assertEquals(d, getU(createRngWithSequence(1 << 10)));
+ Assertions.assertEquals(PI_4 / 2, getU(createRngWithSequence(Long.MIN_VALUE >>> 1)));
+ Assertions.assertEquals(PI_4 - d, getU(createRngWithSequence(Long.MAX_VALUE)));
// Extremes of the exponential sampler
- Assert.assertEquals(0, ZigguratSampler.Exponential.of(
+ Assertions.assertEquals(0, ZigguratSampler.Exponential.of(
createRngWithSequence(0L)).sample(), 0.0);
- Assert.assertEquals(SMALL_W, ZigguratSampler.Exponential.of(
+ Assertions.assertEquals(SMALL_W, ZigguratSampler.Exponential.of(
createRngWithSequence(1)).sample(), 0.0);
- Assert.assertEquals(1.0, ZigguratSampler.Exponential.of(
+ Assertions.assertEquals(1.0, ZigguratSampler.Exponential.of(
createRngWithSequence(1446480648965178882L)).sample(), 0.0);
- Assert.assertEquals(5.0, ZigguratSampler.Exponential.of(
+ Assertions.assertEquals(5.0, ZigguratSampler.Exponential.of(
createRngWithSequence(6092639261715210240L)).sample(), 0.0);
- Assert.assertEquals(TAIL_W, ZigguratSampler.Exponential.of(
+ Assertions.assertEquals(TAIL_W, ZigguratSampler.Exponential.of(
createRngWithSequence(-1, -1, 0)).sample(), 0.0);
- Assert.assertEquals(3 * TAIL_W, ZigguratSampler.Exponential.of(
+ Assertions.assertEquals(3 * TAIL_W, ZigguratSampler.Exponential.of(
createRngWithSequence(-1, -1, -1, -1, -1, -1, 0)).sample(), 1e-14);
}
@@ -1893,10 +1895,10 @@ public class StableSamplerTest {
// Validate series
final SharedStateContinuousSampler exp = ZigguratSampler.Exponential.of(rng);
for (int i = 0; i < expected.length; i += 2) {
- int j = i / 2;
- Assert.assertEquals(j + ": Incorrect u", expected[i], getU(rng), 0.0);
+ final int j = i / 2;
+ Assertions.assertEquals(expected[i], getU(rng), () -> j + ": Incorrect u");
if (i + 1 < expected.length) {
- Assert.assertEquals(j + ": Incorrect w", expected[i + 1], exp.sample(), 0.0);
+ Assertions.assertEquals(expected[i + 1], exp.sample(), () -> j + ": Incorrect w");
}
}
}
@@ -1962,7 +1964,7 @@ public class StableSamplerTest {
final StableSampler sampler1 = StableSampler.of(rng1, alpha1, beta1);
final StableSampler sampler2 = StableSampler.of(rng2, alpha2, beta2);
final StableSampler sampler3 = StableSampler.of(rng3, alpha3, beta3);
- final String msg = String.format("alpha=%s, beta=%s", alpha2, beta2);
+ final Supplier<String> msg = () -> String.format("alpha=%s, beta=%s", alpha2, beta2);
for (int i = 0; i < 1000; i++) {
final double x1 = sampler1.sample();
final double x2 = sampler2.sample();
@@ -1971,16 +1973,16 @@ public class StableSamplerTest {
if (x3 > x1) {
if (x2 > x3) {
// Should be the same
- Assert.assertEquals(msg, x3, x2, ulp * Math.ulp(x3));
+ Assertions.assertEquals(x3, x2, ulp * Math.ulp(x3), msg);
} else if (x2 < x1) {
- Assert.assertEquals(msg, x1, x2, ulp * Math.ulp(x1));
+ Assertions.assertEquals(x1, x2, ulp * Math.ulp(x1), msg);
}
} else if (x3 < x1) {
if (x2 < x3) {
// Should be the same
- Assert.assertEquals(msg, x3, x2, ulp * Math.ulp(x3));
+ Assertions.assertEquals(x3, x2, ulp * Math.ulp(x3), msg);
} else if (x2 > x1) {
- Assert.assertEquals(msg, x1, x2, ulp * Math.ulp(x1));
+ Assertions.assertEquals(x1, x2, ulp * Math.ulp(x1), msg);
}
}
}
@@ -2095,7 +2097,7 @@ public class StableSamplerTest {
for (int i = 0; i < 10; i++) {
final double x1 = sampler1.sample();
final double x2 = sampler2.sample();
- Assert.assertEquals(x1, x2, ulp * Math.ulp(x1));
+ Assertions.assertEquals(x1, x2, ulp * Math.ulp(x1));
}
}
}
@@ -2193,7 +2195,7 @@ public class StableSamplerTest {
// Since mirroring applies before the shift of delta this must be negated too
final StableSampler s2 = StableSampler.of(reverse, alpha, -beta, gamma, -delta);
for (int i = 0; i < 100; i++) {
- Assert.assertEquals(s1.sample(), -s2.sample(), 0.0);
+ Assertions.assertEquals(s1.sample(), -s2.sample());
}
}
}
@@ -2217,7 +2219,7 @@ public class StableSamplerTest {
// Since mirroring applies before the shift of delta this must be negated too
final StableSampler s2 = StableSampler.of(rng2, alpha, -beta, gamma, -delta);
for (int i = 0; i < 100; i++) {
- Assert.assertEquals(s1.sample(), -s2.sample(), 0.0);
+ Assertions.assertEquals(s1.sample(), -s2.sample());
}
}
}
@@ -2247,7 +2249,7 @@ public class StableSamplerTest {
sampler = StableSampler.of(rng, p[0], p[1], p[2], p[3]);
}
final String s = sampler.toString().toLowerCase();
- Assert.assertTrue(s.contains("stable"));
+ Assertions.assertTrue(s.contains("stable"));
}
}
@@ -2272,16 +2274,16 @@ public class StableSamplerTest {
final double hi = getU(Long.MAX_VALUE & unsetHighBit);
final double lo = getU(Long.MIN_VALUE | setLowBit);
// The limits are roughly pi/4 and -pi/4
- Assert.assertEquals(PI_4, hi, 2e-3);
- Assert.assertEquals(-PI_4, lo, 2e-3);
- Assert.assertEquals(0.0, lo + hi, 1e-3);
+ Assertions.assertEquals(PI_4, hi, 2e-3);
+ Assertions.assertEquals(-PI_4, lo, 2e-3);
+ Assertions.assertEquals(0.0, lo + hi, 1e-3);
// Setting a bit ensure the exponential sampler cannot be zero
final UniformRandomProvider rng = createRngWithSequence(setLowBit);
final double w = ZigguratSampler.Exponential.of(rng).sample();
- Assert.assertNotEquals(0.0, w, 0.0);
+ Assertions.assertNotEquals(0.0, w);
// This is the actual value; it is small but not extreme.
- Assert.assertEquals(0.007391869818503967, w, 0.0);
+ Assertions.assertEquals(0.007391869818503967, w);
final RandomSource source = RandomSource.XO_RO_SHI_RO_128_SS;
final long seed = 0x83762b3daf1c43L;
@@ -2311,7 +2313,7 @@ public class StableSamplerTest {
for (final double alpha : alphas) {
for (final double beta : betas) {
- final String msg = String.format("alpha=%s, beta=%s", alpha, beta);
+ final Supplier<String> msg = () -> String.format("alpha=%s, beta=%s", alpha, beta);
// WARNING:
// Created by direct access to package-private constructor.
// This is for testing only as these do not validate the parameters.
@@ -2327,7 +2329,7 @@ public class StableSamplerTest {
for (int i = 0; i < 1000; i++) {
final double x = s1.sample();
final double y = s2.sample();
- Assert.assertEquals(msg, x, y, Math.max(absolute, Math.abs(x) * relative));
+ Assertions.assertEquals(x, y, Math.max(absolute, Math.abs(x) * relative), msg);
}
}
}
@@ -2418,14 +2420,14 @@ public class StableSamplerTest {
}, longs);
final double zeta = -beta * Math.tan(alpha * PI_2);
- Assert.assertEquals(0.0, alpha * PI_4 + Math.atan(-zeta), 0.0);
+ Assertions.assertEquals(0.0, alpha * PI_4 + Math.atan(-zeta));
final UniformRandomProvider rng = createRngWithSequence(longs);
final StableSampler sampler = new WeronStableSampler(rng, alpha, beta);
// zeta is the offset used to shift the 1-parameterization to the
// 0-parameterization. This is returned when other terms multiply to zero.
- Assert.assertEquals(zeta, sampler.sample(), 0.0);
- Assert.assertEquals(zeta, sampler.sample(), 0.0);
- Assert.assertEquals(zeta, sampler.sample(), 0.0);
+ Assertions.assertEquals(zeta, sampler.sample());
+ Assertions.assertEquals(zeta, sampler.sample());
+ Assertions.assertEquals(zeta, sampler.sample());
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/UniformLongSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/UniformLongSamplerTest.java
index 00f6ddd..f55aeb6 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/UniformLongSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/UniformLongSamplerTest.java
@@ -21,7 +21,7 @@ import org.apache.commons.rng.core.source64.LongProvider;
import org.apache.commons.rng.core.source64.SplitMix64;
import org.apache.commons.rng.sampling.RandomAssert;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import java.util.Locale;
@@ -57,7 +57,7 @@ public class UniformLongSamplerTest {
final UniformRandomProvider rng = RandomSource.SPLIT_MIX_64.create();
final UniformLongSampler sampler = UniformLongSampler.of(rng, lower, upper);
for (int i = 0; i < 5; i++) {
- Assert.assertEquals(lower, sampler.sample());
+ Assertions.assertEquals(lower, sampler.sample());
}
}
@@ -73,7 +73,7 @@ public class UniformLongSamplerTest {
final UniformRandomProvider rng2 = RandomSource.SPLIT_MIX_64.create(0L);
final UniformLongSampler sampler = UniformLongSampler.of(rng2, lower, upper);
for (int i = 0; i < 10; i++) {
- Assert.assertEquals(rng1.nextLong(), sampler.sample());
+ Assertions.assertEquals(rng1.nextLong(), sampler.sample());
}
}
@@ -93,7 +93,7 @@ public class UniformLongSamplerTest {
final UniformRandomProvider rng2 = createRngWithFullBitsOnFirstCall();
final UniformLongSampler sampler = UniformLongSampler.of(rng2, lower, upper);
for (int i = 0; i < 10; i++) {
- Assert.assertEquals(lower + rng1.nextLong(n), sampler.sample());
+ Assertions.assertEquals(lower + rng1.nextLong(n), sampler.sample());
}
}
}
@@ -143,9 +143,9 @@ public class UniformLongSamplerTest {
final long range = 1L << i;
final long upper = lower + range - 1;
sampler = UniformLongSampler.of(rngZeroBits, lower, upper);
- Assert.assertEquals("Zero bits sample", lower, sampler.sample());
+ Assertions.assertEquals(lower, sampler.sample(), "Zero bits sample");
sampler = UniformLongSampler.of(rngAllBits, lower, upper);
- Assert.assertEquals("All bits sample", upper, sampler.sample());
+ Assertions.assertEquals(upper, sampler.sample(), "All bits sample");
}
}
@@ -166,7 +166,7 @@ public class UniformLongSamplerTest {
final UniformRandomProvider rng2 = RandomSource.SPLIT_MIX_64.create(0L);
sampler = UniformLongSampler.of(rng2, lower, upper);
for (int j = 0; j < 10; j++) {
- Assert.assertEquals(rng1.nextLong() >>> shift, sampler.sample());
+ Assertions.assertEquals(rng1.nextLong() >>> shift, sampler.sample());
}
}
}
@@ -189,7 +189,7 @@ public class UniformLongSamplerTest {
do {
expected = rng1.nextLong();
} while (expected < lower || expected > upper);
- Assert.assertEquals(expected, sampler.sample());
+ Assertions.assertEquals(expected, sampler.sample());
}
}
@@ -225,8 +225,8 @@ public class UniformLongSamplerTest {
final long sample1 = sampler.sample();
final long sample2 = samplerLo.sample();
final long sample3 = samplerHi.sample();
- Assert.assertEquals("Incorrect negative offset sample", sample1 + offsetLo, sample2);
- Assert.assertEquals("Incorrect positive offset sample", sample1 + offsetHi, sample3);
+ Assertions.assertEquals(sample1 + offsetLo, sample2, "Incorrect negative offset sample");
+ Assertions.assertEquals(sample1 + offsetHi, sample3, "Incorrect positive offset sample");
}
}
@@ -264,7 +264,7 @@ public class UniformLongSamplerTest {
// This should be even across the entire range
for (int value : histogram) {
- Assert.assertEquals(expected, value);
+ Assertions.assertEquals(expected, value);
}
}
@@ -336,6 +336,6 @@ public class UniformLongSamplerTest {
private static void assertToString(long lower, long upper) {
final UniformRandomProvider rng = RandomSource.SPLIT_MIX_64.create(0L);
final UniformLongSampler sampler = UniformLongSampler.of(rng, lower, upper);
- Assert.assertTrue(sampler.toString().toLowerCase(Locale.US).contains("uniform"));
+ Assertions.assertTrue(sampler.toString().toLowerCase(Locale.US).contains("uniform"));
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ZigguratSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ZigguratSamplerTest.java
index 4ac616e..2ad0a24 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ZigguratSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ZigguratSamplerTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.sampling.distribution;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import java.util.Arrays;
import org.apache.commons.math3.distribution.AbstractRealDistribution;
@@ -97,8 +97,8 @@ public class ZigguratSamplerTest {
// and leave it to a seeded RNG to select different layers.
// A value of zero will create a sample of zero (42 is the seed)
- Assert.assertEquals(0.0, expSample(42, 0), 0.0);
- Assert.assertEquals(tailValue, expSample(42, -1, -1, 0), 0.0);
+ Assertions.assertEquals(0.0, expSample(42, 0));
+ Assertions.assertEquals(tailValue, expSample(42, -1, -1, 0));
// Use different seeds to test different layers from the edge of the ziggurat.
for (final long seed : new long[] {42, -2136612838, 2340923842L, -1263746817818681L}) {
@@ -109,11 +109,11 @@ public class ZigguratSamplerTest {
// Recursion
// Note the order of additions is important as the final sample is added to the
// tail value multiple times.
- Assert.assertEquals(x0 + tailValue, expSample(seed, -1, -1), 0.0);
- Assert.assertEquals(x1 + tailValue, expSample(seed, -1, -1, -1), 0.0);
+ Assertions.assertEquals(x0 + tailValue, expSample(seed, -1, -1));
+ Assertions.assertEquals(x1 + tailValue, expSample(seed, -1, -1, -1));
// Double recursion
- Assert.assertEquals(x0 + tailValue + tailValue, expSample(seed, -1, -1, -1, -1), 0.0);
- Assert.assertEquals(x1 + tailValue + tailValue, expSample(seed, -1, -1, -1, -1, -1), 0.0);
+ Assertions.assertEquals(x0 + tailValue + tailValue, expSample(seed, -1, -1, -1, -1));
+ Assertions.assertEquals(x1 + tailValue + tailValue, expSample(seed, -1, -1, -1, -1, -1));
}
}
@@ -244,9 +244,10 @@ public class ZigguratSamplerTest {
final ChiSquareTest chiSquareTest = new ChiSquareTest();
// Pass if we cannot reject null hypothesis that the distributions are the same.
- double chi2 = chiSquareTest.chiSquareTest(expected, observed);
- Assert.assertFalse(String.format("(%s <= x < %s) Chi-square p-value = %s",
- lowerBound, values[bins - 1], chi2), chi2 < 0.001);
+ final double chi2 = chiSquareTest.chiSquareTest(expected, observed);
+ Assertions.assertFalse(chi2 < 0.001,
+ () -> String.format("(%s <= x < %s) Chi-square p-value = %s",
+ lowerBound, values[bins - 1], chi2));
// Test bins sampled from the edge of the ziggurat. This is always around zero.
for (final double range : new double[] {0.5, 0.25, 0.1, 0.05}) {
@@ -254,10 +255,10 @@ public class ZigguratSamplerTest {
final int max = findIndex(values, range);
final long[] observed2 = Arrays.copyOfRange(observed, min, max + 1);
final double[] expected2 = Arrays.copyOfRange(expected, min, max + 1);
- chi2 = chiSquareTest.chiSquareTest(expected2, observed2);
- Assert.assertFalse(String.format("(%s <= x < %s) Chi-square p-value = %s",
- min == 0 ? lowerBound : values[min - 1], values[max], chi2),
- chi2 < significanceLevel);
+ final double chi2b = chiSquareTest.chiSquareTest(expected2, observed2);
+ Assertions.assertFalse(chi2b < significanceLevel,
+ () -> String.format("(%s <= x < %s) Chi-square p-value = %s",
+ min == 0 ? lowerBound : values[min - 1], values[max], chi2b));
}
}
@@ -293,9 +294,9 @@ public class ZigguratSamplerTest {
}
}
// Verify the index is correct
- Assert.assertTrue(x < data[low]);
+ Assertions.assertTrue(x < data[low]);
if (low != 0) {
- Assert.assertTrue(x >= data[low - 1]);
+ Assertions.assertTrue(x >= data[low - 1]);
}
return low;
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/BoxSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/BoxSamplerTest.java
index c841d55..89fa197 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/BoxSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/BoxSamplerTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.rng.sampling.shape;
import java.util.Arrays;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.apache.commons.math3.stat.inference.ChiSquareTest;
@@ -55,7 +55,7 @@ public class BoxSamplerTest {
}) {
try {
BoxSampler.of(rng, c[0], c[1]);
- Assert.fail(String.format("Did not detect dimension mismatch: %d,%d",
+ Assertions.fail(String.format("Did not detect dimension mismatch: %d,%d",
c[0].length, c[1].length));
} catch (IllegalArgumentException ex) {
// Expected
@@ -73,7 +73,7 @@ public class BoxSamplerTest {
final double[][] c = new double[][] {
{0, 1, 2}, {-1, 2, 3}
};
- Assert.assertNotNull(BoxSampler.of(rng, c[0], c[1]));
+ Assertions.assertNotNull(BoxSampler.of(rng, c[0], c[1]));
final double[] bad = {Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN};
for (int i = 0; i < c.length; i++) {
for (int j = 0; j < c[0].length; j++) {
@@ -82,7 +82,7 @@ public class BoxSamplerTest {
c[i][j] = d;
try {
BoxSampler.of(rng, c[0], c[1]);
- Assert.fail(String.format("Did not detect non-finite coordinate: %d,%d = %s", i, j, d));
+ Assertions.fail(String.format("Did not detect non-finite coordinate: %d,%d = %s", i, j, d));
} catch (IllegalArgumentException ex) {
// Expected
}
@@ -142,8 +142,8 @@ public class BoxSamplerTest {
}
}
// Show the box is too big to compute vectors between points.
- Assert.assertEquals("Expect vector b - a to be infinite in the x dimension",
- Double.POSITIVE_INFINITY, c2[1][0] - c2[0][0], 0.0);
+ Assertions.assertEquals(Double.POSITIVE_INFINITY, c2[1][0] - c2[0][0],
+ "Expect vector b - a to be infinite in the x dimension");
final BoxSampler sampler1 = BoxSampler.of(
RandomSource.XO_RO_SHI_RO_128_PP.create(seed), c1[0], c1[1]);
@@ -156,7 +156,7 @@ public class BoxSamplerTest {
for (int i = 0; i < a.length; i++) {
a[i] *= scale;
}
- Assert.assertArrayEquals(a, b, 0.0);
+ Assertions.assertArrayEquals(a, b);
}
}
@@ -227,11 +227,11 @@ public class BoxSamplerTest {
final long[] observed = new long[expected.length];
for (int i = 0; i < samples; i++) {
final double[] x = sampler.sample();
- Assert.assertEquals(dimension, x.length);
+ Assertions.assertEquals(dimension, x.length);
int index = 0;
for (int j = 0; j < dimension; j++) {
final double c = (x[j] - a[j]) * scale[j];
- Assert.assertTrue("Not within the box", c >= 0.0 && c <= 1.0);
+ Assertions.assertTrue(c >= 0.0 && c <= 1.0, "Not within the box");
// Get the bin for this dimension (assumes c != 1.0)
final int bin = (int) (c * bins);
// Add to the final bin index
@@ -241,7 +241,7 @@ public class BoxSamplerTest {
observed[index]++;
}
final double p = new ChiSquareTest().chiSquareTest(expected, observed);
- Assert.assertFalse("p-value too small: " + p, p < 0.001);
+ Assertions.assertFalse(p < 0.001, () -> "p-value too small: " + p);
}
}
@@ -330,11 +330,11 @@ public class BoxSamplerTest {
for (int n = 0; n < 3; n++) {
final double[] s1 = sampler1.sample();
final double[] s2 = sampler2.sample();
- Assert.assertEquals(s1.length, s2.length);
- Assert.assertFalse("First sampler has used the vertices by reference",
- Arrays.equals(s1, s2));
+ Assertions.assertEquals(s1.length, s2.length);
+ Assertions.assertFalse(Arrays.equals(s1, s2),
+ "First sampler has used the vertices by reference");
for (int i = 0; i < dimension; i++) {
- Assert.assertEquals(s1[i] + offset, s2[i], 1e-10);
+ Assertions.assertEquals(s1[i] + offset, s2[i], 1e-10);
}
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/CoordinatesTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/CoordinatesTest.java
index cbfc336..941b58f 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/CoordinatesTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/CoordinatesTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.sampling.shape;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -30,7 +30,7 @@ public class CoordinatesTest {
public void testRequireFiniteWithMessageThrows() {
final double[] c = {0, 1, 2};
final String message = "This should be prepended";
- Assert.assertSame(c, Coordinates.requireFinite(c, message));
+ Assertions.assertSame(c, Coordinates.requireFinite(c, message));
final double[] bad = {Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN};
for (int i = 0; i < c.length; i++) {
for (final double d : bad) {
@@ -38,9 +38,9 @@ public class CoordinatesTest {
c[i] = d;
try {
Coordinates.requireFinite(c, message);
- Assert.fail(String.format("Did not detect non-finite coordinate: %d = %s", i, d));
+ Assertions.fail(String.format("Did not detect non-finite coordinate: %d = %s", i, d));
} catch (IllegalArgumentException ex) {
- Assert.assertTrue("Missing message prefix", ex.getMessage().startsWith(message));
+ Assertions.assertTrue(ex.getMessage().startsWith(message), "Missing message prefix");
}
c[i] = value;
}
@@ -55,18 +55,18 @@ public class CoordinatesTest {
final String message = "This should be prepended";
for (final double[] c : new double[][] {{0, 1}, {0, 1, 2}}) {
final int length = c.length;
- Assert.assertSame(c, Coordinates.requireLength(c, length, message));
+ Assertions.assertSame(c, Coordinates.requireLength(c, length, message));
try {
Coordinates.requireLength(c, length - 1, message);
- Assert.fail("Did not detect length was too long: " + (length - 1));
+ Assertions.fail("Did not detect length was too long: " + (length - 1));
} catch (IllegalArgumentException ex) {
- Assert.assertTrue("Missing message prefix", ex.getMessage().startsWith(message));
+ Assertions.assertTrue(ex.getMessage().startsWith(message), "Missing message prefix");
}
try {
Coordinates.requireLength(c, length + 1, message);
- Assert.fail("Did not detect length was too short: " + (length + 1));
+ Assertions.fail("Did not detect length was too short: " + (length + 1));
} catch (IllegalArgumentException ex) {
- Assert.assertTrue("Missing message prefix", ex.getMessage().startsWith(message));
+ Assertions.assertTrue(ex.getMessage().startsWith(message), "Missing message prefix");
}
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/LineSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/LineSamplerTest.java
index ef3e802..b30a734 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/LineSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/LineSamplerTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.rng.sampling.shape;
import java.util.Arrays;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.apache.commons.math3.stat.inference.ChiSquareTest;
@@ -55,7 +55,7 @@ public class LineSamplerTest {
}) {
try {
LineSampler.of(rng, c[0], c[1]);
- Assert.fail(String.format("Did not detect dimension mismatch: %d,%d",
+ Assertions.fail(String.format("Did not detect dimension mismatch: %d,%d",
c[0].length, c[1].length));
} catch (IllegalArgumentException ex) {
// Expected
@@ -73,7 +73,7 @@ public class LineSamplerTest {
final double[][] c = new double[][] {
{0, 1, 2}, {-1, 2, 3}
};
- Assert.assertNotNull(LineSampler.of(rng, c[0], c[1]));
+ Assertions.assertNotNull(LineSampler.of(rng, c[0], c[1]));
final double[] bad = {Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN};
for (int i = 0; i < c.length; i++) {
for (int j = 0; j < c[0].length; j++) {
@@ -82,7 +82,7 @@ public class LineSamplerTest {
c[i][j] = d;
try {
LineSampler.of(rng, c[0], c[1]);
- Assert.fail(String.format("Did not detect non-finite coordinate: %d,%d = %s",
+ Assertions.fail(String.format("Did not detect non-finite coordinate: %d,%d = %s",
i, j, d));
} catch (IllegalArgumentException ex) {
// Expected
@@ -152,8 +152,8 @@ public class LineSamplerTest {
}
}
// Show the line is too big to compute vectors between points.
- Assert.assertEquals("Expect vector b - a to be infinite in the x dimension",
- Double.POSITIVE_INFINITY, c2[1][0] - c2[0][0], 0.0);
+ Assertions.assertEquals(Double.POSITIVE_INFINITY, c2[1][0] - c2[0][0],
+ "Expect vector b - a to be infinite in the x dimension");
final LineSampler sampler1 = LineSampler.of(
RandomSource.XO_RO_SHI_RO_128_PP.create(seed), c1[0], c1[1]);
@@ -166,7 +166,7 @@ public class LineSamplerTest {
for (int i = 0; i < a.length; i++) {
a[i] *= scale;
}
- Assert.assertArrayEquals(a, b, 0.0);
+ Assertions.assertArrayEquals(a, b);
}
}
@@ -250,17 +250,17 @@ public class LineSamplerTest {
final long[] observed = new long[expected.length];
for (int i = 0; i < samples; i++) {
final double[] x = sampler.sample();
- Assert.assertEquals(dimension, x.length);
+ Assertions.assertEquals(dimension, x.length);
final double c = (x[0] - a[0]) * scale[0];
- Assert.assertTrue("Not uniformly distributed", c >= 0.0 && c <= 1.0);
+ Assertions.assertTrue(c >= 0.0 && c <= 1.0, "Not uniformly distributed");
for (int j = 1; j < dimension; j++) {
- Assert.assertEquals("Not on the line", c, (x[j] - a[j]) * scale[j], 1e-14);
+ Assertions.assertEquals(c, (x[j] - a[j]) * scale[j], 1e-14, "Not on the line");
}
// Assign the uniform deviate to a bin. Assumes c != 1.0.
observed[(int) (c * bins)]++;
}
final double p = new ChiSquareTest().chiSquareTest(expected, observed);
- Assert.assertFalse("p-value too small: " + p, p < 0.001);
+ Assertions.assertFalse(p < 0.001, () -> "p-value too small: " + p);
}
}
@@ -365,11 +365,11 @@ public class LineSamplerTest {
for (int n = 0; n < 3; n++) {
final double[] s1 = sampler1.sample();
final double[] s2 = sampler2.sample();
- Assert.assertEquals(s1.length, s2.length);
- Assert.assertFalse("First sampler has used the vertices by reference",
- Arrays.equals(s1, s2));
+ Assertions.assertEquals(s1.length, s2.length);
+ Assertions.assertFalse(Arrays.equals(s1, s2),
+ "First sampler has used the vertices by reference");
for (int i = 0; i < dimension; i++) {
- Assert.assertEquals(s1[i] + offset, s2[i], 1e-10);
+ Assertions.assertEquals(s1[i] + offset, s2[i], 1e-10);
}
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/TetrahedronSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/TetrahedronSamplerTest.java
index ab4dec2..37b2280 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/TetrahedronSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/TetrahedronSamplerTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.rng.sampling.shape;
import java.util.Arrays;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.apache.commons.math3.stat.inference.ChiSquareTest;
@@ -44,7 +44,7 @@ public class TetrahedronSamplerTest {
c[i] = bad;
try {
TetrahedronSampler.of(rng, c[0], c[1], c[2], c[3]);
- Assert.fail(String.format("Did not detect invalid dimension for vertex: %d", i));
+ Assertions.fail(String.format("Did not detect invalid dimension for vertex: %d", i));
} catch (IllegalArgumentException ex) {
// Expected
}
@@ -62,7 +62,7 @@ public class TetrahedronSamplerTest {
final double[][] c = new double[][] {
{1, 1, 1}, {1, -1, 1}, {-1, 1, 1}, {1, 1, -1}
};
- Assert.assertNotNull(TetrahedronSampler.of(rng, c[0], c[1], c[2], c[3]));
+ Assertions.assertNotNull(TetrahedronSampler.of(rng, c[0], c[1], c[2], c[3]));
final double[] bad = {Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN};
for (int i = 0; i < c.length; i++) {
for (int j = 0; j < c[0].length; j++) {
@@ -71,7 +71,7 @@ public class TetrahedronSamplerTest {
c[i][j] = d;
try {
TetrahedronSampler.of(rng, c[0], c[1], c[2], c[3]);
- Assert.fail(String.format("Did not detect non-finite coordinate: %d,%d = %s", i, j, d));
+ Assertions.fail(String.format("Did not detect non-finite coordinate: %d,%d = %s", i, j, d));
} catch (IllegalArgumentException ex) {
// Expected
}
@@ -103,12 +103,12 @@ public class TetrahedronSamplerTest {
}
}
// Show the tetrahedron is too big to compute vectors between points.
- Assert.assertEquals("Expect vector c - a to be infinite in the x dimension",
- Double.NEGATIVE_INFINITY, c2[2][0] - c2[0][0], 0.0);
- Assert.assertEquals("Expect vector c - d to be infinite in the y dimension",
- Double.NEGATIVE_INFINITY, c2[2][1] - c2[3][1], 0.0);
- Assert.assertEquals("Expect vector c - b to be infinite in the z dimension",
- Double.POSITIVE_INFINITY, c2[2][2] - c2[1][2], 0.0);
+ Assertions.assertEquals(Double.NEGATIVE_INFINITY, c2[2][0] - c2[0][0],
+ "Expect vector c - a to be infinite in the x dimension");
+ Assertions.assertEquals(Double.NEGATIVE_INFINITY, c2[2][1] - c2[3][1],
+ "Expect vector c - d to be infinite in the y dimension");
+ Assertions.assertEquals(Double.POSITIVE_INFINITY, c2[2][2] - c2[1][2],
+ "Expect vector c - b to be infinite in the z dimension");
final TetrahedronSampler sampler1 = TetrahedronSampler.of(
RandomSource.XO_RO_SHI_RO_128_PP.create(seed), c1[0], c1[1], c1[2], c1[3]);
@@ -121,7 +121,7 @@ public class TetrahedronSamplerTest {
for (int i = 0; i < a.length; i++) {
a[i] *= scale;
}
- Assert.assertArrayEquals(a, b, 0.0);
+ Assertions.assertArrayEquals(a, b);
}
}
@@ -202,7 +202,7 @@ public class TetrahedronSamplerTest {
}
}
final double p = new ChiSquareTest().chiSquareTest(expected, observed);
- Assert.assertFalse("p-value too small: " + p, p < 0.001);
+ Assertions.assertFalse(p < 0.001, () -> "p-value too small: " + p);
}
}
@@ -232,9 +232,9 @@ public class TetrahedronSamplerTest {
double lx, double ly, double lz,
double sx, double sy, double sz,
Tetrahedron tetrahedron) {
- Assert.assertEquals(3, v.length);
+ Assertions.assertEquals(3, v.length);
// Test the point is inside the correct tetrahedron
- Assert.assertTrue("Not inside the tetrahedron", tetrahedron.contains(v));
+ Assertions.assertTrue(tetrahedron.contains(v), "Not inside the tetrahedron");
final double x = v[0];
final double y = v[1];
final double z = v[2];
@@ -288,10 +288,10 @@ public class TetrahedronSamplerTest {
for (int n = 0; n < 5; n++) {
final double[] s1 = sampler1.sample();
final double[] s2 = sampler2.sample();
- Assert.assertEquals(3, s1.length);
- Assert.assertEquals(3, s2.length);
+ Assertions.assertEquals(3, s1.length);
+ Assertions.assertEquals(3, s2.length);
for (int i = 0; i < 3; i++) {
- Assert.assertEquals(s1[i] + offset, s2[i], 1e-10);
+ Assertions.assertEquals(s1[i] + offset, s2[i], 1e-10);
}
}
}
@@ -309,36 +309,36 @@ public class TetrahedronSamplerTest {
final double epsilon = 1e-14;
// Vertices
for (int i = 0; i < 4; i++) {
- Assert.assertTrue(tetrahedron.contains(c1[i], epsilon));
+ Assertions.assertTrue(tetrahedron.contains(c1[i], epsilon));
}
// Edge
- Assert.assertTrue(tetrahedron.contains(new double[] {1, 0, 0}, epsilon));
- Assert.assertTrue(tetrahedron.contains(new double[] {0.5, 0.5, 1}, epsilon));
+ Assertions.assertTrue(tetrahedron.contains(new double[] {1, 0, 0}, epsilon));
+ Assertions.assertTrue(tetrahedron.contains(new double[] {0.5, 0.5, 1}, epsilon));
// Just inside the edge
- Assert.assertTrue(tetrahedron.contains(new double[] {1 - 1e-10, 0, 0}));
- Assert.assertTrue(tetrahedron.contains(new double[] {0.5, 0.5, 1 - 1e-10}));
+ Assertions.assertTrue(tetrahedron.contains(new double[] {1 - 1e-10, 0, 0}));
+ Assertions.assertTrue(tetrahedron.contains(new double[] {0.5, 0.5, 1 - 1e-10}));
// Just outside the edge
- Assert.assertFalse(tetrahedron.contains(new double[] {1, 0, 1e-10}, epsilon));
- Assert.assertFalse(tetrahedron.contains(new double[] {0.5, 0.5 + 1e-10, 1}, epsilon));
+ Assertions.assertFalse(tetrahedron.contains(new double[] {1, 0, 1e-10}, epsilon));
+ Assertions.assertFalse(tetrahedron.contains(new double[] {0.5, 0.5 + 1e-10, 1}, epsilon));
// Face
double x = 1.0 / 3;
- Assert.assertTrue(tetrahedron.contains(new double[] {x, -x, x}, epsilon));
- Assert.assertTrue(tetrahedron.contains(new double[] {-x, -x, -x}, epsilon));
- Assert.assertTrue(tetrahedron.contains(new double[] {x, x, -x}, epsilon));
- Assert.assertTrue(tetrahedron.contains(new double[] {-x, x, x}, epsilon));
+ Assertions.assertTrue(tetrahedron.contains(new double[] {x, -x, x}, epsilon));
+ Assertions.assertTrue(tetrahedron.contains(new double[] {-x, -x, -x}, epsilon));
+ Assertions.assertTrue(tetrahedron.contains(new double[] {x, x, -x}, epsilon));
+ Assertions.assertTrue(tetrahedron.contains(new double[] {-x, x, x}, epsilon));
// Just outside the face
x += 1e-10;
- Assert.assertFalse(tetrahedron.contains(new double[] {x, -x, x}, epsilon));
- Assert.assertFalse(tetrahedron.contains(new double[] {-x, -x, -x}, epsilon));
- Assert.assertFalse(tetrahedron.contains(new double[] {x, x, -x}, epsilon));
- Assert.assertFalse(tetrahedron.contains(new double[] {-x, x, x}, epsilon));
+ Assertions.assertFalse(tetrahedron.contains(new double[] {x, -x, x}, epsilon));
+ Assertions.assertFalse(tetrahedron.contains(new double[] {-x, -x, -x}, epsilon));
+ Assertions.assertFalse(tetrahedron.contains(new double[] {x, x, -x}, epsilon));
+ Assertions.assertFalse(tetrahedron.contains(new double[] {-x, x, x}, epsilon));
// Inside
- Assert.assertTrue(tetrahedron.contains(new double[] {0, 0, 0}));
- Assert.assertTrue(tetrahedron.contains(new double[] {0.5, 0.25, -0.1}));
+ Assertions.assertTrue(tetrahedron.contains(new double[] {0, 0, 0}));
+ Assertions.assertTrue(tetrahedron.contains(new double[] {0.5, 0.25, -0.1}));
// Outside
- Assert.assertFalse(tetrahedron.contains(new double[] {0, 20, 0}));
- Assert.assertFalse(tetrahedron.contains(new double[] {-20, 0, 0}));
- Assert.assertFalse(tetrahedron.contains(new double[] {6, 6, 4}));
+ Assertions.assertFalse(tetrahedron.contains(new double[] {0, 20, 0}));
+ Assertions.assertFalse(tetrahedron.contains(new double[] {-20, 0, 0}));
+ Assertions.assertFalse(tetrahedron.contains(new double[] {6, 6, 4}));
}
/**
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/TriangleSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/TriangleSamplerTest.java
index fadb3c5..5f51c02 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/TriangleSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/TriangleSamplerTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.rng.sampling.shape;
import java.util.Arrays;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.apache.commons.math3.stat.inference.ChiSquareTest;
@@ -73,18 +73,18 @@ public class TriangleSamplerTest {
// Test that (1 - (1-s) - (1-t)) is not equal to (s + t - 1).
// This is due to the rounding to store s + t as a double.
final double expected = 1 - (1 - s) - (1 - t);
- Assert.assertNotEquals(expected, spt - 1, 0.0);
- Assert.assertNotEquals(expected, s + t - 1, 0.0);
+ Assertions.assertNotEquals(expected, spt - 1);
+ Assertions.assertNotEquals(expected, s + t - 1);
// For any uniform deviate u in [0, 1], u - 1 is exact, thus s - 1 is exact
// and s - 1 + t is exact.
- Assert.assertEquals(expected, s - 1 + t, 0.0);
+ Assertions.assertEquals(expected, s - 1 + t);
// Test that a(1 - s - t) + sb + tc does not overflow is s+t = 1
final double max = Double.MAX_VALUE;
s -= delta;
final UniformRandomProvider rng = RandomSource.XO_RO_SHI_RO_128_PP.create();
for (int n = 0; n < 100; n++) {
- Assert.assertNotEquals(Double.POSITIVE_INFINITY, (1 - s - t) * max + s * max + t * max, 0.0);
+ Assertions.assertNotEquals(Double.POSITIVE_INFINITY, (1 - s - t) * max + s * max + t * max);
s = rng.nextDouble();
t = 1.0 - s;
}
@@ -117,7 +117,7 @@ public class TriangleSamplerTest {
}) {
try {
TriangleSampler.of(rng, c[0], c[1], c[2]);
- Assert.fail(String.format("Did not detect dimension mismatch: %d,%d,%d",
+ Assertions.fail(String.format("Did not detect dimension mismatch: %d,%d,%d",
c[0].length, c[1].length, c[2].length));
} catch (IllegalArgumentException ex) {
// Expected
@@ -135,7 +135,7 @@ public class TriangleSamplerTest {
final double[][] c = new double[][] {
{0, 0, 1}, {2, 1, 0}, {-1, 2, 3}
};
- Assert.assertNotNull(TriangleSampler.of(rng, c[0], c[1], c[2]));
+ Assertions.assertNotNull(TriangleSampler.of(rng, c[0], c[1], c[2]));
final double[] bad = {Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN};
for (int i = 0; i < c.length; i++) {
for (int j = 0; j < c[0].length; j++) {
@@ -144,7 +144,7 @@ public class TriangleSamplerTest {
c[i][j] = d;
try {
TriangleSampler.of(rng, c[0], c[1], c[2]);
- Assert.fail(String.format("Did not detect non-finite coordinate: %d,%d = %s", i, j, d));
+ Assertions.fail(String.format("Did not detect non-finite coordinate: %d,%d = %s", i, j, d));
} catch (IllegalArgumentException ex) {
// Expected
}
@@ -212,10 +212,10 @@ public class TriangleSamplerTest {
}
}
// Show the triangle is too big to compute vectors between points.
- Assert.assertEquals("Expect vector c - a to be infinite in the x dimension",
- Double.POSITIVE_INFINITY, c2[2][0] - c2[0][0], 0.0);
- Assert.assertEquals("Expect vector c - b to be infinite in the y dimension",
- Double.NEGATIVE_INFINITY, c2[2][1] - c2[1][1], 0.0);
+ Assertions.assertEquals(Double.POSITIVE_INFINITY, c2[2][0] - c2[0][0],
+ "Expect vector c - a to be infinite in the x dimension");
+ Assertions.assertEquals(Double.NEGATIVE_INFINITY, c2[2][1] - c2[1][1],
+ "Expect vector c - b to be infinite in the y dimension");
final TriangleSampler sampler1 = TriangleSampler.of(
RandomSource.XO_RO_SHI_RO_128_PP.create(seed), c1[0], c1[1], c1[2]);
@@ -228,7 +228,7 @@ public class TriangleSamplerTest {
for (int i = 0; i < a.length; i++) {
a[i] *= scale;
}
- Assert.assertArrayEquals(a, b, 0.0);
+ Assertions.assertArrayEquals(a, b);
}
}
@@ -334,7 +334,7 @@ public class TriangleSamplerTest {
addObservation(reverse.apply(sampler3.sample()), observed, bins, sx, sy, triangle3);
}
final double p = new ChiSquareTest().chiSquareTest(expected, observed);
- Assert.assertFalse("p-value too small: " + p, p < 0.001);
+ Assertions.assertFalse(p < 0.001, () -> "p-value too small: " + p);
}
}
@@ -358,7 +358,7 @@ public class TriangleSamplerTest {
final double x = v[0];
final double y = v[1];
// Test the point is triangle the triangle
- Assert.assertTrue(triangle.contains(x, y));
+ Assertions.assertTrue(triangle.contains(x, y));
// Add to the correct bin after using the offset
final int binx = (int) (x * sx);
final int biny = (int) (y * sy);
@@ -453,11 +453,11 @@ public class TriangleSamplerTest {
for (int n = 0; n < 3; n++) {
final double[] s1 = sampler1.sample();
final double[] s2 = sampler2.sample();
- Assert.assertEquals(s1.length, s2.length);
- Assert.assertFalse("First sampler has used the vertices by reference",
- Arrays.equals(s1, s2));
+ Assertions.assertEquals(s1.length, s2.length);
+ Assertions.assertFalse(Arrays.equals(s1, s2),
+ "First sampler has used the vertices by reference");
for (int i = 0; i < dimension; i++) {
- Assert.assertEquals(s1[i] + offset, s2[i], 1e-10);
+ Assertions.assertEquals(s1[i] + offset, s2[i], 1e-10);
}
}
}
@@ -519,15 +519,15 @@ public class TriangleSamplerTest {
for (int n = 0; n < 10; n++) {
final double[] a = new double[] {rng.nextDouble(), rng.nextDouble()};
final double[] b = forward.apply(a);
- Assert.assertEquals(dimension, b.length);
+ Assertions.assertEquals(dimension, b.length);
for (int i = 2; i < dimension; i++) {
sum += Math.abs(b[i]);
}
final double[] c = reverse.apply(b);
- Assert.assertArrayEquals(a, c, 1e-10);
+ Assertions.assertArrayEquals(a, c, 1e-10);
}
// Check that higher dimension coordinates are generated
- Assert.assertTrue(sum > 0.5);
+ Assertions.assertTrue(sum > 0.5);
}
/**
@@ -537,10 +537,10 @@ public class TriangleSamplerTest {
public void testRotations3D() {
final double[] x = {1, 0.5, 0};
final double[] y = multiply(F3, x);
- Assert.assertArrayEquals(new double[] {0.465475314831549, 1.004183876910958, -0.157947689551155}, y, 1e-10);
- Assert.assertEquals(length(x), length(y), 1e-10);
+ Assertions.assertArrayEquals(new double[] {0.465475314831549, 1.004183876910958, -0.157947689551155}, y, 1e-10);
+ Assertions.assertEquals(length(x), length(y), 1e-10);
final double[] x2 = multiply(R3, y);
- Assert.assertArrayEquals(x, x2, 1e-10);
+ Assertions.assertArrayEquals(x, x2, 1e-10);
}
/**
@@ -550,11 +550,11 @@ public class TriangleSamplerTest {
public void testRotations4D() {
final double[] x = {1, 0.5, 0, 0};
final double[] y = multiply(F4, x);
- Assert.assertArrayEquals(
+ Assertions.assertArrayEquals(
new double[] {0.676776695296637, 0.780330085889911, 0.323223304703363, -0.280330085889911}, y, 1e-10);
- Assert.assertEquals(length(x), length(y), 1e-10);
+ Assertions.assertEquals(length(x), length(y), 1e-10);
final double[] x2 = multiply(R4, y);
- Assert.assertArrayEquals(x, x2, 1e-10);
+ Assertions.assertArrayEquals(x, x2, 1e-10);
}
/**
@@ -597,27 +597,27 @@ public class TriangleSamplerTest {
public void testTriangleContains() {
final Triangle triangle = new Triangle(1, 2, 3, 1, 0.5, 6);
// Vertices
- Assert.assertTrue(triangle.contains(1, 2));
- Assert.assertTrue(triangle.contains(3, 1));
- Assert.assertTrue(triangle.contains(0.5, 6));
+ Assertions.assertTrue(triangle.contains(1, 2));
+ Assertions.assertTrue(triangle.contains(3, 1));
+ Assertions.assertTrue(triangle.contains(0.5, 6));
// Edge
- Assert.assertTrue(triangle.contains(0.75, 4));
+ Assertions.assertTrue(triangle.contains(0.75, 4));
// Inside
- Assert.assertTrue(triangle.contains(1.5, 3));
+ Assertions.assertTrue(triangle.contains(1.5, 3));
// Outside
- Assert.assertFalse(triangle.contains(0, 20));
- Assert.assertFalse(triangle.contains(-20, 0));
- Assert.assertFalse(triangle.contains(6, 6));
+ Assertions.assertFalse(triangle.contains(0, 20));
+ Assertions.assertFalse(triangle.contains(-20, 0));
+ Assertions.assertFalse(triangle.contains(6, 6));
// Just outside
- Assert.assertFalse(triangle.contains(0.75, 4 - 1e-10));
+ Assertions.assertFalse(triangle.contains(0.75, 4 - 1e-10));
// Note:
// Touching triangles can both have the point triangle.
// This predicate is not suitable for assigning points uniquely to
// non-overlapping triangles that share an edge.
final Triangle triangle2 = new Triangle(1, 2, 3, 1, 0, -2);
- Assert.assertTrue(triangle.contains(2, 1.5));
- Assert.assertTrue(triangle2.contains(2, 1.5));
+ Assertions.assertTrue(triangle.contains(2, 1.5));
+ Assertions.assertTrue(triangle2.contains(2, 1.5));
}
/**
@@ -671,11 +671,11 @@ public class TriangleSamplerTest {
@Override
public double[] apply(double[] coord) {
- Assert.assertEquals(n, coord.length);
+ Assertions.assertEquals(n, coord.length);
final double[] x = multiply(r, coord);
// This should reverse the 2D transform and return to the XY plane.
for (int i = 2; i < x.length; i++) {
- Assert.assertEquals(0.0, x[i], 1e-14);
+ Assertions.assertEquals(0.0, x[i], 1e-14);
}
return new double[] {x[0], x[1]};
}
@@ -687,7 +687,7 @@ public class TriangleSamplerTest {
private static class Transform2Dto2D implements Transform {
@Override
public double[] apply(double[] coord) {
- Assert.assertEquals(2, coord.length);
+ Assertions.assertEquals(2, coord.length);
return coord;
}
}
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/UnitBallSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/UnitBallSamplerTest.java
index 72b400b..66221d5 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/UnitBallSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/shape/UnitBallSamplerTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.rng.sampling.shape;
import java.util.Arrays;
import java.util.function.DoubleUnaryOperator;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.apache.commons.math3.stat.inference.ChiSquareTest;
@@ -143,10 +143,10 @@ public class UnitBallSamplerTest {
}
}
// Radius above 1
- Assert.fail("Invalid sample length: " + length);
+ Assertions.fail("Invalid sample length: " + length);
}
final double p = new ChiSquareTest().chiSquareTest(expected, observed);
- Assert.assertFalse("p-value too small: " + p, p < 0.001);
+ Assertions.assertFalse(p < 0.001, () -> "p-value too small: " + p);
}
}
@@ -184,9 +184,9 @@ public class UnitBallSamplerTest {
};
final double[] vector = UnitBallSampler.of(bad, dimension).sample();
- Assert.assertEquals(dimension, vector.length);
+ Assertions.assertEquals(dimension, vector.length);
// A non-zero coordinate should occur with a SplitMix which returns 0 only once.
- Assert.assertNotEquals(0.0, length(vector));
+ Assertions.assertNotEquals(0.0, length(vector));
}
/**
@@ -273,7 +273,7 @@ public class UnitBallSamplerTest {
final DoubleUnaryOperator volume = createVolumeFunction(n);
final DoubleUnaryOperator radius = createRadiusFunction(n);
for (final double r : radii) {
- Assert.assertEquals(r, radius.applyAsDouble(volume.applyAsDouble(r)), 1e-10);
+ Assertions.assertEquals(r, radius.applyAsDouble(volume.applyAsDouble(r)), 1e-10);
}
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/JDKRandomBridgeTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/JDKRandomBridgeTest.java
index 6e735c7..e920400 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/JDKRandomBridgeTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/JDKRandomBridgeTest.java
@@ -22,7 +22,7 @@ import java.io.ObjectInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.util.Random;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -39,7 +39,7 @@ public class JDKRandomBridgeTest {
// Reseed.
final long newSeed = RandomSource.createLong();
- Assert.assertNotEquals(seed, newSeed);
+ Assertions.assertNotEquals(seed, newSeed);
rng1.setSeed(newSeed);
rng2.setSeed(newSeed);
checkSameSequence(rng1, rng2);
@@ -76,36 +76,33 @@ public class JDKRandomBridgeTest {
private void checkSameSequence(Random rng1,
Random rng2) {
for (int i = 0; i < 4; i++) {
- Assert.assertEquals(rng1.nextInt(),
- rng2.nextInt());
+ Assertions.assertEquals(rng1.nextInt(),
+ rng2.nextInt());
}
for (int i = 0; i < 7; i++) {
- Assert.assertEquals(rng1.nextLong(),
- rng2.nextLong());
+ Assertions.assertEquals(rng1.nextLong(),
+ rng2.nextLong());
}
for (int i = 0; i < 9; i++) {
- Assert.assertEquals(rng1.nextFloat(),
- rng2.nextFloat(),
- 0f);
+ Assertions.assertEquals(rng1.nextFloat(),
+ rng2.nextFloat());
}
for (int i = 0; i < 12; i++) {
- Assert.assertEquals(rng1.nextDouble(),
- rng2.nextDouble(),
- 0d);
+ Assertions.assertEquals(rng1.nextDouble(),
+ rng2.nextDouble());
}
for (int i = 0; i < 17; i++) {
- Assert.assertEquals(rng1.nextGaussian(),
- rng2.nextGaussian(),
- 0d);
+ Assertions.assertEquals(rng1.nextGaussian(),
+ rng2.nextGaussian());
}
for (int i = 0; i < 18; i++) {
- Assert.assertEquals(rng1.nextBoolean(),
- rng2.nextBoolean());
+ Assertions.assertEquals(rng1.nextBoolean(),
+ rng2.nextBoolean());
}
for (int i = 0; i < 19; i++) {
final int max = i + 123456;
- Assert.assertEquals(rng1.nextInt(max),
- rng2.nextInt(max));
+ Assertions.assertEquals(rng1.nextInt(max),
+ rng2.nextInt(max));
}
final int len = 233;
@@ -114,8 +111,8 @@ public class JDKRandomBridgeTest {
rng1.nextBytes(store1);
rng2.nextBytes(store2);
for (int i = 0; i < len; i++) {
- Assert.assertEquals(store1[i],
- store2[i]);
+ Assertions.assertEquals(store1[i],
+ store2[i]);
}
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/JDKRandomWrapperTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/JDKRandomWrapperTest.java
index e4e9895..e6a0559 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/JDKRandomWrapperTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/JDKRandomWrapperTest.java
@@ -20,7 +20,7 @@ import java.util.Random;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.core.source64.LongProvider;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -48,31 +48,29 @@ public class JDKRandomWrapperTest {
private static void checkSameSequence(Random rng1,
UniformRandomProvider rng2) {
for (int i = 0; i < 4; i++) {
- Assert.assertEquals(rng1.nextInt(),
- rng2.nextInt());
+ Assertions.assertEquals(rng1.nextInt(),
+ rng2.nextInt());
}
for (int i = 0; i < 7; i++) {
- Assert.assertEquals(rng1.nextLong(),
- rng2.nextLong());
+ Assertions.assertEquals(rng1.nextLong(),
+ rng2.nextLong());
}
for (int i = 0; i < 9; i++) {
- Assert.assertEquals(rng1.nextFloat(),
- rng2.nextFloat(),
- 0f);
+ Assertions.assertEquals(rng1.nextFloat(),
+ rng2.nextFloat());
}
for (int i = 0; i < 12; i++) {
- Assert.assertEquals(rng1.nextDouble(),
- rng2.nextDouble(),
- 0d);
+ Assertions.assertEquals(rng1.nextDouble(),
+ rng2.nextDouble());
}
for (int i = 0; i < 18; i++) {
- Assert.assertEquals(rng1.nextBoolean(),
- rng2.nextBoolean());
+ Assertions.assertEquals(rng1.nextBoolean(),
+ rng2.nextBoolean());
}
for (int i = 0; i < 19; i++) {
final int max = i + 123456;
- Assert.assertEquals(rng1.nextInt(max),
- rng2.nextInt(max));
+ Assertions.assertEquals(rng1.nextInt(max),
+ rng2.nextInt(max));
}
final int len = 233;
@@ -81,8 +79,8 @@ public class JDKRandomWrapperTest {
rng1.nextBytes(store1);
rng2.nextBytes(store2);
for (int i = 0; i < len; i++) {
- Assert.assertEquals(store1[i],
- store2[i]);
+ Assertions.assertEquals(store1[i],
+ store2[i]);
}
}
@@ -116,7 +114,7 @@ public class JDKRandomWrapperTest {
// all code paths.
for (final long max : new long[] {1, 256, 56757, 1L << 32, (1L << 62) + 1}) {
for (int i = 0; i < 10; i++) {
- Assert.assertEquals(rng1.nextLong(max),
+ Assertions.assertEquals(rng1.nextLong(max),
rng2.nextLong(max));
}
}
@@ -163,7 +161,7 @@ public class JDKRandomWrapperTest {
rng1.nextBytes(store1);
rng2.nextBytes(store2, start, length);
for (int i = 0; i < length; i++) {
- Assert.assertEquals(store1[i],
+ Assertions.assertEquals(store1[i],
store2[i + start]);
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ProvidersCommonParametricTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ProvidersCommonParametricTest.java
index ba4f60c..036790b 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ProvidersCommonParametricTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ProvidersCommonParametricTest.java
@@ -26,9 +26,9 @@ import java.io.ObjectInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
-import org.junit.Assume;
+import org.junit.jupiter.api.Assumptions;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@@ -86,10 +86,10 @@ public class ProvidersCommonParametricTest {
@Test
public void testFactoryCreateMethod() {
// Cannot test providers that require arguments
- Assume.assumeTrue(originalArgs == null);
+ Assumptions.assumeTrue(originalArgs == null);
@SuppressWarnings("deprecation")
final UniformRandomProvider rng = RandomSource.create(originalSource);
- Assert.assertEquals(generator.getClass(), rng.getClass());
+ Assertions.assertEquals(generator.getClass(), rng.getClass());
}
/**
@@ -100,11 +100,11 @@ public class ProvidersCommonParametricTest {
public void testFactoryCreateMethodWithSeed() {
@SuppressWarnings("deprecation")
final UniformRandomProvider rng1 = RandomSource.create(originalSource, originalSeed, originalArgs);
- Assert.assertEquals(rng1.getClass(), generator.getClass());
+ Assertions.assertEquals(rng1.getClass(), generator.getClass());
// Check the output
final UniformRandomProvider rng2 = originalSource.create(originalSeed, originalArgs);
for (int i = 0; i < 10; i++) {
- Assert.assertEquals(rng2.nextLong(), rng1.nextLong());
+ Assertions.assertEquals(rng2.nextLong(), rng1.nextLong());
}
}
@@ -120,7 +120,7 @@ public class ProvidersCommonParametricTest {
int arg1 = 123;
double arg2 = 456.0;
originalSource.create(arg1, arg2);
- Assert.fail("Source does not require arguments: " + originalSource);
+ Assertions.fail("Source does not require arguments: " + originalSource);
} catch (IllegalArgumentException ex) {
// Expected
}
@@ -128,7 +128,7 @@ public class ProvidersCommonParametricTest {
try {
// Try no arguments for a provider that does require them
originalSource.create();
- Assert.fail("Source requires arguments: " + originalSource);
+ Assertions.fail("Source requires arguments: " + originalSource);
} catch (IllegalArgumentException ex) {
// Expected
}
@@ -155,9 +155,9 @@ public class ProvidersCommonParametricTest {
for (Object s : seeds) {
++seedCount;
if (originalSource.isNativeSeed(s)) {
- Assert.assertNotNull("Identified native seed is null", s);
- Assert.assertEquals("Incorrect identification of native seed type",
- s.getClass(), originalSeed.getClass());
+ Assertions.assertNotNull(s, "Identified native seed is null");
+ Assertions.assertEquals(s.getClass(), originalSeed.getClass(),
+ "Incorrect identification of native seed type");
} else {
++nonNativeSeedCount;
}
@@ -165,8 +165,8 @@ public class ProvidersCommonParametricTest {
originalSource.create(s, originalArgs);
}
- Assert.assertEquals(6, seedCount);
- Assert.assertEquals(5, nonNativeSeedCount);
+ Assertions.assertEquals(6, seedCount);
+ Assertions.assertEquals(5, nonNativeSeedCount);
}
@Test
@@ -181,7 +181,7 @@ public class ProvidersCommonParametricTest {
@Test
public void testEmptyIntArraySeed() {
final int[] empty = new int[0];
- Assume.assumeTrue(originalSource.isNativeSeed(empty));
+ Assumptions.assumeTrue(originalSource.isNativeSeed(empty));
// Exercise the default seeding procedure.
final UniformRandomProvider rng = originalSource.create(empty, originalArgs);
@@ -191,9 +191,9 @@ public class ProvidersCommonParametricTest {
@Test
public void testEmptyLongArraySeed() {
final long[] empty = new long[0];
- Assume.assumeTrue(originalSource.isNativeSeed(empty));
+ Assumptions.assumeTrue(originalSource.isNativeSeed(empty));
// The Middle-Square Weyl Sequence generator cannot self-seed
- Assume.assumeFalse(originalSource == RandomSource.MSWS);
+ Assumptions.assumeFalse(originalSource == RandomSource.MSWS);
// Exercise the default seeding procedure.
final UniformRandomProvider rng = originalSource.create(empty, originalArgs);
@@ -205,8 +205,8 @@ public class ProvidersCommonParametricTest {
// Exercise capacity to escape all "zero" state.
final int[] zero = new int[2000]; // Large enough to fill the entire state with zeroes.
final UniformRandomProvider rng = originalSource.create(zero, originalArgs);
- Assume.assumeTrue("RNG is non-functional with an all zero seed: " + originalSource,
- createsNonZeroLongOutput(rng, 2000));
+ Assumptions.assumeTrue(createsNonZeroLongOutput(rng, 2000),
+ () -> "RNG is non-functional with an all zero seed: " + originalSource);
checkNextIntegerInRange(rng, 10, 10000);
}
@@ -215,8 +215,8 @@ public class ProvidersCommonParametricTest {
// Exercise capacity to escape all "zero" state.
final long[] zero = new long[2000]; // Large enough to fill the entire state with zeroes.
final UniformRandomProvider rng = originalSource.create(zero, originalArgs);
- Assume.assumeTrue("RNG is non-functional with an all zero seed: " + originalSource,
- createsNonZeroLongOutput(rng, 2000));
+ Assumptions.assumeTrue(createsNonZeroLongOutput(rng, 2000),
+ () -> "RNG is non-functional with an all zero seed: " + originalSource);
checkNextIntegerInRange(rng, 10, 10000);
}
@@ -250,7 +250,7 @@ public class ProvidersCommonParametricTest {
// Cast must fail.
try {
final RestorableUniformRandomProvider dummy = (RestorableUniformRandomProvider) rng2;
- Assert.fail("Cast should have failed");
+ Assertions.fail("Cast should have failed");
} catch (ClassCastException e) {
// Expected.
}
@@ -278,40 +278,42 @@ public class ProvidersCommonParametricTest {
// Discard a few more.
final List<Number> listDiscard = makeList(n);
- Assert.assertNotEquals(0, listDiscard.size());
- Assert.assertNotEquals(listOrig, listDiscard);
+ Assertions.assertNotEquals(0, listDiscard.size());
+ Assertions.assertNotEquals(listOrig, listDiscard);
// Retrieve from serialized stream.
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
final RandomProviderState stateNew = new RandomProviderDefaultState((byte[]) ois.readObject());
- Assert.assertNotSame(stateOrig, stateNew);
+ Assertions.assertNotSame(stateOrig, stateNew);
// Reset.
restorable.restoreState(stateNew);
// Replay.
final List<Number> listReplay = makeList(n);
- Assert.assertNotSame(listOrig, listReplay);
+ Assertions.assertNotSame(listOrig, listReplay);
// Check that the serialized data recreated the orginal state.
- Assert.assertEquals(listOrig, listReplay);
+ Assertions.assertEquals(listOrig, listReplay);
}
@Test
public void testUnrestorableToString() {
- Assert.assertEquals(generator.toString(),
+ Assertions.assertEquals(generator.toString(),
RandomSource.unrestorable(generator).toString());
}
@Test
public void testSupportedInterfaces() {
final UniformRandomProvider rng = originalSource.create(null, originalArgs);
- Assert.assertEquals("isJumpable", rng instanceof JumpableUniformRandomProvider,
- originalSource.isJumpable());
- Assert.assertEquals("isLongJumpable", rng instanceof LongJumpableUniformRandomProvider,
- originalSource.isLongJumpable());
+ Assertions.assertEquals(rng instanceof JumpableUniformRandomProvider,
+ originalSource.isJumpable(),
+ "isJumpable");
+ Assertions.assertEquals(rng instanceof LongJumpableUniformRandomProvider,
+ originalSource.isLongJumpable(),
+ "isLongJumpable");
}
///// Support methods below.
@@ -422,7 +424,7 @@ public class ProvidersCommonParametricTest {
Arrays.fill(observed, 0);
for (int j = 0; j < sampleSize; j++) {
final long value = nextMethod.call().longValue();
- Assert.assertTrue("Range", value >= 0 && value < n);
+ Assertions.assertTrue(value >= 0 && value < n, "Range");
for (int k = 0; k < numBins; k++) {
if (value < binUpperBounds[k]) {
@@ -458,7 +460,7 @@ public class ProvidersCommonParametricTest {
// 12 0.00190
if (numFailures > 11) { // Test will fail with 0.5% probability
- Assert.fail(generator + ": Too many failures for n = " + n +
+ Assertions.fail(generator + ": Too many failures for n = " + n +
" (" + numFailures + " out of " + numTests + " tests failed)");
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/RandomAssert.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/RandomAssert.java
index e38f6b0..d295528 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/RandomAssert.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/RandomAssert.java
@@ -17,7 +17,7 @@
package org.apache.commons.rng.simple;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.apache.commons.rng.UniformRandomProvider;
@@ -40,31 +40,31 @@ public final class RandomAssert {
public static void assertProduceSameSequence(UniformRandomProvider rng1,
UniformRandomProvider rng2) {
for (int i = 0; i < 54; i++) {
- Assert.assertEquals(rng1.nextBoolean(), rng2.nextBoolean());
+ Assertions.assertEquals(rng1.nextBoolean(), rng2.nextBoolean());
}
for (int i = 0; i < 23; i++) {
- Assert.assertEquals(rng1.nextInt(), rng2.nextInt());
+ Assertions.assertEquals(rng1.nextInt(), rng2.nextInt());
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 5; j++) {
final int max = 107 * i + 374 * j + 11;
- Assert.assertEquals(rng1.nextInt(max), rng2.nextInt(max));
+ Assertions.assertEquals(rng1.nextInt(max), rng2.nextInt(max));
}
}
for (int i = 0; i < 23; i++) {
- Assert.assertEquals(rng1.nextLong(), rng2.nextLong());
+ Assertions.assertEquals(rng1.nextLong(), rng2.nextLong());
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 5; j++) {
final long max = (Long.MAX_VALUE << 2) + 107 * i + 374 * j + 11;
- Assert.assertEquals(rng1.nextLong(max), rng2.nextLong(max));
+ Assertions.assertEquals(rng1.nextLong(max), rng2.nextLong(max));
}
}
for (int i = 0; i < 103; i++) {
- Assert.assertEquals(rng1.nextFloat(), rng2.nextFloat(), 0);
+ Assertions.assertEquals(rng1.nextFloat(), rng2.nextFloat());
}
for (int i = 0; i < 79; i++) {
- Assert.assertEquals(rng1.nextDouble(), rng2.nextDouble(), 0);
+ Assertions.assertEquals(rng1.nextDouble(), rng2.nextDouble());
}
final int size = 345;
@@ -74,7 +74,7 @@ public final class RandomAssert {
for (int i = 0; i < 3; i++) {
rng1.nextBytes(a1);
rng2.nextBytes(a2);
- Assert.assertArrayEquals(a1, a2);
+ Assertions.assertArrayEquals(a1, a2);
}
for (int i = 0; i < 5; i++) {
@@ -82,7 +82,7 @@ public final class RandomAssert {
final int n = 23 + i;
rng1.nextBytes(a1, offset, n);
rng2.nextBytes(a2, offset, n);
- Assert.assertArrayEquals(a1, a2);
+ Assertions.assertArrayEquals(a1, a2);
}
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/RandomSourceTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/RandomSourceTest.java
index 5739246..b4e983c 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/RandomSourceTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/RandomSourceTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.simple;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -28,8 +28,8 @@ public class RandomSourceTest {
final int n = 4;
for (int i = 0; i < n; i++) {
// Can fail, but unlikely given the range.
- Assert.assertNotEquals(RandomSource.createInt(),
- RandomSource.createInt());
+ Assertions.assertNotEquals(RandomSource.createInt(),
+ RandomSource.createInt());
}
}
@@ -38,8 +38,8 @@ public class RandomSourceTest {
final int n = 6;
for (int i = 0; i < n; i++) {
// Can fail, but unlikely given the range.
- Assert.assertNotEquals(RandomSource.createLong(),
- RandomSource.createLong());
+ Assertions.assertNotEquals(RandomSource.createLong(),
+ RandomSource.createLong());
}
}
@@ -47,11 +47,11 @@ public class RandomSourceTest {
public void testCreateIntArray() {
final int n = 13;
final int[] seed = RandomSource.createIntArray(n);
- Assert.assertEquals(n, seed.length);
+ Assertions.assertEquals(n, seed.length);
for (int i = 1; i < n; i++) {
// Can fail, but unlikely given the range.
- Assert.assertNotEquals(seed[i - 1], seed[i]);
+ Assertions.assertNotEquals(seed[i - 1], seed[i]);
}
}
@@ -59,25 +59,25 @@ public class RandomSourceTest {
public void testCreateLongArray() {
final int n = 9;
final long[] seed = RandomSource.createLongArray(n);
- Assert.assertEquals(n, seed.length);
+ Assertions.assertEquals(n, seed.length);
for (int i = 1; i < n; i++) {
// Can fail, but unlikely given the range.
- Assert.assertNotEquals(seed[i - 1], seed[i]);
+ Assertions.assertNotEquals(seed[i - 1], seed[i]);
}
}
@Test
public void testIsJumpable() {
- Assert.assertFalse("JDK is not Jumpable", RandomSource.JDK.isJumpable());
- Assert.assertTrue("XOR_SHIFT_1024_S_PHI is Jumpable", RandomSource.XOR_SHIFT_1024_S_PHI.isJumpable());
- Assert.assertTrue("XO_SHI_RO_256_SS is Jumpable", RandomSource.XO_SHI_RO_256_SS.isJumpable());
+ Assertions.assertFalse(RandomSource.JDK.isJumpable(), "JDK is not Jumpable");
+ Assertions.assertTrue(RandomSource.XOR_SHIFT_1024_S_PHI.isJumpable(), "XOR_SHIFT_1024_S_PHI is Jumpable");
+ Assertions.assertTrue(RandomSource.XO_SHI_RO_256_SS.isJumpable(), "XO_SHI_RO_256_SS is Jumpable");
}
@Test
public void testIsLongJumpable() {
- Assert.assertFalse("JDK is not LongJumpable", RandomSource.JDK.isLongJumpable());
- Assert.assertFalse("XOR_SHIFT_1024_S_PHI is not LongJumpable", RandomSource.XOR_SHIFT_1024_S_PHI.isLongJumpable());
- Assert.assertTrue("XO_SHI_RO_256_SS is LongJumpable", RandomSource.XO_SHI_RO_256_SS.isLongJumpable());
+ Assertions.assertFalse(RandomSource.JDK.isLongJumpable(), "JDK is not LongJumpable");
+ Assertions.assertFalse(RandomSource.XOR_SHIFT_1024_S_PHI.isLongJumpable(), "XOR_SHIFT_1024_S_PHI is not LongJumpable");
+ Assertions.assertTrue(RandomSource.XO_SHI_RO_256_SS.isLongJumpable(), "XO_SHI_RO_256_SS is LongJumpable");
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ThreadLocalRandomSourceTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ThreadLocalRandomSourceTest.java
index eefabac..613fc6c 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ThreadLocalRandomSourceTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ThreadLocalRandomSourceTest.java
@@ -17,7 +17,7 @@
package org.apache.commons.rng.simple;
import org.apache.commons.rng.UniformRandomProvider;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -61,19 +61,21 @@ public class ThreadLocalRandomSourceTest {
final UniformRandomProvider[] rngs = new UniformRandomProvider[sources.length];
for (int i = 0; i < sources.length; i++) {
- if (toIgnore.contains(sources[i])) {
+ final RandomSource source = sources[i];
+ if (toIgnore.contains(source)) {
continue;
}
- final UniformRandomProvider rng = getCurrent(sources[i]);
- Assert.assertNotNull("Failed to create source: " + sources[i], rng);
+ final UniformRandomProvider rng = getCurrent(source);
+ Assertions.assertNotNull(rng, () -> "Failed to create source: " + source);
rngs[i] = rng;
}
for (int i = 0; i < sources.length; i++) {
- if (toIgnore.contains(sources[i])) {
+ final RandomSource source = sources[i];
+ if (toIgnore.contains(source)) {
continue;
}
- final UniformRandomProvider rng = getCurrent(sources[i]);
- Assert.assertSame("Failed to return same source: " + sources[i], rngs[i], rng);
+ final UniformRandomProvider rng = getCurrent(source);
+ Assertions.assertSame(rngs[i], rng, () -> "Failed to return same source: " + source);
}
// Build on a new thread
@@ -98,10 +100,11 @@ public class ThreadLocalRandomSourceTest {
// The RNG from the new thread should be different
for (int i = 0; i < sources.length; i++) {
- if (toIgnore.contains(sources[i])) {
+ final RandomSource source = sources[i];
+ if (toIgnore.contains(source)) {
continue;
}
- Assert.assertNotSame("Failed to return different source: " + sources[i], rngs[i], rngs2[i]);
+ Assertions.assertNotSame(rngs[i], rngs2[i], () -> "Failed to return different source: " + source);
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/ByteArray2IntArrayTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/ByteArray2IntArrayTest.java
index dddc7a4..b3980d8 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/ByteArray2IntArrayTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/ByteArray2IntArrayTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.simple.internal;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -27,7 +27,7 @@ public class ByteArray2IntArrayTest {
public void testSeedSizeIsMultipleOfIntSize() {
final byte[] seed = new byte[128];
final int[] out = new ByteArray2IntArray().convert(seed);
- Assert.assertEquals(32, out.length);
+ Assertions.assertEquals(32, out.length);
}
@Test
@@ -37,7 +37,7 @@ public class ByteArray2IntArrayTest {
for (int i = 1; i < 4; i++) {
final byte[] seed = new byte[len + i];
final int[] out = conv.convert(seed);
- Assert.assertEquals(5, out.length);
+ Assertions.assertEquals(5, out.length);
}
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/ByteArray2LongArrayTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/ByteArray2LongArrayTest.java
index 1c9a424..a681738 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/ByteArray2LongArrayTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/ByteArray2LongArrayTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.simple.internal;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -27,7 +27,7 @@ public class ByteArray2LongArrayTest {
public void testSeedSizeIsMultipleOfLongSize() {
final byte[] seed = new byte[128];
final long[] out = new ByteArray2LongArray().convert(seed);
- Assert.assertEquals(16, out.length);
+ Assertions.assertEquals(16, out.length);
}
@Test
@@ -37,7 +37,7 @@ public class ByteArray2LongArrayTest {
for (int i = 1; i < 8; i++) {
final byte[] seed = new byte[len + i];
final long[] out = conv.convert(seed);
- Assert.assertEquals(3, out.length);
+ Assertions.assertEquals(3, out.length);
}
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/IntArray2LongArrayTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/IntArray2LongArrayTest.java
index e665ca2..4a276dd 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/IntArray2LongArrayTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/IntArray2LongArrayTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.simple.internal;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -27,13 +27,13 @@ public class IntArray2LongArrayTest {
public void testSeedSizeIsMultipleOfLongSize() {
final int[] seed = new int[12];
final long[] out = new IntArray2LongArray().convert(seed);
- Assert.assertEquals(6, out.length);
+ Assertions.assertEquals(6, out.length);
}
@Test
public void testSeedSizeIsNotMultipleOfLongSize() {
final int[] seed = new int[13];
final long[] out = new IntArray2LongArray().convert(seed);
- Assert.assertEquals(7, out.length);
+ Assertions.assertEquals(7, out.length);
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/Long2IntArrayTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/Long2IntArrayTest.java
index 97c915a..7a2d04d 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/Long2IntArrayTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/Long2IntArrayTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.simple.internal;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -33,11 +33,11 @@ public class Long2IntArrayTest {
private static void testFixedLengthConversion(int length) {
final Long seed = 567L;
final int[] out = new Long2IntArray(length).convert(seed);
- Assert.assertEquals(length, out.length);
+ Assertions.assertEquals(length, out.length);
// This very seed dependent but the algorithm
// should only produce 0 about 1 in 2^32 times.
for (int i = 0; i < length; i++) {
- Assert.assertNotEquals(0, out[i]);
+ Assertions.assertNotEquals(0, out[i]);
}
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/Long2LongArrayTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/Long2LongArrayTest.java
index 36d3960..d0efaef 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/Long2LongArrayTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/Long2LongArrayTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.simple.internal;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -28,6 +28,6 @@ public class Long2LongArrayTest {
final Long seed = 567L;
final int length = 3;
final long[] out = new Long2LongArray(length).convert(seed);
- Assert.assertEquals(length, out.length);
+ Assertions.assertEquals(length, out.length);
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/NativeSeedTypeParametricTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/NativeSeedTypeParametricTest.java
index 3913341..8469047 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/NativeSeedTypeParametricTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/NativeSeedTypeParametricTest.java
@@ -16,13 +16,14 @@
*/
package org.apache.commons.rng.simple.internal;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import java.lang.reflect.Array;
+import java.util.function.Supplier;
/**
* Tests for the {@link NativeSeedType} seed conversions. This test
@@ -76,8 +77,8 @@ public class NativeSeedTypeParametricTest {
public static Object[] getTypes() {
// Check that there are enum values for all supported types.
// This ensures the test is maintained to correspond to the enum.
- Assert.assertEquals("Incorrect number of enum values for the supported native types",
- SUPPORTED_NATIVE_TYPES.length, NativeSeedType.values().length);
+ Assertions.assertEquals(SUPPORTED_NATIVE_TYPES.length, NativeSeedType.values().length,
+ "Incorrect number of enum values for the supported native types");
return SUPPORTED_NATIVE_TYPES;
}
@@ -104,10 +105,10 @@ public class NativeSeedTypeParametricTest {
public void testCreateSeed() {
final int size = 3;
final Object seed = nativeSeedType.createSeed(size);
- Assert.assertNotNull(seed);
- Assert.assertEquals("Seed was not the correct class", type, seed.getClass());
+ Assertions.assertNotNull(seed);
+ Assertions.assertEquals(type, seed.getClass(), "Seed was not the correct class");
if (type.isArray()) {
- Assert.assertEquals("Seed was not created the correct length", size, Array.getLength(seed));
+ Assertions.assertEquals(size, Array.getLength(seed), "Seed was not created the correct length");
}
}
@@ -118,18 +119,18 @@ public class NativeSeedTypeParametricTest {
public void testConvertSeedToBytes() {
final int size = 3;
final Object seed = nativeSeedType.createSeed(size);
- Assert.assertNotNull("Null seed", seed);
+ Assertions.assertNotNull(seed, "Null seed");
final byte[] bytes = NativeSeedType.convertSeedToBytes(seed);
- Assert.assertNotNull("Null byte[] seed", bytes);
+ Assertions.assertNotNull(bytes, "Null byte[] seed");
final Object seed2 = nativeSeedType.convertSeed(bytes, size);
if (type.isArray()) {
// This handles nested primitive arrays
- Assert.assertArrayEquals("byte[] seed was not converted back",
- new Object[] {seed}, new Object[] {seed2});
+ Assertions.assertArrayEquals(new Object[] {seed}, new Object[] {seed2},
+ "byte[] seed was not converted back");
} else {
- Assert.assertEquals("byte[] seed was not converted back", seed, seed2);
+ Assertions.assertEquals(seed, seed2, "byte[] seed was not converted back");
}
}
@@ -142,9 +143,9 @@ public class NativeSeedTypeParametricTest {
final int size = 3;
for (final Object input : SUPPORTED_SEEDS) {
final Object seed = nativeSeedType.convertSeed(input, size);
- final String msg = input.getClass() + " input seed was not converted";
- Assert.assertNotNull(msg, seed);
- Assert.assertEquals(msg, type, seed.getClass());
+ final Supplier<String> msg = () -> input.getClass() + " input seed was not converted";
+ Assertions.assertNotNull(seed, msg);
+ Assertions.assertEquals(type, seed.getClass(), msg);
}
}
@@ -157,7 +158,7 @@ public class NativeSeedTypeParametricTest {
for (final Object input : UNSUPPORTED_SEEDS) {
try {
nativeSeedType.convertSeed(input, size);
- Assert.fail(input.getClass() + " input seed was not rejected as unsupported");
+ Assertions.fail(input.getClass() + " input seed was not rejected as unsupported");
} catch (UnsupportedOperationException ex) {
// This is expected
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/NativeSeedTypeTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/NativeSeedTypeTest.java
index be699ae..e325d39 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/NativeSeedTypeTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/NativeSeedTypeTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.simple.internal;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -39,6 +39,6 @@ public class NativeSeedTypeTest {
@Test
public void testConvertSeedToBytesUsingByteArray() {
final byte[] seed = {42, 78, 99};
- Assert.assertSame(seed, NativeSeedType.convertSeedToBytes(seed));
+ Assertions.assertSame(seed, NativeSeedType.convertSeedToBytes(seed));
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/NoOpConverterTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/NoOpConverterTest.java
index 759f004..db4e270 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/NoOpConverterTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/NoOpConverterTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.simple.internal;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -27,13 +27,13 @@ public class NoOpConverterTest {
public void testNoOpIntegerCoversion() {
final NoOpConverter<Integer> converter = new NoOpConverter<Integer>();
final Integer in = 123;
- Assert.assertSame(in, converter.convert(in));
+ Assertions.assertSame(in, converter.convert(in));
}
@Test
public void testNoOpLongArrayCoversion() {
final NoOpConverter<long[]> converter = new NoOpConverter<long[]>();
final long[] in = {123L, 456L, Long.MAX_VALUE};
- Assert.assertSame(in, converter.convert(in));
+ Assertions.assertSame(in, converter.convert(in));
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/RandomSourceInternalParametricTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/RandomSourceInternalParametricTest.java
index 4c8f118..5948223 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/RandomSourceInternalParametricTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/RandomSourceInternalParametricTest.java
@@ -18,13 +18,14 @@ package org.apache.commons.rng.simple.internal;
import org.apache.commons.rng.core.source64.SplitMix64;
import org.apache.commons.rng.simple.internal.ProviderBuilder.RandomSourceInternal;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import java.util.EnumMap;
+import java.util.function.Supplier;
/**
* Tests for the {@link ProviderBuilder.RandomSourceInternal} seed conversions. This test
@@ -136,9 +137,9 @@ public class RandomSourceInternalParametricTest {
@Test
public void testCreateSeed() {
final Object seed = randomSourceInternal.createSeed();
- Assert.assertNotNull(seed);
- Assert.assertEquals("Seed was not the correct class", type, seed.getClass());
- Assert.assertTrue("Seed was not identified as the native type", randomSourceInternal.isNativeSeed(seed));
+ Assertions.assertNotNull(seed);
+ Assertions.assertEquals(type, seed.getClass(), "Seed was not the correct class");
+ Assertions.assertTrue(randomSourceInternal.isNativeSeed(seed), "Seed was not identified as the native type");
}
/**
@@ -148,10 +149,10 @@ public class RandomSourceInternalParametricTest {
public void testConvertSupportedSeed() {
for (final Object input : SUPPORTED_SEEDS) {
final Object seed = randomSourceInternal.convertSeed(input);
- final String msg = input.getClass() + " input seed was not converted";
- Assert.assertNotNull(msg, seed);
- Assert.assertEquals(msg, type, seed.getClass());
- Assert.assertTrue(msg, randomSourceInternal.isNativeSeed(seed));
+ final Supplier<String> msg = () -> input.getClass() + " input seed was not converted";
+ Assertions.assertNotNull(seed, msg);
+ Assertions.assertEquals(type, seed.getClass(), msg);
+ Assertions.assertTrue(randomSourceInternal.isNativeSeed(seed), msg);
}
}
@@ -163,7 +164,7 @@ public class RandomSourceInternalParametricTest {
for (final Object input : UNSUPPORTED_SEEDS) {
try {
randomSourceInternal.convertSeed(input);
- Assert.fail(input.getClass() + " input seed was not rejected as unsupported");
+ Assertions.fail(input.getClass() + " input seed was not rejected as unsupported");
} catch (UnsupportedOperationException ex) {
// This is expected
}
@@ -180,18 +181,18 @@ public class RandomSourceInternalParametricTest {
final byte[] seed = randomSourceInternal.createSeedBytes(new SplitMix64(12345L));
final int size = seed.length;
- Assert.assertNotEquals("Seed is empty", 0, size);
+ Assertions.assertNotEquals(0, size, "Seed is empty");
if (randomSourceInternal.isNativeSeed(Integer.valueOf(0))) {
- Assert.assertEquals("Expect 4 bytes for Integer", 4, size);
+ Assertions.assertEquals(4, size, "Expect 4 bytes for Integer");
} else if (randomSourceInternal.isNativeSeed(Long.valueOf(0))) {
- Assert.assertEquals("Expect 8 bytes for Long", 8, size);
+ Assertions.assertEquals(8, size, "Expect 8 bytes for Long");
} else if (randomSourceInternal.isNativeSeed(new int[0])) {
- Assert.assertEquals("Expect 4n bytes for int[]", 0, size % 4);
+ Assertions.assertEquals(0, size % 4, "Expect 4n bytes for int[]");
} else if (randomSourceInternal.isNativeSeed(new long[0])) {
- Assert.assertEquals("Expect 8n bytes for long[]", 0, size % 8);
+ Assertions.assertEquals(0, size % 8, "Expect 8n bytes for long[]");
} else {
- Assert.fail("Unknown native seed type");
+ Assertions.fail("Unknown native seed type");
}
}
@@ -210,8 +211,7 @@ public class RandomSourceInternalParametricTest {
final int size = seed.length;
final Integer expected = EXPECTED_SEED_BYTES.get(randomSourceInternal);
- Assert.assertNotNull("Missing expected seed byte size: " + randomSourceInternal, expected);
- Assert.assertEquals(randomSourceInternal.toString(),
- expected.intValue(), size);
+ Assertions.assertNotNull(expected, () -> "Missing expected seed byte size: " + randomSourceInternal);
+ Assertions.assertEquals(expected.intValue(), size, () -> randomSourceInternal.toString());
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedConverterComposerTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedConverterComposerTest.java
index 3554dba..ea3a838 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedConverterComposerTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedConverterComposerTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.rng.simple.internal;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
/**
@@ -31,7 +31,7 @@ public class SeedConverterComposerTest {
new SeedConverterComposer<Integer, Long, long[]>(int2Long, long2LongArray);
final Integer in = 123;
final Object out = composer.convert(in);
- Assert.assertTrue("Bad type conversion", out instanceof long[]);
- Assert.assertEquals("Incorrect long[] length", 3, ((long[])out).length);
+ Assertions.assertTrue(out instanceof long[], "Bad type conversion");
+ Assertions.assertEquals(3, ((long[])out).length, "Incorrect long[] length");
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedFactoryTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedFactoryTest.java
index b936d81..ab6fe36 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedFactoryTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedFactoryTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.rng.simple.internal;
import java.util.Map;
import java.util.HashMap;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.core.source32.IntProvider;
@@ -54,7 +54,7 @@ public class SeedFactoryTest {
final int n = 100000;
final long[] array = SeedFactory.createLongArray(n);
- Assert.assertEquals(n, array.length);
+ Assertions.assertEquals(n, array.length);
for (long v : array) {
Integer count = values.get(v);
@@ -109,7 +109,7 @@ public class SeedFactoryTest {
}
if (duplicates > 0) {
- Assert.fail(duplicates + " duplicates\n" + sb);
+ Assertions.fail(duplicates + " duplicates\n" + sb);
}
}
@@ -134,7 +134,7 @@ public class SeedFactoryTest {
*/
private static void assertCreateIntArray(int n) {
final int[] array = SeedFactory.createIntArray(n);
- Assert.assertEquals("Incorrect array length", n, array.length);
+ Assertions.assertEquals(n, array.length, "Incorrect array length");
// The bit count should be 50%.
int bitCount = 0;
for (final int i : array) {
@@ -165,7 +165,7 @@ public class SeedFactoryTest {
*/
private static void assertCreateLongArray(int n) {
final long[] array = SeedFactory.createLongArray(n);
- Assert.assertEquals("Incorrect array length", n, array.length);
+ Assertions.assertEquals(n, array.length, "Incorrect array length");
// The bit count should be 50%.
int bitCount = 0;
for (final long i : array) {
@@ -201,10 +201,10 @@ public class SeedFactoryTest {
// (Re-runs are not configured for this test.)
final double absSum = Math.abs(sum);
final double max = Math.sqrt(numberOfBits) * 3.891;
- Assert.assertTrue("Walked too far astray: " + absSum +
- " > " + max +
- " (test will fail randomly about 1 in 10,000 times)",
- absSum <= max);
+ Assertions.assertTrue(absSum <= max,
+ () -> "Walked too far astray: " + absSum +
+ " > " + max +
+ " (test will fail randomly about 1 in 10,000 times)");
}
@Test
@@ -233,7 +233,7 @@ public class SeedFactoryTest {
final UniformRandomProvider rng = new IntProvider() {
@Override
public int next() {
- Assert.fail("This method should not be used");
+ Assertions.fail("This method should not be used");
return 0;
}
@@ -244,7 +244,7 @@ public class SeedFactoryTest {
};
final byte[] seed = SeedFactory.createByteArray(rng, expected.length);
- Assert.assertArrayEquals(expected, seed);
+ Assertions.assertArrayEquals(expected, seed);
}
@Test
@@ -258,9 +258,9 @@ public class SeedFactoryTest {
};
// Test the method only replaces position 0
final byte[] seed = SeedFactory.createByteArray(rng, 4);
- Assert.assertNotEquals("Zero at position 0 should be modified", 0, seed[0]);
+ Assertions.assertNotEquals(0, seed[0], "Zero at position 0 should be modified");
for (int i = 1; i < seed.length; i++) {
- Assert.assertEquals("Position above 0 should be unmodified", 0, seed[i]);
+ Assertions.assertEquals(0, seed[i], "Position above 0 should be unmodified");
}
}
@@ -278,9 +278,9 @@ public class SeedFactoryTest {
final int[] seed = new int[] {position0, 0, 0, 0};
final int[] before = seed.clone();
SeedFactory.ensureNonZero(seed);
- Assert.assertEquals("Non-zero at position 0 should be unmodified", position0, seed[0]);
+ Assertions.assertEquals(position0, seed[0], "Non-zero at position 0 should be unmodified");
for (int i = 1; i < seed.length; i++) {
- Assert.assertEquals("Position above 0 should be unmodified", before[i], seed[i]);
+ Assertions.assertEquals(before[i], seed[i], "Position above 0 should be unmodified");
}
}
@@ -290,9 +290,9 @@ public class SeedFactoryTest {
final int[] seed = new int[] {0, 123, 456, 789};
final int[] before = seed.clone();
SeedFactory.ensureNonZero(seed);
- Assert.assertNotEquals("Zero at position 0 should be modified", 0, seed[0]);
+ Assertions.assertNotEquals(0, seed[0], "Zero at position 0 should be modified");
for (int i = 1; i < seed.length; i++) {
- Assert.assertEquals("Position above 0 should be unmodified", before[i], seed[i]);
+ Assertions.assertEquals(before[i], seed[i], "Position above 0 should be unmodified");
}
}
@@ -310,9 +310,9 @@ public class SeedFactoryTest {
final long[] seed = new long[] {position0, 0, 0, 0};
final long[] before = seed.clone();
SeedFactory.ensureNonZero(seed);
- Assert.assertEquals("Non-zero at position 0 should be unmodified", position0, seed[0]);
+ Assertions.assertEquals(position0, seed[0], "Non-zero at position 0 should be unmodified");
for (int i = 1; i < seed.length; i++) {
- Assert.assertEquals("Position above 0 should be unmodified", before[i], seed[i]);
+ Assertions.assertEquals(before[i], seed[i], "Position above 0 should be unmodified");
}
}
@@ -322,9 +322,9 @@ public class SeedFactoryTest {
final long[] seed = new long[] {0, 123, 456, 789};
final long[] before = seed.clone();
SeedFactory.ensureNonZero(seed);
- Assert.assertNotEquals("Zero at position 0 should be modified", 0, seed[0]);
+ Assertions.assertNotEquals(0, seed[0], "Zero at position 0 should be modified");
for (int i = 1; i < seed.length; i++) {
- Assert.assertEquals("Position above 0 should be unmodified", before[i], seed[i]);
+ Assertions.assertEquals(before[i], seed[i], "Position above 0 should be unmodified");
}
}
@@ -337,11 +337,11 @@ public class SeedFactoryTest {
return expected;
}
};
- Assert.assertEquals("Zero should be replaced using the random source",
- expected, SeedFactory.ensureNonZero(source, 0));
+ Assertions.assertEquals(expected, SeedFactory.ensureNonZero(source, 0),
+ "Zero should be replaced using the random source");
for (final long nonZero : new long[] {Long.MIN_VALUE, -1, 1, 9876654321L, Long.MAX_VALUE}) {
- Assert.assertEquals("Non-zero should be unmodified",
- nonZero, SeedFactory.ensureNonZero(source, nonZero));
+ Assertions.assertEquals(nonZero, SeedFactory.ensureNonZero(source, nonZero),
+ "Non-zero should be unmodified");
}
}
}
diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedUtilsTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedUtilsTest.java
index 412cc8c..d14373e 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedUtilsTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedUtilsTest.java
@@ -20,7 +20,7 @@ package org.apache.commons.rng.simple.internal;
import org.apache.commons.math3.stat.inference.ChiSquareTest;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.core.source64.SplitMix64;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.junit.Test;
import java.util.Arrays;
@@ -43,7 +43,7 @@ public class SeedUtilsTest {
int observed = 0;
for (int j = 0; j < 8; j++) {
final int digit = sample & 0xf;
- Assert.assertEquals("Duplicate digit in sample", 0, observed & (1 << digit));
+ Assertions.assertEquals(0, observed & (1 << digit), "Duplicate digit in sample");
observed |= 1 << digit;
samples[j][digit]++;
sample >>>= 4;
@@ -55,8 +55,8 @@ public class SeedUtilsTest {
Arrays.fill(expected, 1.0 / 16);
// Pass if we cannot reject null hypothesis that distributions are the same.
for (int j = 0; j < 8; j++) {
- Assert.assertFalse("Not uniform in digit " + j,
- chiSquareTest.chiSquareTest(expected, samples[j], 0.001));
+ Assertions.assertFalse(chiSquareTest.chiSquareTest(expected, samples[j], 0.001),
+ "Not uniform in digit " + j);
}
}
@@ -76,7 +76,7 @@ public class SeedUtilsTest {
long observed = 0;
for (int j = 0; j < 8; j++) {
final int digit = (int) (sample & 0xfL);
- Assert.assertEquals("Duplicate digit in lower sample", 0, observed & (1 << digit));
+ Assertions.assertEquals(0, observed & (1 << digit), "Duplicate digit in lower sample");
observed |= 1 << digit;
samples[j][digit]++;
sample >>>= 4;
@@ -85,7 +85,7 @@ public class SeedUtilsTest {
observed = 0;
for (int j = 8; j < 16; j++) {
final int digit = (int) (sample & 0xfL);
- Assert.assertEquals("Duplicate digit in upper sample", 0, observed & (1 << digit));
+ Assertions.assertEquals(0, observed & (1 << digit), "Duplicate digit in upper sample");
observed |= 1 << digit;
samples[j][digit]++;
sample >>>= 4;
@@ -97,8 +97,8 @@ public class SeedUtilsTest {
Arrays.fill(expected, 1.0 / 16);
// Pass if we cannot reject null hypothesis that distributions are the same.
for (int j = 0; j < 16; j++) {
- Assert.assertFalse("Not uniform in digit " + j,
- chiSquareTest.chiSquareTest(expected, samples[j], 0.001));
+ Assertions.assertFalse(chiSquareTest.chiSquareTest(expected, samples[j], 0.001),
+ "Not uniform in digit " + j);
}
}
}