Skip to content
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

Add generic n-ary product shrinking #2999

Merged
merged 11 commits into from
Nov 9, 2021

Conversation

sevanspowell
Copy link
Contributor

@sevanspowell sevanspowell commented Nov 3, 2021

  • Translate the round-robin shrinking algorithm to work on n-ary products (types
    with one constructor [product types], with n constructor arguments), in the
    Generics.SOP universe.
  • Write a property to assert that the old selectionParams shrinker and the new
    one produce the same result.
  • Replace all instances of liftShrinkN with a generic alternative.

See the following resource for more info on generics-sop: https://raw.githubusercontent.com/kosmikus/cufp-tutorial-2016/master/LectureNotes.pdf

@sevanspowell sevanspowell force-pushed the feature/generics-sop-reduce-boilerplate branch 4 times, most recently from da5d94f to 8617e1e Compare November 3, 2021 12:35
@sevanspowell sevanspowell marked this pull request as ready for review November 3, 2021 12:35
@sevanspowell sevanspowell force-pushed the feature/generics-sop-reduce-boilerplate branch 2 times, most recently from 2a8756f to 795d5f3 Compare November 5, 2021 06:33
Copy link
Contributor

@jonathanknowles jonathanknowles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making this PR @sevanspowell!

LGTM.

@jonathanknowles
Copy link
Contributor

bors r+

iohk-bors bot added a commit that referenced this pull request Nov 9, 2021
2999: Add generic n-ary product shrinking r=jonathanknowles a=sevanspowell

- Translate the round-robin shrinking algorithm to work on n-ary products (types
  with one constructor [product types], with n constructor arguments), in the
  Generics.SOP universe.
- Write a property to assert that the old selectionParams shrinker and the new
  one produce the same result.
- Replace all instances of liftShrinkN with a generic alternative.

See the following resource for more info on generics-sop: https://raw.githubusercontent.com/kosmikus/cufp-tutorial-2016/master/LectureNotes.pdf

Co-authored-by: Samuel Evans-Powell <[email protected]>
Co-authored-by: IOHK <[email protected]>
Co-authored-by: Jonathan Knowles <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 9, 2021

Build failed:

Cached failure:

https://hydra.iohk.io/build/8178016/nixlog/3/tail

================================================================================
RUNNING TESTS for cardano-wallet-test-utils-test-unit-x86_64-w64-mingw32-2021.9.29-check-x86_64-w64-mingw32 via wine64
================================================================================
Copying extra test libraries ...
Copying library dependencies...
Could not load wine-gecko. HTML rendering will be disabled.
Native IE detected, not doing registration
wine: configuration in '/build' has been updated.
002a:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\nix\\store\\mldlvx71ybk83q3j5l5jxbqfyn0gwg63-cardano-wallet-test-utils-test-unit-x86_64-w64-mingw32-2021.9.29\\bin\\unit.exe") not found
002a:err:module:attach_dlls Importing dlls for L"Z:\\nix\\store\\mldlvx71ybk83q3j5l5jxbqfyn0gwg63-cardano-wallet-test-utils-test-unit-x86_64-w64-mingw32-2021.9.29\\bin\\unit.exe" failed, status c0000135
builder for '/nix/store/8xmpb9z1qd5w4xwwn5lby61zadp4rxbv-cardano-wallet-test-utils-test-unit-x86_64-w64-mingw32-2021.9.29-check-x86_64-w64-mingw32.drv' failed with exit code 53

sevanspowell and others added 10 commits November 9, 2021 06:46
- Translate the round-robin shrinking algorithm to work on n-ary products (types
  with one constructor [product types], with n constructor arguments), in the
  Generics.SOP universe.
- Derive an instance of Generics.SOP.Generic for SelectionParams.
- Replace shrinkSelectionParams with new version that uses generic shrinker
  function ("groundRobinShrink").
- Write a property to assert that the old selectionParams shrinker and the new
  one produce the same result.
Use  4n    space indents for expressions.
Use (4n+2) space indents for `where` clauses.
These operators allow us to define shrinkers with a syntax that is very
similar to the applicative syntax for defining generators.

For example:

```haskell

genMyRecord :: Gen MyRecord
genMyRecord = MyRecord
    <$> genFoo
    <*> genBar
    <*> genBaz

shrinkMyRecord :: MyRecord -> [MyRecord]
shrinkMyRecord = genericRoundRobinShrink
    <@> shrinkFoo
    <:> shrinkBar
    <:> shrinkBaz
    <:> Nil

```
We give it an increased possibility of generating zero values.

This increases the probability that we'll generate a minimal test record.
@jonathanknowles jonathanknowles force-pushed the feature/generics-sop-reduce-boilerplate branch from 49eec98 to 4cb2855 Compare November 9, 2021 06:49
@jonathanknowles
Copy link
Contributor

bors r+

iohk-bors bot added a commit that referenced this pull request Nov 9, 2021
2999: Add generic n-ary product shrinking r=jonathanknowles a=sevanspowell

- Translate the round-robin shrinking algorithm to work on n-ary products (types
  with one constructor [product types], with n constructor arguments), in the
  Generics.SOP universe.
- Write a property to assert that the old selectionParams shrinker and the new
  one produce the same result.
- Replace all instances of liftShrinkN with a generic alternative.

See the following resource for more info on generics-sop: https://raw.githubusercontent.com/kosmikus/cufp-tutorial-2016/master/LectureNotes.pdf

Co-authored-by: Samuel Evans-Powell <[email protected]>
Co-authored-by: IOHK <[email protected]>
Co-authored-by: Jonathan Knowles <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 9, 2021

Build failed:

Cached failure: https://hydra.iohk.io/build/8178016/nixlog/4/tail

Same problem as before:

unpacking sources
unpacking source archive /nix/store/w7v711ax8vzrqijikpnmg18mpw31bskd-cardano-wallet-test-utils-test-unit-x86_64-w64-mingw32-2021.9.29-x86_64-w64-mingw32
source root is cardano-wallet-test-utils-test-unit-x86_64-w64-mingw32-2021.9.29-x86_64-w64-mingw32
building
================================================================================
RUNNING TESTS for cardano-wallet-test-utils-test-unit-x86_64-w64-mingw32-2021.9.29-check-x86_64-w64-mingw32 via wine64
================================================================================
Copying extra test libraries ...
Copying library dependencies...
Could not load wine-gecko. HTML rendering will be disabled.
Native IE detected, not doing registration
wine: configuration in '/build' has been updated.
002a:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\nix\\store\\mldlvx71ybk83q3j5l5jxbqfyn0gwg63-cardano-wallet-test-utils-test-unit-x86_64-w64-mingw32-2021.9.29\\bin\\unit.exe") not found
002a:err:module:attach_dlls Importing dlls for L"Z:\\nix\\store\\mldlvx71ybk83q3j5l5jxbqfyn0gwg63-cardano-wallet-test-utils-test-unit-x86_64-w64-mingw32-2021.9.29\\bin\\unit.exe" failed, status c0000135
builder for '/nix/store/8xmpb9z1qd5w4xwwn5lby61zadp4rxbv-cardano-wallet-test-utils-test-unit-x86_64-w64-mingw32-2021.9.29-check-x86_64-w64-mingw32.drv' failed with exit code 53

@jonathanknowles
Copy link
Contributor

bors r+

iohk-bors bot added a commit that referenced this pull request Nov 9, 2021
2999: Add generic n-ary product shrinking r=jonathanknowles a=sevanspowell

- Translate the round-robin shrinking algorithm to work on n-ary products (types
  with one constructor [product types], with n constructor arguments), in the
  Generics.SOP universe.
- Write a property to assert that the old selectionParams shrinker and the new
  one produce the same result.
- Replace all instances of liftShrinkN with a generic alternative.

See the following resource for more info on generics-sop: https://raw.githubusercontent.com/kosmikus/cufp-tutorial-2016/master/LectureNotes.pdf

Co-authored-by: Samuel Evans-Powell <[email protected]>
Co-authored-by: IOHK <[email protected]>
Co-authored-by: Jonathan Knowles <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 9, 2021

Build failed:

Cached failure... 🙄

I've restarted the failed job, and this time it passed.

I'll wait for all jobs to succeed on hydra before restarting the merge.

@jonathanknowles
Copy link
Contributor

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 9, 2021

Build succeeded:

@iohk-bors iohk-bors bot merged commit 533a1b2 into master Nov 9, 2021
@iohk-bors iohk-bors bot deleted the feature/generics-sop-reduce-boilerplate branch November 9, 2021 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants