Last active
December 15, 2016 05:05
-
-
Save jclaggett/2446a199a6fb3c05250a0eb429d8fc79 to your computer and use it in GitHub Desktop.
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
(ns squarespec | |
(:require [clojure.spec :as s] | |
[clojure.spec.gen :as sgen] | |
[clojure.spec.test :as stest])) | |
;; Implementation | |
(defn square | |
"Define a square path given an origin and length." | |
[[x1 y1 :as origin] length] | |
(let [x2 (+ x1 length) | |
y2 (+ y1 length)] | |
[origin [x2 y1] [x2 y2] [x1 y2]])) | |
;; Specification | |
(s/def ::scalar | |
(s/or :int int? | |
:double (s/double-in :NaN? false :infinite? false))) | |
(s/def ::point | |
(s/coll-of ::scalar :kind sequential? :count 2)) | |
(s/def ::points | |
(s/coll-of ::point :kind sequential?)) | |
(s/fdef square | |
:args (s/cat :origin ::point :length ::scalar) | |
:ret ::points | |
:fn (fn [{[x1 y1 :as origin] :args | |
ret :ret}] | |
(and (= origin (second ret)) | |
(= 4 (count ret))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment