test.rose
Jump to function (19) ›
- test.rose/int-rose-tree
- test.rose/int-rose-tree-towards
- test.rose/rose-bind
- test.rose/rose-children
- test.rose/rose-filter
- test.rose/rose-fmap
- test.rose/rose-join
- test.rose/rose-map
- test.rose/rose-pure
- test.rose/rose-root
- test.rose/rose-shrinks
- test.rose/rose-string
- test.rose/rose-tree
- test.rose/rose-vector
- test.rose/rose-vector-lax
- test.rose/rose-zip
- test.rose/rose?
- test.rose/shrink-int
- test.rose/shrink-int-towards
test.rose/int-rose-tree#
(int-rose-tree n)
Rose tree for an integer n that shrinks toward zero.
Example:
(int-rose-tree 10)
test.rose/int-rose-tree-towards#
(int-rose-tree-towards target n)
Rose tree for n whose children shrink strictly toward target.
test.rose/rose-bind#
(rose-bind t f)
Monadic bind. f takes a value and returns a rose tree; the resulting
tree combines the shrinks of t (each fed through f) with the
shrinks produced by f on the root.
Example:
(rose-bind (rose-pure 1) (fn [n] (rose-pure (inc n))))
test.rose/rose-children#
(rose-children t)
Returns the lazy sequence of immediate child rose trees.
Example:
(rose-children (rose-pure 1)) ; => ()
test.rose/rose-filter#
(rose-filter pred t)
Returns the subtree consisting only of nodes whose value satisfies
pred. Children that fail pred are pruned. If the root fails
pred, returns nil (caller is responsible for handling).
Example:
(rose-filter pos? (rose-pure 1))
test.rose/rose-fmap#
(rose-fmap f t)
Applies f to every value in rose tree t (the root and, lazily,
every descendant).
Example:
(rose-fmap inc (rose-pure 1)) ; root = 2
test.rose/rose-join#
(rose-join t)
Flattens a rose tree of rose trees into a single rose tree.
Example:
(rose-join (rose-pure (rose-pure 1)))
test.rose/rose-map#
(rose-map entry-trees)
Rose tree for a hash-map. entry-trees is a vector of rose trees of
[k v] pairs. Shrinks by removing entries and by shrinking each
pair in place.
Example:
(rose-map [...])
test.rose/rose-pure#
(rose-pure x)
Leaf rose tree: value x with no shrink candidates.
Example:
(rose-pure 42)
test.rose/rose-root#
(rose-root t)
Returns the root value of rose tree t.
Example:
(rose-root (rose-pure 42)) ; => 42
test.rose/rose-shrinks#
(rose-shrinks t)
Alias for rose-children: the lazy sequence of immediate smaller
variants of the current root.
Example:
(rose-shrinks (rose-pure 1)) ; => ()
test.rose/rose-string#
(rose-string char-trees)
Rose tree for a string whose elements are char rose trees.
Example:
(rose-string [(rose-pure " ")])
test.rose/rose-tree#
(rose-tree root children)
Rose tree constructor. children should be a lazy sequence of rose
trees (or any seqable value).
Example:
(rose-tree 1 (list (rose-pure 0)))
test.rose/rose-vector#
(rose-vector element-trees)
Rose tree for a vector whose children are built from the rose trees of its elements. Shrinks by removing elements and by shrinking each element in place.
Example:
(rose-vector [(int-rose-tree 3) (int-rose-tree 5)])
test.rose/rose-vector-lax#
(rose-vector-lax element-trees)
Like rose-vector but preserves original length; only shrinks each
element in place (no removal).
test.rose/rose-zip#
(rose-zip trees)
Takes a vector of rose trees and returns a rose tree whose root is the vector of roots and whose children shrink one position at a time.
Example:
(rose-zip [(rose-pure 1) (rose-pure 2)])
test.rose/rose?#
(rose? x)
Returns true if x looks like a rose tree.
Example:
(rose? (rose-pure 1)) ; => true
test.rose/shrink-int#
(shrink-int n)
Shrink strategy toward zero: halving steps (n/2, n/4, …) and then
decrement toward zero.
Example:
(shrink-int 8)
test.rose/shrink-int-towards#
(shrink-int-towards target n)
Returns a seq of integer candidates strictly closer to target than
n. Yields the target first, then halving steps.
Example:
(shrink-int-towards 0 10) ; => (0 5 7 8 9)