Explicit bias (Range) #2978
-
ContextI consider using fast-check in production, and so I started diving into some of the internals. I like the fact that fast-check has its own 'Size' approach (vs typical QuickCheck style where 'Size' just goes from 0 up to 99 as number of tests increase), and as far as I can tell, these are the options to have some control over 'Size':
I haven't checked all combinators but I assume that some of them are affected by 'Size' while some are not. Please correct me if I am wrong. DiscussionI just wanted to point out an alternative approach, the one we've been using in Hedgehog, where combinators are parameterized by a 'Range' type. A 'Range' describes the 'Bounds' of a number to generate, which may or may not be dependent on a 'Size'. (Pardon my F# and Haskell.) -- Haskell
data Range a =
Range a (Size -> (a, a)) // F#
type Range<'a> =
| Range of ('a * (Size -> 'a * 'a))
Based on that, you can construct various types of ranges, as per the pseudo-code below, and have fine-grained control over the scope and shrinking of generated values. Singleton rangeUnaffected of 'Size'
Constant rangeUnaffected by 'Size'. Shrinks towards the origin.
Linear rangeAffected by 'Size'. As 'Size' increases the range increases. Shrinks towards the origin.
ExamplesHere's how the concept or Range looks like in F# (which can be closer to TypeScript) and how existing generators are modified to work with the Range type. (You might notice that these PRs are from 2017, still I'd be happy to discuss further in case you find the concept interesting.) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @moodmosaic, In fast-check the size à-la-QuickCheck has been divided into two distinct parts. The bias itself - Historically, we introduced a bias that will generate extreme values with higher probability for first runs and lower as we go in the runs. Contrary to the solutions adopted by jsverify, QuickCheck and many others, we don't say: "first runs must only generate small values". Doing that may miss issues as some bugs may appear for long arrays with only small values. More details on the historical bias here. The size - Starting at the middle of the v2, we introduced the idea of size. The main reasons for this approach was: We want our users to write the contract the code should handle without having to include runtime constraints inherent to the complexity of the algorithm or to fast-check itself. We also want them to be able to select how large there values will be depending on some criteria like is in CI, is in pre-release... So size has two roles:
|
Beta Was this translation helpful? Give feedback.
Hi @moodmosaic,
In fast-check the size à-la-QuickCheck has been divided into two distinct parts.
The bias itself - Historically, we introduced a bias that will generate extreme values with higher probability for first runs and lower as we go in the runs. Contrary to the solutions adopted by jsverify, QuickCheck and many others, we don't say: "first runs must only generate small values". Doing that may miss issues as some bugs may appear for long arrays with only small values. More details on the historical bias here.
The size - Starting at the middle of the v2, we introduced the idea of size. The main reasons for this approach was: We want our users to write the contract the code should h…