(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))))
+;; Here we define some basic generators which are basically the
+;; lowest level building blocks of our generator DSL.
+ ;; Functions may be used directly as generators. They generate
+ ;; a `SimpleValue` which is not shrinable.
- (arbitrary [this size] (
DomainValue. this (this size)))
+ (arbitrary [this size] (Value. (this size)))
+ ;; Vectors and sequences are treated as tupels of generators.
(arbitrary [this size] (arbitrary (seq this) size))
- (let [[generators values]
- (reduce (fn [[generators values] gen]
- (let [dval (arbitrary gen size)]
- [(conj generators (.domain dval))
- (conj values (.value dval))]))
- (DomainValue. generators values)))
+ (arbitrary [this size] (map #(generate % size) this))
+ ;; Maps generate static maps with fixed keys mapped to the
+ ;; values generated by the named generators.
- dvals (arbitrary gens size)]
- (DomainValue. (zipmap ks (.domain dvals))
- (zipmap ks (.value dvals)))))
+ (into (empty this) (for [[k gen] this] [k (generate gen size)])))
+ ;; Any other arbitrary object, which does not take part in the
+ ;; `Generator` protocol gives a generator which always generates
(arbitrary [this size] (arbitrary (constantly this) size)))