Hi Colin, You've correctly followed the guide for writing recursive generators. Trouble is, the guide (which I wrote) is wrong! I'll work on getting it updated shortly, but in the interim, you can check out the detailed commit message here: https://github.com/clojure/test.check/commit/2a2bd8f09a59391e7a0510291094c529ec3d922e, which fixes this issue in test.check's built-in recursive generators. Additionally, that commit offers a new convenience function for writing your own recursive generators, without all of the current boilerplate. This commit should be available on 0.5.9-SNAPSHOT, and should be a in a release soon.
Reid On Friday, June 20, 2014 12:18:21 PM UTC-5, Colin Fleming wrote: > > Hi all, > > I'm trying to use test.check to create random objects to test some > serialisation code I'm having problems with. In the past, generative > testing has worked really well for me for exactly this use case. However, > I'm finding that I'm getting OutOfMemoryError when trying to test a lot of > iterations: > > (defn object [size] > (if (= 0 size) > (gen/one-of > [(gen/return nil) > gen/boolean > gen/string > gen/keyword > gen/nat]) > (let [new-size (quot size 2) > next (gen/resize new-size (gen/sized object))] > (gen/one-of > [(gen/return nil) > gen/boolean > gen/string > gen/keyword > (gen/vector next) > (gen/map next next) > (gen/fmap set (gen/vector next)) > gen/nat])))) > > (def object-serializes > (prop/for-all [v (gen/sized object)] > (let [serialiser (ClojureSerialiser. {}) > byte-stream (ByteArrayOutputStream.) > data-stream (DataOutputStream. byte-stream) > _ (.serialise serialiser data-stream v) > bytes (.toByteArray byte-stream)] > (= v (.deserialise serialiser (DataInputStream. > (ByteArrayInputStream. bytes))))))) > > (check/quick-check 500 object-serializes) > java.lang.OutOfMemoryError: Java heap space > Dumping heap to java_pid9895.hprof ... > Heap dump file created [1976236588 bytes in 35.110 secs] > OutOfMemoryError Java heap space > clojure.test.check.rose-tree/permutations/iter--43--47 (rose_tree.clj:71) > > Looking at the heap dump in MAT, it looks like something internal to > test.check is holding onto the head of a sequence: > > clojure.lang.PersistentVector > + clojure.test.check.generators$sequence$fn__109$fn__110$fn__111 > | + clojure.test.check.generators$gen_bind$fn__149 > > I assume this is something I'm doing wrong, but I have no idea what. Can > anyone suggest anything? > > Thanks, > Colin > -- 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.