effect-ts-laws
Version:
effect-ts law testing using fast-check.
59 lines • 1.99 kB
JavaScript
import { predicate, testPredicateEquivalence, tinyPositive, tinyString, } from '#arbitrary';
import { Monoid as MO, Semigroup as SE } from '@effect/typeclass';
import { Function as FN, Number as NU, Struct as ST, String as STR, } from 'effect';
import fc from 'fast-check';
import { unfoldMonomorphicGiven } from './given.js';
import { monoPredicateArbitrary } from './mono.js';
/**
* An arbitrary for the alternative monomorphic underlying type `MonoProps`.
* @category monomorphic
*/
export const propsArbitrary = fc.record({
x: tinyPositive,
y: tinyString,
});
/**
* An arbitrary predicate the alternative monomorphic underlying type
* `MonoProps`.
* @category monomorphic
*/
export const propsPredicateArbitrary = predicate();
/**
* Monoid instance for the `MonoProps` type.
* @category monomorphic
*/
export const propsMonoid = MO.fromSemigroup(SE.struct({
x: SE.min(NU.Order),
y: SE.make(FN.dual(2, STR.concat)),
}), { x: 0, y: '' });
/**
* An equivalence for the alternative monomorphic underlying type `MonoProps`.
* @category monomorphic
*/
export const propsEquivalence = ST.getEquivalence({
x: NU.Equivalence,
y: STR.Equivalence,
});
/**
* Build a sampling equivalence for predicates of the underlying `Mono` type.
* @category monomorphic
*/
export const propsPredicateEquivalence = testPredicateEquivalence(propsArbitrary);
/**
* Unfold options for monomorphic typeclass law tests. This is a version of
* {@link unfoldMonoGiven} on the underlying type `{x: number; y: string}`.
* @category monomorphic
*/
export const unfoldPropsGiven = (getEquivalence, getArbitrary) => unfoldMonomorphicGiven({
a: propsArbitrary,
equalsA: propsEquivalence,
Monoid: propsMonoid,
getEquivalence,
getArbitrary,
});
const contravariant = (F) => ({
F,
...unfoldPropsGiven(((_) => propsPredicateEquivalence), ((_) => monoPredicateArbitrary)),
});
unfoldPropsGiven.contravariant = contravariant;
//# sourceMappingURL=props.js.map