Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer generator outputs 0 very frequently #73

Open
eshioji opened this issue Aug 2, 2020 · 0 comments
Open

Integer generator outputs 0 very frequently #73

eshioji opened this issue Aug 2, 2020 · 0 comments

Comments

@eshioji
Copy link

eshioji commented Aug 2, 2020

The following code results in java.lang.IllegalStateException: Gave up after finding only 1 example(s) matching the assumptions, because the generators tend to generate empty arrays. Is this expected? Interestingly it seems to happen more often if I specify larger ranges like integers().between(0, 100), integers().between(0, 100) and less if I specify a smaller range like integers().between(0, 3).

@Test
void reproduce(){
    qt().forAll(stringArraysWithDefaultContent(), stringArraysWithDefaultContent())
            .assuming((x, y) -> {
                System.out.println(Arrays.toString(x) + ":" + Arrays.toString(y));
                return true;
            })
            .assuming((x, y) -> !Arrays.equals(x, y))
            .check((x, y) -> !Arrays.equals(x, y));
}

private static Gen<String[]> stringArraysWithDefaultContent() {
    return stringArrays(integers().between(0, 20), strings().allPossible().ofLengthBetween(0, 1));
}

private static Gen<String[]> stringArrays(Gen<Integer> sizes, Gen<String> contents) {
    Gen<String[]> gen = td -> {
        int size = sizes.generate(td);
        String[] ds = new String[size];
        for (int i = 0; i != size; i++) {
            ds[i] = contents.generate(td);
        }
        return ds;
    };
    return gen.describedAs(Arrays::toString);
}

The output of the snippet:

[, 㟔, , , , ?, 剜, , , ?, , ?, ]:[, Ⅾ, ?, , , ?, ?, ?, 翴, ?, ?, , ?, , , ?, , ?]
[]:[]
[]:[, , !, , , , , !, , , !, ]
[]:[]
[]:[]
[]:[]
[]:[]
[]:[]
[]:[]
[]:[]
[]:[]
[]:[]
[]:[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant