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

WIP: Deterministic and varied pure/impure fn gen #1042

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

frenchy64
Copy link
Contributor

@frenchy64 frenchy64 commented Apr 18, 2024

Close #1039

FWIW I haven't worked out how to make functions shrinkable.

The implementation can be further simplified by using the private gen/randomized function instead of seeded. That might fix the babashka tests.

;; This sequence of results should be reproducible.
(def pure   (mg/generate [:=>                    [:cat :int] :int] {:seed 0 :size 10}))
(def impure (mg/generate [:=> {:gen/impure true} [:cat :int] :int] {:seed 0 :size 10}))
(repeatedly 10 #(pure 2))
;=> (-106 -106 -106 -106 -106 -106 -106 -106 -106 -106)
(repeatedly 10 #(pure 2))
;=> (-106 -106 -106 -106 -106 -106 -106 -106 -106 -106)
(repeatedly 10 #(impure 2))
;=> (0 -1 0 -3 0 1 16 0 7 3)
(repeatedly 10 #(impure 2))
;=> (0 -1 -1 1 2 3 -2 38 -5 -12)

(mapv pure (range 10))
;=> [5 511 -106 20 -51 -322 1 0 434 -1]
(mapv pure (range 10))
;=> [5 511 -106 20 -51 -322 1 0 434 -1]
(mapv impure (range 10))
;=> [-1 0 -2 -4 -3 -4 -15 -15 -16 -2]
(mapv impure (range 10))
;=> [-1 -1 -1 0 1 3 -12 30 -2 1]

@frenchy64 frenchy64 changed the title WIP: Deterministic and varied pure/impure fn gen WIP: Varied pure/impure fn gen Apr 18, 2024
@frenchy64 frenchy64 changed the title WIP: Varied pure/impure fn gen WIP: Deterministic and varied pure/impure fn gen Apr 18, 2024
@frenchy64 frenchy64 mentioned this pull request May 2, 2024
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

Successfully merging this pull request may close these issues.

Function generators return constant function if seed provided
1 participant