Skip to content

Instantly share code, notes, and snippets.

@zcaudate
Created August 6, 2015 10:41
Show Gist options
  • Save zcaudate/f50595ae9da76d133421 to your computer and use it in GitHub Desktop.
Save zcaudate/f50595ae9da76d133421 to your computer and use it in GitHub Desktop.
generative testing
(defn count-elements [coll1 coll2]
(+ (count coll1) (count coll2) 1))
(defn count-elements-tester [f]
(let [n (rand-int 6)
m (rand-int 6)
output (+ n m)
inputs [(range n) (range m)]
actual (apply f inputs)]
(if (= actual output)
{:result :success}
{:result :error :inputs inputs :output output :actual actual})))
(filter #(-> % :result (= :error)) (map count-elements-tester (repeat 10 count-elements)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment