nick8325 / quickcheck

Automatic testing of Haskell programs.
Other
717 stars 119 forks source link

Added All and Any monoids #397

Closed coot closed 1 month ago

coot commented 5 months ago

All is a monoid build around .&&.. It is useful when writing complex properties which check multiple conditions. Since it is a monoid it allows one to use foldMap which is often much more ergonomic than using conjoin.

All satisfies monoid laws up to isSuccess, unless one is using checkCoverage & cover. I'd argue this is not a problem since checkCoverage and cover are most often added at the top of the property.

This patch also adds Any monoid build around .||..

Tests are also included.

MaximilianAlgehed commented 5 months ago

C.f. #279.

MaximilianAlgehed commented 5 months ago

The tricky thing here is deciding if this is the right point on the tradeoff spectrum. Maybe having Monoid Property and Any as an option is another good option? Another problem here is that the names Any and All are taken in base.

The build also fails on a bunch of older GHC versions (and Hugs) but thats not a huge deal - it should be pretty easy to address.

coot commented 5 months ago

The tricky thing here is deciding if this is the right point on the tradeoff spectrum.

Note that All is more general than Property, as it is an existential type which can hold any Testable p => p. When I discussed this with John, we came up with this design as it gives a lot of flexibility in writing things like Any p <> label ..., or even Any p .||. Any p' etc. I am not sure how limiting p :: Property is in general (at least, I don't usually write code which is polymorphic with Testable constraint), but in other areas, e.g. for teaching purposes, people are taking advantage of it, so students do not need to write type annotations, or modify them when playing with code.

coot commented 4 months ago

@MaximilianAlgehed I addressed your comments.

MaximilianAlgehed commented 4 months ago

Great! Please fix the build failures and I'll have a look next week! (OOTO this week)

coot commented 2 months ago

@MaximilianAlgehed could you approve the workflows to run?

coot commented 2 months ago

Something went terribly wrong with all the linux jobs:

Run actions/checkout@v3
/usr/bin/docker exec  f8c8e73e602a1181103553ab346548bbea1153df1ee39cd8bca903f874d0dd8f sh -c "cat /etc/*release | grep ^ID"
/__e/node20/bin/node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /__e/node20/bin/node)
coot commented 2 months ago

Let's try to re-run them.

MaximilianAlgehed commented 2 months ago

@coot I'm working on a fix for the CI issue in #412

MaximilianAlgehed commented 2 months ago

@coot sorry for the delay but the fix has been merged

coot commented 2 months ago

I rebased this PR.

MaximilianAlgehed commented 2 months ago

Ok, sorry... You need to rebase again because I screwed up with the semantics of github actions and the difference between "run on push" and "run on PR". There is no neat way to get "run on push and also run on PR from forks"... Anway, hopefully this works for now.

coot commented 2 months ago

Done.

coot commented 1 month ago

Let's see if I fixed 7.10.3. I was getting a linking error with ghc-7.10.3 locally.