nick8325 / nick8325/quickcheck
RFC: Create a SuchThat data type that allows call site `suchThat`
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 790
- Forks
- 130
- Avg merge
- 16h 41m
- Merged PRs (30d)
- 2
Description
I was recently writing tests where I needed some properties to hold in a specific situation. My usual path here is to make a newtype to get the Arbitrary instance I want. However I realized that suchThat could be used at the call site via Testable. What do you think of this type?
data SuchThat a prop = SuchThat (a -> Bool) (a -> prop)
instance (Arbitrary a, Show a, Testable prop) => Testable (SuchThat a prop) where
property (SuchThat predicate prop) =
forAllShrink (arbitrary `suchThat` predicate) shrink prop
This allows Arbitrary instances to be decorated via a generic combinator at the call site.
Here is a trivial example that would always pass:
it "is greater than 0" . property . SuchThat (> 0) $ \int -> int > 0
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the proposed SuchThat definition and its Testable instance in the issue, then inspect QuickCheck’s existing Testable, Arbitrary, and suchThat APIs. Because this is an RFC, clarify the desired API and acceptance criteria with maintainers before implementing; done would mean an agreed design and accompanying implementation and tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100