-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Arbitrary.size as an option to tweak during arbitrary construction. #494
Comments
Can you shortly describe what effect you'd like to get by re-sizing arbitraries/generators based on previous value? In jqwik the |
@jlink in a library of mine for generating regex-conforming strings, I want an arbitrary to respect the size argument. But to access the size the only way for me is to implement an Arbitrary interface (here) But this is what the jqwik doc has to say about this:
So I'm just trying to do the right thing. |
Very much appreciated. Two possibilities I see:
Both take care of many constraints. |
@jlink I do use decorator for the most part. Unfortunately it and the other option still don't give access to size. Size is only surfaced in |
UPD I guess |
Maybe the combination is worthwhile looking at. A sketch: class SizedArbitrary implements ArbitraryDecorator<String> {
private int size;
SizedArbitrary(int size) { this.size = size; }
Arbitrary<String> arbitrary() {
return Arbitraries.fromGenerator(new MyGenerator(size));
}
} |
@jlink thank you, and that will essentially fix the size to some value. It's a bit different from what I'm trying to achieve. I want the size to grow with every new iteration like you described - every new trial gives you a greater size and therefore you start by exploring smaller values slowly expanding it further. You can't achieve that via arbitrary configuration because that would be static. |
I assumed that - since it's how QuickCheck's generators basically work. One of the problems is that if you did that generators would accumulate state and therefore no longer show deterministic generation behaviour when given the same random seed. QuickCheck and kin solve that by having |
@jlink not sure I follow you line of thought here. I'm not suggesting you to change existing random generators. If they work fine without the size that's alright. Though built-in container like types are already utilizing genSize internally: https://github.com/jqwik-team/jqwik/blob/main/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/ContainerGenerator.java#L11. This is applicable to string types as well. So, why can't custom user-provided generators do that? To modify your example a little. I want my custom generator to be defined like this: Arbitraries.size().flatMap(size -> Arbitraries.fromGenerator(new MyGenerator(size)))
// or maybe
Arbitraries.fromGenerator(size -> new MyGenerator(size))) To me, size is essentially an |
I’ve probably rambled too much in the theory of value generation and looked too little into what you want to achieve. :-/
Sure they can. My point: In existing generators
That seems to make a lot of sense and I’m wondering why I left out the |
@SimY4 Had another look at it and cannot see any valid argument against |
@jlink yes, very much so. Thank you |
Starting work on this feature in |
First obstacle: The method cannot be called Using |
@jlink I was actually thinking of proposing |
Seems like a very generic name at first glance. Have to think about that. |
@SimY4 Having slept over it, Names I've considered: More ideas? Favourites? |
@jlink I like the inclusion of the word size in the name since using a generic functional interface there won't actually help to realize that int argument is size. I would vote for the last option of yours. |
Adding a postfix to the original method seems reasonable. Three options remaining:
|
@jlink any way works for me |
I have decided on |
Available in |
Support for
Arbitraries.size()
to access the current size and<A> Arbitraries.resize(int size, Arbitrary<A> arb)
for resizing the subsequent arbitrary.The text was updated successfully, but these errors were encountered: