For each typeclass we test:
- The laws pass on some well tested instance, such as
ReadonlyArray<number>
. - The conjunction of the law predicates passes.
- Bad instances fail.
For example the Monad typeclass laws self-test tests:
ReadonlyArray<number>
passes the laws.- It also passes the predicates of the laws.
- A bad instance fails the laws.
Bad instances are easy to create, for example for the test described above, we
setup flatMap
to fail the identity
tests:
import {Monad as arrayMonad} from '@effect/typeclass/data/Array'
const badInstance = {
...arrayMonad,
flatMap: dual(2, flow(AR.flatMap, AR.drop(1))),
}