# test-check

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

andrea.crotti 11:09:02

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

andrea.crotti 11:09:09

so this actually works
``` (defn gen-image [nrows ncols] (gen/vector (gen/vector (gen/elements core/COLOURS) ncols) nrows))


andrea.crotti 11:10: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.crotti 11:10:16

because nrows and ncols are not defined at that point

andrea.crotti 11:10: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.crotti 11:10:45

any suggestion?

gfredericks 14:18:29

@gfredericks uploaded a file: gen-image.clj and commented: @andrea.crotti

andrea.crotti 14:51:25

@gfredericks brilliant thanks

nwjsmith 21:48:42

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

nwjsmith 22:49: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

nwjsmith 23:17: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)))))

nwjsmith 23:19: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

nwjsmith 23:19:46

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

gfredericks 23:25:19

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

gfredericks 23:26: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...)

gfredericks 23:27:20

pardon my lack of line breaks

gfredericks 23:29:41

@nwjsmith ⇑