bias/limit for input values that are less relevant #4141
Unanswered
dt-eric-lefevreardant
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In our tests, some of the input values generated by arbitraries are not as important as others. For example, in this function, the
values
are clearly important, while thedate
does not matter much:When writing the tests on our project, we are interested in using arbitraries for the
values
, but we also interested in making clear to the reader that any date works. So we end up with tests such as one:The issue however is that fast-check will try to vary all inputs, including the date, even though the date does not prove anything interesting about the code. This reduces the number of relevant combinaisons of values passed to the code, while we'd prefer fast-check to vary the
data
more aggressively, and thedate
less, or not at all.We could, of course, pass a hard-coded date (eg.
sortNumbersAscending(data, new Date("2000-01-01"))
), but then it begins to look suspicious to the reader who might wonder if there is anything special about this date. We think that passing a fast-check-generated value instead makes clearer that any value here is acceptable.We've started addressing this by introducing helpers for those cases that ensure that only a small number of possible values are generated. Here is an example:
In some cases, this significantly reduces the number of necessary runs, especially when dealing with enums.
It seems that this is a problem that others might also have. Are there well known patterns to address this issue?
Beta Was this translation helpful? Give feedback.
All reactions