Closed
Description
A function exists which takes a list or an int, and contains a bug:
defmodule Demo do
def list_or_int(input) when is_list(input), do: Enum.count input
def list_or_int(input) when is_integer(input) and input > 0, do: -1
end
To test, we may do this:
test "returns a positive integer value" do
ptest input: choose(from: [list(of: positive_int(), min: 1), positive_int()]) do
result = Demo.list_or_int input
assert is_integer(result)
assert result > 0
end
end
When the value 1 is passed to list_or_int, it will return a negative number. quixir will then attempt to shrink the value, but will try 0 as a possible value despite the generator being declared as a positive_int().
If the test drops the choose clause like this:
test "returns a positive integer value" do
ptest input: list(of: positive_int(), min: 1) do
result = Demo.list_or_int input
assert is_integer(result)
assert result > 0
end
ptest input: positive_int() do
result = Demo.list_or_int input
assert is_integer(result)
assert result > 0
end
end
Then it works as expected.
It therefore appears to be the choose(..) clause causing the min/max boundaries for the generator to be lost.
Code to reproduce attached.
Metadata
Metadata
Assignees
Labels
No labels