QuickTheories icon indicating copy to clipboard operation
QuickTheories copied to clipboard

Add specific values to generator.

Open jockbert opened this issue 8 years ago • 1 comments

In release 0.15, you could do something like integers().between(1, 100).andAlwaysTheValues(2560) if you have implemented the interface WithQuickTheories

How do you do something similar in release 0.20? The method Gen<Integer>.andAlwaysTheValues(Integer) seem to have disapeared in release 0.20, and using integers().between(1, 100).mix(arbitrary().constant(2560)) does not give the same result.

jockbert avatar Oct 02 '17 10:10 jockbert

At the moment there isn't a way to do this in 0.20 - the way values are now generated makes this hard - it would require a way to convert from a given type to a long array that matches the precursor the generator would produce for that value.

This would be possible to do for some simple types such as integer, longs etc, but not generally possible.

I think the general solution would be something similar to what you tried with mix - it could perhaps be extended to allow the mixed generators to be weighted by differing amounts.

Allowing some deterministic behaviour (such as always generating certain values) caused unexpected issues in 0.15 (such as shrinking getting stuck in loops), so unless there is a strong use case I'd prefer to support mixing with a high probability of including a value rather than a guarantee.

hcoles avatar Oct 02 '17 11:10 hcoles