Try to eliminate random failures which did happen on GH with a 100 limit
This commit is contained in:
parent
8168aa2bc1
commit
6000dd8a3c
|
@ -37,10 +37,12 @@ import java.util.Random;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.RandomStringUtils}.
|
||||
* Tests {@link org.apache.commons.lang3.RandomStringUtils}.
|
||||
*/
|
||||
public class RandomStringUtilsTest extends AbstractLangTest {
|
||||
|
||||
private static final int LOOP_COUNT = 1_000;
|
||||
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new RandomStringUtils());
|
||||
|
@ -195,7 +197,7 @@ public class RandomStringUtilsTest extends AbstractLangTest {
|
|||
public void testRandomAlphaNumeric() {
|
||||
final char[] testChars = {'a', 'z', 'A', 'Z', '0', '9'};
|
||||
final boolean[] found = {false, false, false, false, false, false};
|
||||
for (int i = 0; i < 100; i++) {
|
||||
for (int i = 0; i < LOOP_COUNT; i++) {
|
||||
final String randString = RandomStringUtils.randomAlphanumeric(10);
|
||||
for (int j = 0; j < testChars.length; j++) {
|
||||
if (randString.indexOf(testChars[j]) > 0) {
|
||||
|
@ -218,7 +220,7 @@ public class RandomStringUtilsTest extends AbstractLangTest {
|
|||
public void testRandomNumeric() {
|
||||
final char[] testChars = {'0', '9'};
|
||||
final boolean[] found = {false, false};
|
||||
for (int i = 0; i < 100; i++) {
|
||||
for (int i = 0; i < LOOP_COUNT; i++) {
|
||||
final String randString = RandomStringUtils.randomNumeric(10);
|
||||
for (int j = 0; j < testChars.length; j++) {
|
||||
if (randString.indexOf(testChars[j]) > 0) {
|
||||
|
@ -241,7 +243,7 @@ public class RandomStringUtilsTest extends AbstractLangTest {
|
|||
public void testRandomAlphabetic() {
|
||||
final char[] testChars = {'a', 'z', 'A', 'Z'};
|
||||
final boolean[] found = {false, false, false, false};
|
||||
for (int i = 0; i < 100; i++) {
|
||||
for (int i = 0; i < LOOP_COUNT; i++) {
|
||||
final String randString = RandomStringUtils.randomAlphabetic(10);
|
||||
for (int j = 0; j < testChars.length; j++) {
|
||||
if (randString.indexOf(testChars[j]) > 0) {
|
||||
|
@ -265,7 +267,7 @@ public class RandomStringUtilsTest extends AbstractLangTest {
|
|||
final char[] testChars = {(char) 32, (char) 126};
|
||||
final boolean[] found = {false, false};
|
||||
// Test failures have been observed on GitHub builds with a 100 limit.
|
||||
for (int i = 0; i < 1_000; i++) {
|
||||
for (int i = 0; i < LOOP_COUNT; i++) {
|
||||
final String randString = RandomStringUtils.randomAscii(10);
|
||||
for (int j = 0; j < testChars.length; j++) {
|
||||
if (randString.indexOf(testChars[j]) > 0) {
|
||||
|
@ -288,7 +290,7 @@ public class RandomStringUtilsTest extends AbstractLangTest {
|
|||
|
||||
int maxCreatedLength = expectedMinLengthInclusive;
|
||||
int minCreatedLength = expectedMaxLengthExclusive - 1;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
for (int i = 0; i < LOOP_COUNT; i++) {
|
||||
final String s = RandomStringUtils.randomAscii(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
||||
assertTrue(s.matches(pattern), s);
|
||||
|
@ -313,7 +315,7 @@ public class RandomStringUtilsTest extends AbstractLangTest {
|
|||
|
||||
int maxCreatedLength = expectedMinLengthInclusive;
|
||||
int minCreatedLength = expectedMaxLengthExclusive - 1;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
for (int i = 0; i < LOOP_COUNT; i++) {
|
||||
final String s = RandomStringUtils.randomAlphabetic(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
||||
assertTrue(s.matches(pattern), s);
|
||||
|
@ -338,7 +340,7 @@ public class RandomStringUtilsTest extends AbstractLangTest {
|
|||
|
||||
int maxCreatedLength = expectedMinLengthInclusive;
|
||||
int minCreatedLength = expectedMaxLengthExclusive - 1;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
for (int i = 0; i < LOOP_COUNT; i++) {
|
||||
final String s = RandomStringUtils.randomAlphanumeric(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
||||
assertTrue(s.matches(pattern), s);
|
||||
|
@ -363,7 +365,7 @@ public class RandomStringUtilsTest extends AbstractLangTest {
|
|||
|
||||
int maxCreatedLength = expectedMinLengthInclusive;
|
||||
int minCreatedLength = expectedMaxLengthExclusive - 1;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
for (int i = 0; i < LOOP_COUNT; i++) {
|
||||
final String s = RandomStringUtils.randomGraph(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
||||
assertTrue(s.matches(pattern), s);
|
||||
|
@ -388,7 +390,7 @@ public class RandomStringUtilsTest extends AbstractLangTest {
|
|||
|
||||
int maxCreatedLength = expectedMinLengthInclusive;
|
||||
int minCreatedLength = expectedMaxLengthExclusive - 1;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
for (int i = 0; i < LOOP_COUNT; i++) {
|
||||
final String s = RandomStringUtils.randomNumeric(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
||||
assertTrue(s.matches(pattern), s);
|
||||
|
@ -413,7 +415,7 @@ public class RandomStringUtilsTest extends AbstractLangTest {
|
|||
|
||||
int maxCreatedLength = expectedMinLengthInclusive;
|
||||
int minCreatedLength = expectedMaxLengthExclusive - 1;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
for (int i = 0; i < LOOP_COUNT; i++) {
|
||||
final String s = RandomStringUtils.randomPrint(expectedMinLengthInclusive, expectedMaxLengthExclusive);
|
||||
assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1)));
|
||||
assertTrue(s.matches(pattern), s);
|
||||
|
@ -433,7 +435,7 @@ public class RandomStringUtilsTest extends AbstractLangTest {
|
|||
/**
|
||||
* Test homogeneity of random strings generated --
|
||||
* i.e., test that characters show up with expected frequencies
|
||||
* in generated strings. Will fail randomly about 1 in 1000 times.
|
||||
* in generated strings. Will fail randomly about 1 in LOOP_COUNT times.
|
||||
* Repeated failures indicate a problem.
|
||||
*/
|
||||
@Test
|
||||
|
@ -443,7 +445,8 @@ public class RandomStringUtilsTest extends AbstractLangTest {
|
|||
String gen = "";
|
||||
final int[] counts = {0, 0, 0};
|
||||
final int[] expected = {200, 200, 200};
|
||||
for (int i = 0; i< 100; i++) {
|
||||
// More likely to fail for 1000?
|
||||
for (int i = 0; i < 100; i++) {
|
||||
gen = RandomStringUtils.random(6, chars);
|
||||
for (int j = 0; j < 6; j++) {
|
||||
switch (gen.charAt(j)) {
|
||||
|
|
Loading…
Reference in New Issue