Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by
Add {{bigint?}} and spec.gen support.

This part is easy:


(defn bigint?
  "Returns true if n is a BigInt"
  {:added "1.9"}
  [n] (instance? clojure.lang.BigInt n))


The generator is the tricky bit. test.check doesn't have a generator for bigints, just {{large-integer}} for things in long range. I think we'd want numbers beyond long range in a bigint generator (as that's a likely place where bugs might lie). Making a really high-quality bigint generator (with good growth and shrinking characteristics) is something that needs more thought.

http://clojure.github.io/test.check/clojure.test.check.generators.html#var-large-integer

4 Answers

0 votes
by

Comment made by: gfredericks

In case I don't get around to making a patch, I think a generator along these lines would be a decent start:

`
(def gen-bigint
(gen/sized
(fn [size]

 (let [large-integer (gen/resize size gen/large-integer)] 
   ;; scaling gives us relatively small vectors, but using  
   ;; the resized large-integer above means the numbers in 
   ;; the small vectors will still be big 
   (gen/scale #(+ 2 (/ % 20))
              (gen/fmap (fn [xs] (+ (bigint (first xs)) (reduce * (map bigint (rest xs))))) 
                        (gen/not-empty (gen/vector large-integer)))))))) ```
0 votes
by

Comment made by: gfredericks

If anything seems inadequate about the sizing in the above generator, I should point out that sizing in test.check is rather subtle but the requirements are also not well-defined. I'd be happy to discuss in detail.

0 votes
by

Comment made by: gfredericks

As an update, I've put together a marvelous bigint generator that this margin is too small to contain. It might need tweaking but is probably fine for these purposes. It's not on test.check master yet but I expect it will be soon.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-1951 (reported by alexmiller)
...