BAEL-3678 - Moving from java-numbers-2 to java-numbers-3 (#8521)

This commit is contained in:
aitorcuesta 2020-01-13 18:26:57 +01:00 committed by maibin
parent e10dc3cb9a
commit 4697561c51
4 changed files with 40 additions and 8 deletions

View File

@ -21,11 +21,6 @@
<artifactId>jmh-generator-annprocess</artifactId> <artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh-generator.version}</version> <version>${jmh-generator.version}</version>
</dependency> </dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>dsiutils</artifactId>
<version>2.6.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -13,6 +13,14 @@
<relativePath>../parent-java</relativePath> <relativePath>../parent-java</relativePath>
</parent> </parent>
<dependencies>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>dsiutils</artifactId>
<version>2.6.0</version>
</dependency>
</dependencies>
<build> <build>
<finalName>java-numbers-3</finalName> <finalName>java-numbers-3</finalName>
<resources> <resources>

View File

@ -70,12 +70,24 @@ public class RandomNumbersGenerator {
return randomWithSplittableRandom; return randomWithSplittableRandom;
} }
public IntStream generateRandomWithSplittableRandomLimitedIntStreamWithinARange(int min, int max, long streamSize) {
SplittableRandom splittableRandom = new SplittableRandom();
IntStream limitedIntStreamWithinARangeWithSplittableRandom = splittableRandom.ints(streamSize, min, max);
return limitedIntStreamWithinARangeWithSplittableRandom;
}
public Integer generateRandomWithSecureRandom() { public Integer generateRandomWithSecureRandom() {
SecureRandom secureRandom = new SecureRandom(); SecureRandom secureRandom = new SecureRandom();
int randomWithSecureRandom = secureRandom.nextInt(); int randomWithSecureRandom = secureRandom.nextInt();
return randomWithSecureRandom; return randomWithSecureRandom;
} }
public Integer generateRandomWithSecureRandomWithinARange(int min, int max) {
SecureRandom secureRandom = new SecureRandom();
int randomWithSecureRandomWithinARange = secureRandom.nextInt(max - min) + min;
return randomWithSecureRandomWithinARange;
}
public Integer generateRandomWithRandomDataGenerator(int min, int max) { public Integer generateRandomWithRandomDataGenerator(int min, int max) {
RandomDataGenerator randomDataGenerator = new RandomDataGenerator(); RandomDataGenerator randomDataGenerator = new RandomDataGenerator();
int randomWithRandomDataGenerator = randomDataGenerator.nextInt(min, max); int randomWithRandomDataGenerator = randomDataGenerator.nextInt(min, max);

View File

@ -11,6 +11,7 @@ public class RandomNumbersGeneratorUnitTest {
private static final int MIN_RANGE = 1; private static final int MIN_RANGE = 1;
private static final int MAX_RANGE = 10; private static final int MAX_RANGE = 10;
private static final int MIN_RANGE_NEGATIVE = -10;
private static final int ITERATIONS = 50; private static final int ITERATIONS = 50;
private static final long STREAM_SIZE = 50; private static final long STREAM_SIZE = 50;
@ -19,7 +20,7 @@ public class RandomNumbersGeneratorUnitTest {
RandomNumbersGenerator generator = new RandomNumbersGenerator(); RandomNumbersGenerator generator = new RandomNumbersGenerator();
for (int i = 0; i < ITERATIONS; i++) { for (int i = 0; i < ITERATIONS; i++) {
int randomNumer = generator.generateRandomWithMathRandom(MIN_RANGE, MAX_RANGE); int randomNumer = generator.generateRandomWithMathRandom(MIN_RANGE, MAX_RANGE);
assertTrue(isInRange(randomNumer, Integer.MIN_VALUE, Integer.MAX_VALUE)); assertTrue(isInRange(randomNumer, MIN_RANGE, MAX_RANGE));
} }
} }
@ -97,11 +98,18 @@ public class RandomNumbersGeneratorUnitTest {
public void whenGenerateRandomWithSplittableRandom_returnsSuccessfully() { public void whenGenerateRandomWithSplittableRandom_returnsSuccessfully() {
RandomNumbersGenerator generator = new RandomNumbersGenerator(); RandomNumbersGenerator generator = new RandomNumbersGenerator();
for (int i = 0; i < ITERATIONS; i++) { for (int i = 0; i < ITERATIONS; i++) {
int randomNumber = generator.generateRandomWithSplittableRandom(MIN_RANGE, MAX_RANGE); int randomNumber = generator.generateRandomWithSplittableRandom(MIN_RANGE_NEGATIVE, MAX_RANGE);
assertTrue(isInRange(randomNumber, MIN_RANGE, MAX_RANGE)); assertTrue(isInRange(randomNumber, MIN_RANGE_NEGATIVE, MAX_RANGE));
} }
} }
@Test
public void whenGenerateRandomWithSplittableRandomLimitedIntStreamWithinARange_returnsSuccessfully() {
RandomNumbersGenerator generator = new RandomNumbersGenerator();
generator.generateRandomWithSplittableRandomLimitedIntStreamWithinARange(MIN_RANGE, MAX_RANGE, STREAM_SIZE)
.forEach(randomNumber -> assertTrue(isInRange(randomNumber, MIN_RANGE, MAX_RANGE)));
}
@Test @Test
public void whenGenerateRandomWithSecureRandom_returnsSuccessfully() { public void whenGenerateRandomWithSecureRandom_returnsSuccessfully() {
RandomNumbersGenerator generator = new RandomNumbersGenerator(); RandomNumbersGenerator generator = new RandomNumbersGenerator();
@ -111,6 +119,15 @@ public class RandomNumbersGeneratorUnitTest {
} }
} }
@Test
public void whenGenerateRandomWithSecureRandomWithinARange_returnsSuccessfully() {
RandomNumbersGenerator generator = new RandomNumbersGenerator();
for (int i = 0; i < ITERATIONS; i++) {
int randomNumber = generator.generateRandomWithSecureRandomWithinARange(MIN_RANGE, MAX_RANGE);
assertTrue(isInRange(randomNumber, MIN_RANGE, MAX_RANGE));
}
}
@Test @Test
public void whenGenerateRandomWithRandomDataGenerator_returnsSuccessfully() { public void whenGenerateRandomWithRandomDataGenerator_returnsSuccessfully() {
RandomNumbersGenerator generator = new RandomNumbersGenerator(); RandomNumbersGenerator generator = new RandomNumbersGenerator();