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
Filtering list by minimum length fails when used in a property #139
Comments
For such cases, I usually build a generator that creates the first two elements and appends a possibly empty list of elements. This has the advantage that it always succeeds, so the constraint will never fail. Example: def at_least_two_integers do
let [first <- integer(), second <- integer(), many <- list(integer())], do:
[first, second | many]
end This can then be used in property "all integers" do
forall ints <- at_least_two_integers() do
Enum.all?(ints, &is_integer/1)
end
end |
But I also wonder why |
Thank you @evnu! I'd tried a similar approach, but the thing I was missing was |
No, sorry, not yet. But I can confirm, that it behaves exactly the same for me. Very annoying, at least, if not a wrong implementation, some how. |
It behaves that way, because it tries to generate instances of lists of size from 0 to 1 (default value of |
Thanks @x4lldux – good explanation. |
Indeed, this solves this puzzle. We need to document that behaviour. I was totally not aware of this. |
@alfert it kinda already is. Might be clearer, though.
|
Firstly, I'm new to both property-based testing and this library, so apologies if this is user error.
I'm trying to write a property for something that's only applicable to lists with at least two elements, but I can't seem to generate values for the test. Here's a reduced example:
When I run it, I get a "can't generate" error:
However, when I paste the same code into iex, it seems to work:
This is with propcheck 1.2.0, proper 1.3.0, elixir 1.9.4 and erlang 22.1.0, running on macOS 10.15.1.
The text was updated successfully, but these errors were encountered: