test-check

2017-05-26T08:09:02.668696Z

I was trying to write a generator for a matrix of random elements, but with rows of equal length

2017-05-26T08:09:09.670268Z

so this actually works

(defn gen-image
  [nrows ncols]
  (gen/vector (gen/vector
               (gen/elements core/COLOURS)
               ncols)
              nrows))

2017-05-26T08:10:06.680493Z

however now gen-image is a function, and also doing this is not possible

(prop/for-all
 [nrows gen/pos-int
  ncols gen/pos-int
  mat (gen-image nrows ncols)])

2017-05-26T08:10:16.682614Z

because nrows and ncols are not defined at that point

2017-05-26T08:10:36.686488Z

I also try to nest prop/for-all but while that doesn't fail it doesn't really seem to do anything useful

2017-05-26T08:10:45.688083Z

any suggestion?

2017-05-26T11:51:25.172680Z

@gfredericks brilliant thanks

nwjsmith 2017-05-26T18:48:42.513964Z

err, wasn't there a guide for using recursive-gen somewhere?

nwjsmith 2017-05-26T19:49:08.467153Z

Hrm. So I'm a bit stuck trying to write a generator for a directed acyclic graph. This is what I would like to do:

;; generate a list of nodes
;; for each node x in the list
;;   generate a none-empty subset of nodes to the right of x in the list 
;;   for each node in the subset
;;     create an edge from x to the node

nwjsmith 2017-05-26T20:17:45.878930Z

(gen/bind (gen/list-distinct gen-node {:min-elements 2})
           (fn [[node & possible-joins]]
             (gen/fmap (fn [adjacent-nodes]
                         (map (partial join-nodes node) adjacent-nodes))
                       (gen/set (gen/elements possible-joins)))))

nwjsmith 2017-05-26T20:19:17.899407Z

that's what I have so far. Generate some nodes, take the first one, generate a subset from the rest, and create edges between the node and each node in the subset

nwjsmith 2017-05-26T20:19:46.905687Z

I'm having trouble figuring out how to recur on the "next" node

2017-05-26T20:25:19.983492Z

you could make that work, but something simpler might be to just generate all the edges at once

2017-05-26T20:26:23.998166Z

(gen/let [nodes (gen/vector-distinct gen-node {:min-elements 2}), edges (gen/vector-distinct (gen/vector-distinct (gen/elements nodes) {:num-elements 2}))] ... figure which direction the edges go based on the ordering of nodes...)

1
2017-05-26T20:27:20.010871Z

pardon my lack of line breaks

2017-05-26T20:29:41.043469Z

@nwjsmith