Welcome! Please see the About page for a little more info on how this works.

0 votes
in Spec by

Problem

One of the goals of test.check is for users to be able to write arbitrarily rich generators while maintaining determinism, which has obvious benefits for reproducing failures.

Currently the {{fspec}} generator generates a function which itself generates random return values by calling {{clojure.test.check.generators/generate}}, which is a function intended only for development use as it circumvents test.check's controlled source of psuedorandomness. It also circumvents test.check's sizing mechanism, since the {{generate}} function always uses a size of {{30}}.

Possible Solutions

I see two reasonable solutions to this, depending on whether the generated function ought to be a pure function (which it currently isn't, since it ignores its arguments and randomly generates a return value).

Pure Function

We can generate a non-empty vector of possible return values and use that to create a function that selects one of the possible return values using the {{hash}} of the arguments.

Impure Function

We can generate a non-empty collection of possible return values and use that to create a function with internal state that cycles through the possible return values.

2 Answers

0 votes
by

Comment made by: gfredericks

Added a patch for each of the approaches listed. Would be happy to add tests too if feedback is given about either approach being preferred.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-1949 (reported by gfredericks)
...