-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify QC generators for commonly-used types. #2768
Conversation
48c39be
to
4eeb09d
Compare
b37f8bd
to
c2fad8d
Compare
Spotted this refactoring opportunity while reviewing test coverage for UTxO properties. The following are equivalent: - Set.null (a `Set.intersection` b) - a `Set.disjoint` b
This commit: - Renames `genCoinAny` to `genCoinFullRange`, making it clear from the name that values are chosen from across the full range of a `Coin`. - Gives the generator a slight bias toward the limits of the range, but otherwise preserves the uniform distribution across the whole range.
Instead of having `genCoinSmall` and `genCoinLarge` variants, we instead define a single shared generator that makes use of the implicit `size` parameter. This commit also adjusts the call sites of these generators to use one of the following generators, depending on the use case: - `genCoin` - `genCoinPositive` - `genCoinFullRange`
c2fad8d
to
ff2f2bc
Compare
In this test, the expected numbers of inputs are highly sensitive to the size distribution of token bundles within generated transaction outputs. This commit imposes a limit on the sizes of generated token bundles, so that the expected numbers of inputs are as close as possible to the previous set of values.
With large values, we want to limit the number of results returned in order to avoid processing long lists of shrunken values.
estimateMaxInputsTests @IcarusKey | ||
[(1,73),(5,67),(10,63),(20,52),(50,14)] | ||
[(1,73),(5,69),(10,64),(20,54),(50,17)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did try to retain the old values here, but in the end settled for making the (1, *)
pairs match, and getting the rest to match as closely as possible.
bors try |
tryBuild failed:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors try |
tryBuild succeeded: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was kinda hoping the weeds in TokenMap and TokenBundle would be fixed, but thanks.
@rvl wrote:
That's next on my list: will do this when I get a spare moment! Thanks for the review. 👍🏻 |
2829: Rewrite generators to use the QC size parameter r=jonathanknowles a=jonathanknowles ### Issue Number Follow-up from #2768 Supports work for #2819 ### Comments This PR adjusts generators for the following types to use the QC size parameter: - `Address` - `Hash "Tx"` - `TxIndex` (`Word32`) - `TxIn` - `TxOut` - `UTxO` - `UTxOIndex` Some minor adjustments to coverage conditions were necessary (but surprisingly few). This PR also: - Adds the module `UTxO.Gen`, so that we can generate values of `UTxO` without having to generate indices (which add extra overhead), and redefines the `UTxOIndex` generators in terms of these generators. - Adds the functions `genSized2` and `genSized2With`, which restore size linearity to generators of compound values (those defined in terms of other generators). Co-authored-by: Jonathan Knowles <[email protected]>
2829: Rewrite generators to use the QC size parameter r=jonathanknowles a=jonathanknowles ### Issue Number Follow-up from #2768 Supports work for #2819 ### Comments This PR adjusts generators for the following types to use the QC size parameter: - `Address` - `Hash "Tx"` - `TxIndex` (`Word32`) - `TxIn` - `TxOut` - `UTxO` - `UTxOIndex` Some minor adjustments to coverage conditions were necessary (but surprisingly few). This PR also: - Adds the module `UTxO.Gen`, so that we can generate values of `UTxO` without having to generate indices (which add extra overhead), and redefines the `UTxOIndex` generators in terms of these generators. - Adds the functions `genSized2` and `genSized2With`, which restore size linearity to generators of compound values (those defined in terms of other generators). Co-authored-by: Jonathan Knowles <[email protected]>
2829: Rewrite generators to use the QC size parameter r=jonathanknowles a=jonathanknowles ### Issue Number Follow-up from #2768 Supports work for #2819 ### Comments This PR adjusts generators for the following types to use the QC size parameter: - `Address` - `Hash "Tx"` - `TxIndex` (`Word32`) - `TxIn` - `TxOut` - `UTxO` - `UTxOIndex` Some minor adjustments to coverage conditions were necessary (but surprisingly few). This PR also: - Adds the module `UTxO.Gen`, so that we can generate values of `UTxO` without having to generate indices (which add extra overhead), and redefines the `UTxOIndex` generators in terms of these generators. - Adds the functions `genSized2` and `genSized2With`, which restore size linearity to generators of compound values (those defined in terms of other generators). Co-authored-by: Jonathan Knowles <[email protected]>
Issue Number
#2695
Overview
This PR simplifies the generators (and shrinkers) for the following types:
Coin
TokenQuantity
TokenPolicyId
TokenName
AssetId
Each type now has a single generator and shrinker that relies on the QC size parameter. These have the following form:
genType
shrinkType
Where strictly-positive values are required, we also have:
genTypePositive
shrinkTypePositive
Where values across the full range of a type are required, we also have:
genTypeFullRange
shrinkTypeFullRange
This PR also adjusts coverage checks for some properties.
Future work
In a future PR, we can simplify generators for
TokenMap
,TokenBundle
,UTxOIndex
,TxIn
,TxOut
.