From df4621622a2a17ae123d70be17e53b3c808726b5 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 26 Jul 2016 13:03:13 -0400 Subject: [PATCH] Formulate a merge law. --- test/Data/Mergeable/Spec.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/Data/Mergeable/Spec.hs b/test/Data/Mergeable/Spec.hs index 945f5c75c..16e3ef33f 100644 --- a/test/Data/Mergeable/Spec.hs +++ b/test/Data/Mergeable/Spec.hs @@ -16,6 +16,11 @@ spec = parallel $ do describe "Identity" $ sequenceAltLaws (Identity <$> arbitrary :: Gen (Identity Char)) describe "Syntax" $ sequenceAltLaws (sized (syntaxOfSize (const arbitrary)) :: Gen (Syntax Char Char)) +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) + sequenceAltLaws :: forall f a. (Arbitrary a, CoArbitrary a, Mergeable f, Eq (f a), Show (f a)) => Gen (f a) -> Spec sequenceAltLaws gen = do describe "Maybe" $ sequenceAltLaws' gen (arbitrary :: Gen (Blind (a -> Maybe a)))