Created
November 13, 2013 15:10
-
-
Save cemerick/7450631 to your computer and use it in GitHub Desktop.
bigint, bigdec generators for simple-check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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