diff --git a/src/func/instances/composition.rs b/src/func/instances/composition.rs index 2229fe2..8e9440b 100644 --- a/src/func/instances/composition.rs +++ b/src/func/instances/composition.rs @@ -187,13 +187,11 @@ mod composition_tests { type T = CompositionInstance>; - impl<'a> tests::Eqr<'a> for T { - fn eqr( - name: &'a str, - left: Self::F, - right: Self::F, - ) -> tests::R { - tests::eqr(name, left, right) + impl<'a> tests::ToEq<'a> for T { + type Eq = Self::F; + + fn to_eq(fa: Self::F) -> Self::Eq { + fa } } @@ -234,6 +232,11 @@ mod composition_tests { test_suite::fail_functor_follows_laws::().unwrap(); } + #[test] + fn local_follows_laws() { + test_suite::local_follows_laws::().unwrap(); + } + #[test] fn select_second() { type T = CompositionInstance, ResultInstance>; diff --git a/src/func/instances/effect.rs b/src/func/instances/effect.rs index 3ae3e1d..58f15ad 100644 --- a/src/func/instances/effect.rs +++ b/src/func/instances/effect.rs @@ -221,17 +221,11 @@ mod effect_tests { type T = EffectInstance; - impl<'a> tests::Eqr<'a> for T { - fn eqr( - name: &'a str, - left: Self::F, - right: Self::F, - ) -> tests::R { - tests::eqr( - name, - (left.value, left.effect.simplify()), - (right.value, right.effect.simplify()), - ) + impl<'a> tests::ToEq<'a> for T { + type Eq = (A, Arc); + + fn to_eq(fa: Self::F) -> Self::Eq { + (fa.value, fa.effect.simplify()) } } diff --git a/src/func/instances/future.rs b/src/func/instances/future.rs index 702e65a..301bf4a 100644 --- a/src/func/instances/future.rs +++ b/src/func/instances/future.rs @@ -141,23 +141,17 @@ impl<'a> SharedFunctor<'a> for FutureInstance { mod future_tests { use std::sync::Arc; - use crate::func::{applicative_select::Selected, tests::Eqr, ApplicativeSelect}; + use crate::func::{applicative_select::Selected, ApplicativeSelect}; use super::{test_suite, tests, FutureInstance}; type T = FutureInstance; - impl<'a> Eqr<'a> for T { - fn eqr( - name: &'a str, - left: Self::F, - right: Self::F, - ) -> tests::R { - tests::eqr( - name, - futures::executor::block_on(left), - futures::executor::block_on(right), - ) + impl<'a> tests::ToEq<'a> for T { + type Eq = A; + + fn to_eq(fa: Self::F) -> Self::Eq { + futures::executor::block_on(fa) } } diff --git a/src/func/instances/lazy.rs b/src/func/instances/lazy.rs index 0774c97..a26c280 100644 --- a/src/func/instances/lazy.rs +++ b/src/func/instances/lazy.rs @@ -111,13 +111,11 @@ mod lazy_tests { type T = LazyInstance; - impl<'a> tests::Eqr<'a> for T { - fn eqr( - name: &'a str, - left: Self::F, - right: Self::F, - ) -> tests::R { - tests::eqr(name, left(), right()) + impl<'a> tests::ToEq<'a> for T { + type Eq = A; + + fn to_eq(fa: Self::F) -> Self::Eq { + fa() } } diff --git a/src/func/instances/option.rs b/src/func/instances/option.rs index 642c172..ffda809 100644 --- a/src/func/instances/option.rs +++ b/src/func/instances/option.rs @@ -146,13 +146,11 @@ mod option_tests { use super::OptionInstance as T; - impl<'a> tests::Eqr<'a> for T { - fn eqr( - name: &'a str, - left: Self::F, - right: Self::F, - ) -> tests::R { - tests::eqr(name, left, right) + impl<'a> tests::ToEq<'a> for T { + type Eq = Self::F; + + fn to_eq(fa: Self::F) -> Self::Eq { + fa } } @@ -207,4 +205,9 @@ mod option_tests { fn fail_follows_laws() { test_suite::fail_functor_follows_laws::().unwrap(); } + + #[test] + fn local_follows_laws() { + test_suite::local_follows_laws::().unwrap(); + } } diff --git a/src/func/instances/result.rs b/src/func/instances/result.rs index bf0f6d8..60a3ec2 100644 --- a/src/func/instances/result.rs +++ b/src/func/instances/result.rs @@ -254,13 +254,11 @@ mod result_tests { type T = ResultInstance; - impl<'a> tests::Eqr<'a> for T { - fn eqr( - name: &'a str, - left: Self::F, - right: Self::F, - ) -> tests::R { - tests::eqr(name, left, right) + impl<'a> tests::ToEq<'a> for T { + type Eq = Self::F; + + fn to_eq(fa: Self::F) -> Self::Eq { + fa } } diff --git a/src/func/instances/solo.rs b/src/func/instances/solo.rs index 1eda3f3..db534f2 100644 --- a/src/func/instances/solo.rs +++ b/src/func/instances/solo.rs @@ -125,13 +125,11 @@ mod solo_tests { type T = SoloInstance; - impl<'a> tests::Eqr<'a> for T { - fn eqr( - name: &'a str, - left: Self::F, - right: Self::F, - ) -> tests::R { - tests::eqr(name, left, right) + impl<'a> tests::ToEq<'a> for T { + type Eq = Self::F; + + fn to_eq(fa: Self::F) -> Self::Eq { + fa } } @@ -152,4 +150,9 @@ mod solo_tests { fn shared_follows_laws() { test_suite::shared_follows_laws::().unwrap(); } + + #[test] + fn local_follows_laws() { + test_suite::local_follows_laws::().unwrap(); + } } diff --git a/src/func/instances/stackless.rs b/src/func/instances/stackless.rs index 8890949..63fcee7 100644 --- a/src/func/instances/stackless.rs +++ b/src/func/instances/stackless.rs @@ -270,13 +270,11 @@ mod stackless_test { use super::StacklessInstance as T; - impl<'a> tests::Eqr<'a> for T { - fn eqr( - name: &'a str, - left: Self::F, - right: Self::F, - ) -> tests::R { - tests::eqr(name, left.evaluate(), right.evaluate()) + impl<'a> tests::ToEq<'a> for T { + type Eq = A; + + fn to_eq(fa: Self::F) -> Self::Eq { + fa.evaluate() } } diff --git a/src/func/instances/tryfuture.rs b/src/func/instances/tryfuture.rs index f26f32f..228fdd1 100644 --- a/src/func/instances/tryfuture.rs +++ b/src/func/instances/tryfuture.rs @@ -207,23 +207,17 @@ impl<'a> MonadFailAny<'a> for FutureFailAny { mod tryfuture_tests { use std::sync::Arc; - use crate::func::{applicative_select::Selected, tests::Eqr, ApplicativeSelect}; + use crate::func::{applicative_select::Selected, ApplicativeSelect}; use super::{test_suite, tests, TryFutureInstance}; type T = TryFutureInstance; - impl<'a> Eqr<'a> for T { - fn eqr( - name: &'a str, - left: Self::F, - right: Self::F, - ) -> tests::R { - tests::eqr( - name, - futures::executor::block_on(left), - futures::executor::block_on(right), - ) + impl<'a> tests::ToEq<'a> for T { + type Eq = Result; + + fn to_eq(fa: Self::F) -> Self::Eq { + futures::executor::block_on(fa) } } diff --git a/src/func/tests.rs b/src/func/tests.rs index d936831..356f6ec 100644 --- a/src/func/tests.rs +++ b/src/func/tests.rs @@ -40,6 +40,22 @@ pub trait Eqr<'a>: WeakFunctor<'a> { ) -> R; } +pub trait ToEq<'a>: WeakFunctor<'a> { + type Eq: PartialEq + Debug; + + fn to_eq(fa: Self::F) -> Self::Eq; +} + +impl<'a, T: ToEq<'a>> Eqr<'a> for T { + fn eqr( + name: &'a str, + left: Self::F, + right: Self::F, + ) -> R { + eqr(name, Self::to_eq(left), Self::to_eq(right)) + } +} + pub fn eqr(name: &str, left: T, right: T) -> R { if left == right { TestResults {