Skip to content

Instantly share code, notes, and snippets.

@martintrojer
Created June 21, 2012 07:23
Show Gist options
  • Save martintrojer/2964379 to your computer and use it in GitHub Desktop.
Save martintrojer/2964379 to your computer and use it in GitHub Desktop.
Generative Testing
;; example from ScalaCheck
(ns string-tests
(:use clojure.test.generative))
(defspec startsWith
(partial map identity)
[^string a ^string b]
(assert (.startsWith (str a b) a)))
(defspec concatenate
(partial map identity)
[^string a ^string b]
(let [s (str a b)]
(assert (>= (.length s) (.length a)))
(assert (>= (.length s) (.length b)))))
(defspec substring
(partial map identity)
[^string a ^string b ^string c]
(let [s (str a b c)
al (.length a)
bl (.length b)]
(assert (= b (.substring s al (+ al bl))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment