Last active
November 27, 2018 15:10
-
-
Save minimal/40085951c277d8ce26ad to your computer and use it in GitHub Desktop.
testing monoids with 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 passes-monoid-props | |
[f id a b c] | |
(and (= (f (f a b) c) (f a (f b c))) ;; associativity | |
(= (f a id) a) ;; identity element | |
(= (f id a) a))) | |
(defspec plus-zero-are-monoid 100 | |
(prop/for-all [[a b c] (gen/vector gen/int 3)] | |
(passes-monoid-props + 0 a b c))) | |
(defspec *-1-are-monoid 100 | |
(prop/for-all [[a b c] (gen/vector gen/int 3)] | |
(passes-monoid-props * 1 a b c))) | |
(defspec concat-emptyvec-are-monoid 50 | |
(prop/for-all [[a b c] (gen/vector (gen/vector gen/any 5) 3)] | |
(passes-monoid-props concat [] a b c))) | |
(defspec intersection-set-are-monoid 50 | |
(prop/for-all [[a b c] (gen/vector (gen/fmap set (gen/vector gen/any-printable 5)) | |
3)] | |
(passes-monoid-props clojure.set/intersection a a b c))) | |
(defspec union-empty-set-are-monoid 50 | |
(prop/for-all [[a b c] (gen/vector (gen/fmap set (gen/vector gen/any-printable 5)) | |
3)] | |
(passes-monoid-props clojure.set/union #{} a b c))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment