test-check

2017-08-02T20:49:37.497093Z

How might you go about writing a generator of sequences of numbers which add up to n?

2017-08-02T20:51:25.556987Z

@cddr depends what kind of distribution you want

2017-08-02T20:51:59.575748Z

the easy dumb way to do it is to generate a sequence of numbers and then append (- n sum) to them

2017-08-02T20:52:38.597387Z

also depends on what kind of numbers you mean

2017-08-02T20:54:09.648143Z

This is related to my question over in #clojure-spec about a having relations between a top-level amount, and children that should add up to that amount https://clojurians.slack.com/archives/C1B1BB2Q3/p1501686285791508

2017-08-02T20:54:54.672886Z

would it be weird to not generate the top-level amount?

2017-08-02T20:55:09.681126Z

generate just the children, then set the top-level to the sum?

2017-08-02T20:58:38.798178Z

Yeah that was my first thought too. But then I thought I needed to solve this type of problem anyway but looking back at my code I can't remember why now 🙂

2017-08-02T20:59:35.830176Z

In the actual example there are a few more relationships between the top-level and the children

2017-08-02T21:08:14.112303Z

a very useful tactic as generating something related to what you want, and using gen/fmap to transform it

2017-08-02T21:08:42.126545Z

i.e., generate the information, then use fmap to get it into the right format