2016-07-26 11:15:56 +03:00
|
|
|
{-# LANGUAGE ScopedTypeVariables #-}
|
2016-07-26 10:56:52 +03:00
|
|
|
module Data.Mergeable.Spec where
|
2016-07-26 10:58:14 +03:00
|
|
|
|
2016-07-26 11:02:52 +03:00
|
|
|
import Data.Functor.Identity
|
|
|
|
import Data.Mergeable
|
2016-07-26 10:58:14 +03:00
|
|
|
import Prologue
|
2016-07-26 12:39:02 +03:00
|
|
|
import Syntax
|
2016-07-26 10:58:14 +03:00
|
|
|
import Test.Hspec
|
2016-07-26 11:02:52 +03:00
|
|
|
import Test.Hspec.QuickCheck
|
2016-07-26 11:06:51 +03:00
|
|
|
import Test.QuickCheck
|
2016-07-26 10:58:14 +03:00
|
|
|
|
|
|
|
spec :: Spec
|
2016-07-26 19:47:38 +03:00
|
|
|
spec = parallel $ do
|
2016-07-26 11:07:46 +03:00
|
|
|
describe "[]" $ sequenceAltLaws (arbitrary :: Gen [Char])
|
2016-07-26 11:08:19 +03:00
|
|
|
describe "Maybe" $ sequenceAltLaws (arbitrary :: Gen (Maybe Char))
|
2016-07-26 11:16:40 +03:00
|
|
|
describe "Identity" $ sequenceAltLaws (Identity <$> arbitrary :: Gen (Identity Char))
|
2016-07-26 12:39:02 +03:00
|
|
|
describe "Syntax" $ sequenceAltLaws (sized (syntaxOfSize (const arbitrary)) :: Gen (Syntax Char Char))
|
2016-07-26 11:04:24 +03:00
|
|
|
|
2016-07-26 20:03:13 +03:00
|
|
|
mergeLaws :: (Mergeable f, Alternative g, Eq (g (f a)), Show (f a), Show (g (f a))) => Gen (f a) -> Gen (Blind (a -> g a)) -> Spec
|
|
|
|
mergeLaws value function = describe "merge" $ do
|
|
|
|
prop "relationship with sequenceAlt" . forAll ((,) <$> value <*> function) $
|
|
|
|
\ (a, f) -> merge (getBlind f) a `shouldBe` sequenceAlt (fmap (getBlind f) a)
|
|
|
|
|
2016-07-26 11:15:56 +03:00
|
|
|
sequenceAltLaws :: forall f a. (Arbitrary a, CoArbitrary a, Mergeable f, Eq (f a), Show (f a)) => Gen (f a) -> Spec
|
2016-07-26 11:06:51 +03:00
|
|
|
sequenceAltLaws gen = do
|
2016-07-26 11:23:03 +03:00
|
|
|
describe "Maybe" $ sequenceAltLaws' gen (arbitrary :: Gen (Blind (a -> Maybe a)))
|
|
|
|
|
|
|
|
sequenceAltLaws' :: forall f g a. (Arbitrary a, CoArbitrary a, Mergeable f, Alternative g, Eq (f a), Eq (g (f a)), Show (f a), Show (g (f a))) => Gen (f a) -> Gen (Blind (a -> g a)) -> Spec
|
|
|
|
sequenceAltLaws' value function = do
|
2016-07-26 11:02:52 +03:00
|
|
|
describe "sequenceAlt" $ do
|
2016-07-26 11:23:03 +03:00
|
|
|
prop "identity" . forAll value $
|
2016-07-26 11:25:45 +03:00
|
|
|
\ a -> sequenceAlt (pure <$> a) `shouldBe` (pure a :: g (f a))
|
2016-07-26 11:15:56 +03:00
|
|
|
|
2016-07-26 11:23:03 +03:00
|
|
|
prop "relationship with merge" . forAll ((,) <$> value <*> function) $
|
2016-07-26 11:15:56 +03:00
|
|
|
\ (a, f) -> sequenceAlt (getBlind f <$> a) `shouldBe` merge (getBlind f) a
|