generalise composition testing
All checks were successful
buildbot/cargo fmt (1.72) Build done.
buildbot/cargo doc (1.72) Build done.
buildbot/cargo clippy (1.72) Build done.
buildbot/cargo test (1.65) Build done.
buildbot/cargo clippy (1.65) Build done.

This commit is contained in:
AF 2023-10-15 18:55:26 +00:00
parent b846e1040a
commit 3c7b122b2a
2 changed files with 20 additions and 8 deletions

View File

@ -187,22 +187,34 @@ mod composition_tests {
type T = CompositionInstance<OptionInstance, ResultInstance<i32>>; type T = CompositionInstance<OptionInstance, ResultInstance<i32>>;
impl<'a> tests::ToEq<'a> for T { impl<'a, U: tests::ToEq<'a> + Functor<'a>, V: tests::ToEq<'a>> tests::ToEq<'a>
type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = Self::F<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> { 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>>>)>( fn sample<A: 'a + Send, F: FnMut(Arc<dyn test_suite::WrapFunction<'a, A, Self::F<A>>>)>(
mut f: F, mut f: F,
) { ) {
OptionInstance::sample(|ua0| { U::sample(|ua0| {
ResultInstance::sample(|a0| { V::sample(|a0| {
let ua0 = ua0.clone(); let ua0 = ua0.clone();
f(Arc::new(move |a| ua0(a0(a)))) f(Arc::new(move |a| regularise(ua0(a0(a)))))
}) })
}); });
} }

View File

@ -41,7 +41,7 @@ pub trait Eqr<'a>: WeakFunctor<'a> {
} }
pub trait ToEq<'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>; fn to_eq<A: 'a + Send + PartialEq + Debug>(fa: Self::F<A>) -> Self::Eq<A>;
} }