Fork me on GitHub
#test-check
<
2017-05-26
>
andrea.crotti08:05:02

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

andrea.crotti08:05:09

so this actually works

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

andrea.crotti08:05:06

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)])

andrea.crotti08:05:16

because nrows and ncols are not defined at that point

andrea.crotti08:05:36

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

andrea.crotti08:05:45

any suggestion?

nwjsmith18:05:42

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

nwjsmith19:05:08

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

nwjsmith20:05:45

(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)))))

nwjsmith20:05:17

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

nwjsmith20:05:46

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

gfredericks20:05:19

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

gfredericks20:05:23

(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...)

gfredericks20:05:20

pardon my lack of line breaks