Nice. Any updates on this? Is this a good idea? On Friday, May 15, 2015 at 12:13:06 PM UTC+5:30, Mikera wrote: > > Hi all, > > I am doing some generative testing with test.check and need a way to > control the growth rate of data structures (the regular linear growth > quickly makes the computations too large for meaningful testing usage). I > came up with the following solution to do this: > > (defn gen-resize > "Creates a generator that pre-modifies the 'size' pramater with the > function f. Use if you want to > have the size grow at a different rate from the normal linear scaling." > ([f gen] > (let [gf (or (:gen gen) "gen paramter must be a test.check generator") > new-gf (fn [rnd size] > (gf rnd (f size)))] > (clojure.test.check.generators.Generator. new-gf)))) > > Normal O(n) growth: > > (gen/sample gen/s-pos-int 30) > => (1 2 3 2 4 5 4 7 6 3 3 7 10 4 8 11 14 12 6 10 9 1 8 21 12 16 25 25 21 6) > > Controlled O(sqrt(n)) growth: > > (gen/sample (gen-resize sqrt gen/s-pos-int) 30) > => (1 2 2 2 2 4 3 3 3 3 4 3 5 1 2 3 2 4 4 2 2 3 6 6 2 5 5 4 6 3) > > So.... it seems to work, but is this a sane / recommended approach? Am I > relying too much on test.check internals? > > mikera >
-- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.