Skip to content

Instantly share code, notes, and snippets.

@sritchie
Created November 7, 2013 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sritchie/7348015 to your computer and use it in GitHub Desktop.
Save sritchie/7348015 to your computer and use it in GitHub Desktop.
(defn monoid-laws [zero g f]
(testing "+ and 0 form a monoid"
(is (let [p (prop/for-all [a g, b g, c g]
(and (= (f zero a) a)
(= (f a zero) a)
(= (f a (f b c)) (f (f a b) c))))]
(:result (sc/quick-check 1000 p))))))
(deftest int-monoid-laws
(monoid-laws 0 gen/int +))
(deftest ratio-monoid-laws
(monoid-laws 0 gen/ratio +))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment