Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implements bifoldable test #62

Merged
merged 1 commit into from
Feb 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/Test/QuickCheck/Classes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ module Test.QuickCheck.Classes
, applicative, applicativeMorphism, semanticApplicative
, bind, bindMorphism, semanticBind, bindApply
, monad, monadMorphism, semanticMonad, monadFunctor
, monadApplicative, arrow, arrowChoice, foldable, foldableFunctor, traversable
, monadApplicative, arrow, arrowChoice, foldable, foldableFunctor, bifoldable, bifoldableBifunctor, traversable
, monadPlus, monadOr, alt, alternative
)
where

import Data.Bifoldable (Bifoldable (..))
import Data.Bifunctor hiding (first, second)
import Data.Foldable (Foldable(..))
import Data.Functor.Apply (Apply ((<.>)))
import Data.Functor.Alt (Alt ((<!>)))
Expand Down Expand Up @@ -826,3 +828,40 @@ foldableFunctor = const ( "Foldable Functor"
where
foldMapP :: (a -> m) -> t a -> Property
foldMapP f t = foldMap f t =-= fold (fmap f t)

bifoldable :: forall p a b c m.
( Bifoldable p, Monoid m
, Show (p a b), Show (p m m)
, Arbitrary (p a b), Arbitrary (p m m), Arbitrary m
, CoArbitrary a, CoArbitrary b
, EqProp m, EqProp c, CoArbitrary c, Arbitrary c, Show c) =>
p a (b, c, m) -> TestBatch
bifoldable = const ( "Bifoldable"
, [ ("identity", property identityP)
, ("bifoldMap f g ≡ bifoldr (mappend . f) (mappend . g) mempty", property bifoldMapBifoldrP)
, ("bifoldr f g z t ≡ appEndo (bifoldMap (Endo . f) (Endo . g) t) z", property bifoldrBifoldMapP)
]
)
where
identityP :: Property
identityP = bifold =-= (bifoldMap id id :: p m m -> m)

bifoldMapBifoldrP :: (a -> m) -> (b -> m) -> Property
bifoldMapBifoldrP f g = bifoldMap f g =-= (bifoldr (mappend . f) (mappend . g) mempty :: p a b -> m)

bifoldrBifoldMapP :: (a -> c -> c) -> (b -> c -> c) -> c -> p a b -> Property
bifoldrBifoldMapP f g z t = bifoldr f g z t =-= appEndo (bifoldMap (Endo . f) (Endo . g) t) z

bifoldableBifunctor :: forall p a b m.
( Bifoldable p, Bifunctor p, Monoid m
, Show (p a b)
, Arbitrary (p a b), Arbitrary m, CoArbitrary a, CoArbitrary b
, EqProp m) =>
p a (b, m) -> TestBatch
bifoldableBifunctor = const ( "Bifoldable Bifunctor"
, [ ("bifoldMap f g ≡ bifold . bimap f g", property bifoldBimapP) ]
)
where
bifoldBimapP :: (a -> m) -> (b -> m) -> Property
bifoldBimapP f g = bifoldMap f g =-= (bifold . bimap f g :: p a b -> m)