Commits

Aleksey Khudyakov committed 2ecb3f8

Generic test for monoid and Group

Comments (0)

Files changed (1)

Test/QuickCheck/Property/Generic.hs

   , prop_RightIdentity
   , prop_Identity
   , prop_GroupInverse
+    -- ** General
+  , prop_GenMonoid
+  , prop_Group
   ) where
 
 import Test.QuickCheck.Property.Common
 
 -- | Test that value is a left identity
 prop_LeftIdentity :: a             -- ^ Left identity
-                  -> (a -> a -> a) -- ^ Function
-                  -> T a
-                  -> a -> Equal a
+                  -> (a -> a -> a) -- ^ Associative operation
+                  -> T a -> a -> Equal a
 prop_LeftIdentity e (<>) T x = (e <> x) .==. x
 
 -- | Test that value is a left identity
 prop_RightIdentity :: a             -- ^ Right identity
-                   -> (a -> a -> a) -- ^ Function
-                   -> T a
-                   -> a -> Equal a
+                   -> (a -> a -> a) -- ^ Associative operation
+                   -> T a -> a -> Equal a
 prop_RightIdentity e (<>) T x = (x <> e) .==. x
 
 -- | Test that value is both right and left identity
 prop_Identity :: a             -- ^ Identity element
-              -> (a -> a -> a) -- ^ Function
-              -> T a
-              -> a -> Equal a
+              -> (a -> a -> a) -- ^ Associative operation
+              -> T a -> a -> Equal a
 prop_Identity = prop_LeftIdentity .&&. prop_RightIdentity
   
 
 prop_GroupInverse :: a             -- ^ Identity element
                   -> (a -> a -> a) -- ^ Group operation
                   -> (a -> a)      -- ^ Find inverse 
-                  -> T a
-                  -> a -> Equal a
+                  -> T a -> a -> Equal a
 prop_GroupInverse e (<>) inv T x =  ((x <> inv x) .==. e)
                                .&&. ((inv x <> x) .==. e)
 
+-- | Test that identity and associative operation satisfy monoid laws.
+prop_GenMonoid :: a             -- ^ Identity element
+               -> (a -> a -> a) -- ^ Associative operation
+               -> T a -> a -> a -> a -> Equal a
+prop_GenMonoid e (<>) T x y z =  prop_Associative   (<>) T x y z
+                         .&&. prop_Identity    e (<>) T x   
 
+-- | Test that identity, associative operation and inverse satisfy group laws
+prop_Group :: a                -- ^ Identity element
+           -> (a -> a -> a)    -- ^ Associative operation
+           -> (a -> a)         -- ^ Find inverse element
+           -> T a -> a -> a -> a -> Equal a
+prop_Group e (<>) inv T x y z =  prop_Identity     e (<>)     T x 
+                            .&&. prop_Associative    (<>)     T x y z
+                            .&&. prop_GroupInverse e (<>) inv T x