quicktheories / QuickTheories

Property based testing for Java 8
Apache License 2.0
505 stars 51 forks source link

Add specific values to generator. #27

Open jockbert opened 7 years ago

jockbert commented 7 years ago

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.

hcoles commented 7 years ago

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.