gfredericks / test.chuck

A utility library for test.check
Eclipse Public License 1.0
215 stars 26 forks source link

bounded-int throws AssertionError Assert failed: (<= lower upper) when min is slightly larger. #11

Closed firesofmay closed 9 years ago

firesofmay commented 9 years ago

Following works fine:

(gen/sample (bounded-int 0 100))
=> (1 1 1 2 2 20 15 70 72 91)

But if you give slightly larger min it throws AssertionError:

(gen/sample (bounded-int 10 100))
AssertionError Assert failed: (<= lower upper)  clojure.test.check.generators/rand-range (generators.clj:159)

Here's a test to check it as well

(def bounded-int-gen
  (gen'/for [size (gen/choose 0 10000)
             min (gen/resize size gen/nat)
             max (gen/fmap (fn [x]
                             (+ min x))
                           gen/nat)
             n (gen'/bounded-int min max)]
    [min n max]))

(defspec bounded-int-spec 100
  (prop/for-all [[min n max] bounded-int-gen]
                (<= min n max)))

Note that If you don't randomise the size it'll pass.

Is this a valid failure?

Also I am not clear why is this function useful over choose? Thanks.

gfredericks commented 9 years ago

Haha that's ridiculous. Thanks for the report.

Based on the fact that bounded-int is used by double, my guess would be that double was the motivating use case. But I can imagine wanting it in other situations -- in particular, you want the large ranges afforded by choose, but the slow initial growth of nat & friends. choose is different because it gives you a uniform distribution right off the bat, so even your "small" tests will use numbers drawn from the whole range.

gfredericks commented 9 years ago

Fix included in release 0.1.20