Created
April 1, 2014 17:19
-
-
Save gfredericks/9918722 to your computer and use it in GitHub Desktop.
Example use of the hypothetical gen/for for test.check.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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