Sorry for my long delay. I cannot reproduce your problem with the such_that operator. I did the following:
iex> use PropCheck
iex> produce(such_that l <- non_empty(list(number())), when: length(l) > 1)
{:ok,
[-10, -12.498990234832617, 26.565811750847487, -0.8553774801624835, -11.727179060408071, 11, 6, -6, 0, -18]}
iex> sample_shrink(such_that l <- non_empty(list(number())), when: length(l) > 1)
[-10.085757951113234,4,0.49263719097867137,-8.994420603636804,-4,-33,
-1.3484964548787592,-2,-28,0.772165396869481]
[-10.085757951113234,4,0.49263719097867137,-8.994420603636804,-4]
[-10.085757951113234,4,0.49263719097867137]
[4,0.49263719097867137]
[0,0.49263719097867137]
[0,21]
[0,0]
:ok
This would be the expected behaviour. Using the produce and sample_shrink helps to find bugs in the generators.
But your approach using
iex> sample_shrink([number() | non_empty(list(number))])
[-6,-129.9346393942964,1,9]
[0,-129.9346393942964,1,9]
[0,1,9]
[0,9]
[0,0]
:ok
works equally well: a list of generators is also a generator and will not shrink towards the empty list. The combination of generators works on the generator and not on the data level, therefore both generators must be present when shrinking.
Hope that explains the approach.
In your case, I would go for several generators:
def non_zero_number, do: such_that n <- number(), where: n != 0
def list_min_two(elem_gen), do:
such_that l <- non_empty(list(elem_gen() )), when: length(l) > 1
def safe_numbers, do: list_min_two(non_zero_number())
def numbers, do: list_min_two(number())
But I assume your approach is similar.
If this still fails, then please file a bug report on GitHub! In the best case, we have a documentation issue.






















