Skip to content

Commit

Permalink
Fixed string shrinking bug #541
Browse files Browse the repository at this point in the history
  • Loading branch information
jlink committed Dec 8, 2023
1 parent b964e65 commit c779a9d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ private boolean hasSingleCharEdgeCases() {
}

private EdgeCases<String> emptyStringEdgeCase() {
return EdgeCases.fromSupplier(() -> new ShrinkableString(Collections.emptyList(), minLength, maxLength(), characterArbitrary));
return EdgeCases.fromSupplier(() -> new ShrinkableString(Collections.emptyList(), minLength, maxLength(), characterArbitrary, uniqueChars));
}

private EdgeCases<String> fixedSizedEdgeCases(int fixedSize, int maxEdgeCases) {
return EdgeCasesSupport.mapShrinkable(
effectiveCharacterArbitrary().edgeCases(maxEdgeCases),
shrinkableChar -> {
List<Shrinkable<Character>> shrinkableChars = new ArrayList<>(Collections.nCopies(fixedSize, shrinkableChar));
return new ShrinkableString(shrinkableChars, minLength, maxLength(), characterArbitrary);
return new ShrinkableString(shrinkableChars, minLength, maxLength(), characterArbitrary, uniqueChars);
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public static RandomGenerator<String> strings(
Arbitrary<Character> characterArbitrary,
boolean uniqueChars
) {
Function<List<Shrinkable<Character>>, Shrinkable<String>> createShrinkable = elements -> new ShrinkableString(elements, minLength, maxLength, characterArbitrary, false);
Set<FeatureExtractor<Character>> featureExtractors = uniqueChars ? Collections.singleton(FeatureExtractor.identity()) : Collections.emptySet();
Function<List<Shrinkable<Character>>, Shrinkable<String>> createShrinkable = elements -> new ShrinkableString(elements, minLength, maxLength, characterArbitrary, uniqueChars);
Set<FeatureExtractor<Character>> featureExtractors = uniqueChars ? ShrinkableString.UNIQUE_CHARS_EXTRACTOR : Collections.emptySet();
return container(elementGenerator, createShrinkable, minLength, maxLength, maxUniqueChars, genSize, lengthDistribution, featureExtractors);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void uniqueCharsWithImpossibleLength(@ForAll Random random) {
}

@Group
@PropertyDefaults(tries = 100)
@PropertyDefaults(tries = 10)
class Shrinking {

@Property
Expand All @@ -345,15 +345,15 @@ void alpha3IsShrunkToTripleA(@ForAll Random random) {
);
}

// @Property // Currently failing
@Property
void alpha3UniqueCharsIsShrunkToABC(@ForAll Random random) {
StringArbitrary arbitrary =
Arbitraries.strings().alpha().uniqueChars().ofLength(3);
assertAllValuesAreShrunkTo(arbitrary, random, "ABC");

assertWhileShrinking(
random, arbitrary,
s -> s.length() == 3 && s.chars().allMatch(c -> c >= 'A' && c <= 'z')
s -> s.length() == 3 && s.chars().distinct().count() == 3
);
}

Expand Down

0 comments on commit c779a9d

Please sign in to comment.