generalise composition testing
This commit is contained in:
parent
b846e1040a
commit
3c7b122b2a
@ -187,22 +187,34 @@ mod composition_tests {
|
||||
|
||||
type T = CompositionInstance<OptionInstance, ResultInstance<i32>>;
|
||||
|
||||
impl<'a> tests::ToEq<'a> for T {
|
||||
type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = Self::F<A>;
|
||||
impl<'a, U: tests::ToEq<'a> + Functor<'a>, V: tests::ToEq<'a>> tests::ToEq<'a>
|
||||
for CompositionInstance<U, V>
|
||||
{
|
||||
type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = U::Eq<V::Eq<A>>;
|
||||
|
||||
fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
|
||||
fa
|
||||
U::to_eq(U::fmap(fa, V::to_eq))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> test_suite::FunctorTestSuite<'a> for T {
|
||||
fn regularise<'a, U: WeakFunctor<'a>, V: WeakFunctor<'a>, A: 'a + Send>(
|
||||
fua: U::F<V::F<A>>,
|
||||
) -> <CompositionInstance<U, V> as WeakFunctor<'a>>::F<A> {
|
||||
fua
|
||||
}
|
||||
|
||||
impl<'a, U: test_suite::FunctorTestSuite<'a>, V: test_suite::FunctorTestSuite<'a>>
|
||||
test_suite::FunctorTestSuite<'a> for CompositionInstance<U, V>
|
||||
where
|
||||
Self: tests::Eqr<'a>,
|
||||
{
|
||||
fn sample<A: 'a + Send, F: FnMut(Arc<dyn test_suite::WrapFunction<'a, A, Self::F<A>>>)>(
|
||||
mut f: F,
|
||||
) {
|
||||
OptionInstance::sample(|ua0| {
|
||||
ResultInstance::sample(|a0| {
|
||||
U::sample(|ua0| {
|
||||
V::sample(|a0| {
|
||||
let ua0 = ua0.clone();
|
||||
f(Arc::new(move |a| ua0(a0(a))))
|
||||
f(Arc::new(move |a| regularise(ua0(a0(a)))))
|
||||
})
|
||||
});
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ pub trait Eqr<'a>: WeakFunctor<'a> {
|
||||
}
|
||||
|
||||
pub trait ToEq<'a>: WeakFunctor<'a> {
|
||||
type Eq<A: 'a + Send + PartialEq + Debug>: PartialEq + Debug;
|
||||
type Eq<A: 'a + Send + PartialEq + Debug>: 'a + Send + PartialEq + Debug;
|
||||
|
||||
fn to_eq<A: 'a + Send + PartialEq + Debug>(fa: Self::F<A>) -> Self::Eq<A>;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user