1. Meikel Brandmeyer
  2. ClojureCheck


Meikel Brandmeyer  committed 01e3820

Implementation basic values

  • Participants
  • Parent commits 349b2cd
  • Branches default

Comments (0)

Files changed (1)

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

View file
  • Ignore whitespace
     "Return a sequence of less complex value than the one given.
   In case the value is not further shrinkable, return `nil`."))
+;; # Implementation
+;; ## Basic values
+;; There are two very basic types of values.
+;; * `SimpleValue` carries a value which is not shrinkable.
+;; * `ShrinkableValue` carries a `DomainValue` and function which
+;;   specifies how the value should be shrunken.
+(deftype SimpleValue [v]
+  DomainValue
+  (value  [this] v)
+  (shrink [this] nil))
+;; These two types are used for the very basic generators. However
+;; it is perfectly possibly to define custom domain value types.
+(deftype ShrinkableValue [v f]
+  DomainValue
+  (value  [this] (value v))
+  (shrink [this] (f v)))
 (extend-protocol Generator
   (arbitrary [this size] (DomainValue. this (this size)))