1. Meikel Brandmeyer
  2. ClojureCheck


Meikel Brandmeyer  committed 2d436c3

DSL domain values

  • Participants
  • Parent commits 01e3820
  • Branches default

Comments (0)

Files changed (1)

File src/main/clojure/clojurecheck/core.clj

View file
  • Ignore whitespace
   (value  [this] (value v))
   (shrink [this] (f v)))
+;; Some of Clojure's internal types are also acting as domain values.
+;; The map to the corresponding behaviour of the given type in the
+;; role of an generator.
+(extend-protocol DomainValue
+  ;; Sequences are considered as tuples of generated values.
+  ;; Shrink one after the other.
+  clojure.lang.ISeq
+  (value  [this] (map value this))
+  (shrink [this] (mapcat shrink this))
+  ;; Maps are also acting as domain values. The keys are fixed
+  ;; but the values are domain values. Again we try to shrink
+  ;; here one after the other.
+  clojure.lang.IPersistentMap
+  (value  [this] (into (empty this) (for [[k v] this] [k (value v)])))
+  (shrink [this] (for [[k v] this sv (shrink v)] (assoc this k sv))))
 (extend-protocol Generator
   (arbitrary [this size] (DomainValue. this (this size)))