Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cemerick
Created November 13, 2013 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cemerick/7450631 to your computer and use it in GitHub Desktop.
Save cemerick/7450631 to your computer and use it in GitHub Desktop.
bigint, bigdec generators for simple-check
;; TODO: sensible default distributions for bigint, bigdec
;; these impls adapted from data.generative
#+clj ;; TODO: add support for cljs bignums if bignumber.js is around
(def ^:private gen-bigint* (gen/such-that identity
(gen/fmap #(when (pos? (count %))
(BigInteger. ^bytes %))
gen/bytes)))
; using bigint to get N-suffixed printing
#+clj
(def gen-bigint (gen/fmap bigint gen-bigint*))
#+clj
(def gen-bigdec (gen/fmap (fn [[unscaled-val scale]]
(BigDecimal. ^BigInteger unscaled-val ^int scale))
(gen/tuple gen-bigint* gen-int)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment