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

choose-with-frequencies only chooses the first generator (or runs forever) #33

Open
default-kramer opened this issue Apr 8, 2019 · 2 comments

Comments

@default-kramer
Copy link
Contributor

I might be misunderstanding what choose-with-frequencies does. I was trying to make a generator that produces integers or symbols at random. I did this:

#lang racket
(require quickcheck)

(define (gen-datum)
  (choose-with-frequencies
   (list
    (cons 1 (choose-integer 100 200))
    (cons 99 (choose-symbol choose-printable-ascii-char 10)))))

(quickcheck
 (property ([x (gen-datum)])
           (println x)
           #t))

But I get 100 integers, followed by "OK, passed 100 tests."

Also, if I reduce the frequency of the first option to 0, it runs forever.

Is this expected? Is it possible to make a generator that produces different kinds of values randomly?

@ausimian
Copy link

ausimian commented Mar 11, 2020

I just ran into this problem, the issue is a bug in the pick function where the recursive call fails to pass the cdr of the generator list, so ultimately always picks the first one. It also explains why passing 0 as the first frequency causes an infinite loop.

[Edit - I'll submit a PR]

@ausimian
Copy link

#37

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