Last active
April 18, 2020 11:19
-
-
Save lagenorhynque/3b1f15000053e4eacbd717099b38d976 to your computer and use it in GitHub Desktop.
Speccing a higher-order function with clojure.spec (+ 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
dev> (require '[clojure.spec.alpha :as s] | |
'[clojure.spec.test.alpha :as stest]) | |
nil | |
dev> (defn twice [f x] | |
(f (f x))) | |
#'dev/twice | |
dev> (s/fdef twice | |
:args (s/cat :f (s/fspec :args (s/tuple integer?) | |
:ret integer?) | |
:x integer?) | |
:ret integer?) | |
dev/twice | |
dev> (stest/instrument `twice) | |
[dev/twice] | |
dev> (twice (comp inc #(doto % prn)) 0) | |
0 | |
0 | |
1 | |
0 | |
-2 | |
7 | |
14 | |
0 | |
-19 | |
-25 | |
-2 | |
99 | |
-7 | |
503 | |
-62 | |
-25 | |
-29 | |
-867 | |
129 | |
-46 | |
-1 | |
0 | |
1 | |
2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cf. https://github.com/lagenorhynque/everyday-life-with-clojure-spec
test.check is included as a dev dependency.