danr / proptest

Property-based testing a'la QuickCheck for TypeScript and JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rename forall to assertForall?

danr opened this issue · comments

To make it more obvious that it will throw an error if it doesn't hold for "all" values?

// compare
QC.assertForall(QC.nat.replicate(2), ([x,y]) => x+10 > y)
// with
QC.forall(QC.nat.replicate(2), ([x,y]) => x+10 > y)

What do you think @paldepind ?

It's slightly longer but also more explicit about what happens. I think its good.

On a related note, I think there should be a way to define properties by throwing inside the testing function instead of returning true/false. Many people are used to assertion libraries that throw. They may also be relying on handy features that such libraries offer. This is what I mean:

import {assert} from 'chai'

QC.???(QC.nat.replicate(2), ([x, y]) => {
  const r = myFn(x, y)
  assert.isNotEmpty(r)
  assert.include(r, "foo")
});

But what should such a function be called? I was thinking of forallAssert (because the function passed to forallAssert can usert assertions). But assertForallAssert sounds odd.

Similarly, the should maybe also be a variant of the function introduced in #6 that works with throwing functions.

A problem with tape and AVA is that their assertions don't actually throw but just record that they failed. I started a discussion about extending the AVA API to support rerunning properties that fail so that shrinking can happen, see avajs/ava#1692

However, I also realized I don't shrink when an exception has been caught, but this is fixed now in f09bd3c. The user still has to return true at the end of their property so it's not as smooth as it could be for this use-case yet.