Skip to content
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

Add specific values to generator. #27

Open
jockbert opened this issue Oct 2, 2017 · 1 comment
Open

Add specific values to generator. #27

jockbert opened this issue Oct 2, 2017 · 1 comment

Comments

@jockbert
Copy link

jockbert commented Oct 2, 2017

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
Copy link
Contributor

hcoles commented Oct 2, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants