-
Notifications
You must be signed in to change notification settings - Fork 222
Fix recursive gen attempt 2 #677
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
Conversation
@ikitommi here's another shot at the recursive gen fix, all changes are in the generators ns. Still need a few more tests, but what do you think? |
I finally had time to read this through, looks really good as everything is resolved on the |
oh, missed the |
@ikitommi thanks for looking. Adding the test indeed revealed a bug, and I don't think my solution is general enough. Needs more thought. |
I think I figured it out--very subtle! Explained the reasoning in comments. I will try and improve the error message for infinite schemas, right now it's pretty confusing. |
Still needs more work. I broke something: the generation never goes more than 1 recursion in the example in the original issue: (mg/sample
[:schema {:registry {::cons [:maybe [:tuple pos-int? [:ref ::cons]]]}}
::cons]
{:size 30})
=> (nil [2 nil] [2 nil] [2 nil] [4 nil] [7 nil] [3 nil] nil [1 nil] nil [1 nil] [17 nil] [490 nil] [3444 nil] nil nil nil [20236 nil] nil nil [501 nil] nil [75 nil] [2703 nil] nil [14 nil] [237664 nil] nil [3733313 nil] [2 nil]) |
The problem was because caching does not take into account I will sleep on it. |
Thanks for working on this. |
b25966f
to
ddec795
Compare
Also fixes problems with the :string and :vector generators, where if you only provided a minimum size, the maximum was set to (* 2 min). Using gen/sized to calculate the maximum yields generators with better distributions.
ddec795
to
31837ca
Compare
@ikitommi thanks. If you're happy with it, please merge. Happy to address any feedback.
There's one optional tweak that users can make to their schemas to optimize their generators---I've added that to the README. Completely optional though. The only people required to make changes is anyone that has created their own schemas that use |
This PR is superb in all ways I think of - it solves a hard problem in an elegant way with easy-to-follow explanation of what happens and why, lot of tests to verify it works correctly while keeping the code in the Big thanks @frenchy64! |
Close #452
Another attempt at #507