Skip to content

Repeatead chars not working as expected #506

Closed
@esfomeado

Description

@esfomeado

Testing Problem

I had an issue where jqwik is generating duplicated values frequently which, for my example should almost never occur.

I have noticed that these duplicated values are always the same character e,g, AAAAAA so I decided to set the repeatedChars to 0 but this type of values are still generated. I have tried the other values but seems that there is no impact on the ammount of time a repeated char is used.

    @Test
    void bug() {
        StringArbitrary strings = Arbitraries.strings()
                .alpha()
                .ofMinLength(5)
                .ofMaxLength(25)
                .repeatChars(0);

        List<String> names = IntStream.range(0, 100)
                .mapToObj(i -> strings.sample())
                .toList();

        Map<String, Long> duplicateCount = names.stream()
                .filter(Objects::nonNull)
                .collect(Collectors.groupingBy(s -> s, Collectors.counting()));

        List<String> duplicateStrings = duplicateCount.entrySet().stream()
                .filter(entry -> entry.getValue() > 1)
                .map(Map.Entry::getKey)
                .collect(Collectors.toList());

        System.out.println("Duplicate strings: " + duplicateStrings);

        assertThat(duplicateStrings).isEmpty();
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions