Skip to content

Instantly share code, notes, and snippets.

@gfredericks
Created April 1, 2014 17:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfredericks/9918722 to your computer and use it in GitHub Desktop.
Save gfredericks/9918722 to your computer and use it in GitHub Desktop.
Example use of the hypothetical gen/for for test.check.
(defn gen-subset
"Generates an even-cardinality subset of the given elements"
[elements]
(gen/for [bools (apply gen/tuple (repeat (count elements) gen/boolean))
:let [true-count (->> bools (filter identity) (count))]
:when (even? true-count)]
(->> (map list bools elements)
(filter first)
(map second)
(set))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment