Commits

Aleksey Khudyakov  committed a3f4e8a

Rename module Utils to Common

  • Participants
  • Parent commits e7daae5

Comments (0)

Files changed (6)

File Test/QuickCheck/Property/Common.hs

+{-# LANGUAGE TypeFamilies      #-}
+{-# LANGUAGE FlexibleContexts  #-}
+{-# LANGUAGE FlexibleInstances #-}
+-- | 
+-- /Fixing type/
+--
+-- All properties in this library are polymorphic. Because of it
+-- following expression will be rejected by compiler (assuming that
+-- @someFunction@ is polymorphic.
+--
+-- > quickCheck (prop_Associative someFunction)
+--
+-- Method for fixing type is nessesary.
+--
+-- /Comparig for equality/
+--
+-- A lot of QuickCheck properties have form @expression = another
+-- expression@. It's natural to compare them for equality however not
+-- all types have 'Eq' instance. For example functions and hence many
+-- monads.
+--
+-- There are three generic ways to compare values for equality.
+--
+--  (1) Use '==' operator
+--
+--  2. Convert value to some type with Eq instance and compare
+--     them. Caller must ensure that such conversion make sence
+--
+--  3. Most generic: use custom comparison function.
+--
+-- Functions 'eq', 'eqOn' and 'eqWith' provide this functionality.
+module Test.QuickCheck.Property.Common (
+    -- * Comparison for equality
+    Equal(..)
+  , appEqual
+  , Equalable(..)
+  , eq
+  , eqOn
+  , eqWith
+    -- * Utils
+  , T(..)
+    -- * Examples
+  ) where
+
+import Data.Function (on)
+
+
+-- | Values to be compared for equality
+data Equal a = Equal a a
+
+-- | Perform comparison using custom function
+appEqual :: (a -> a -> Bool) -> Equal a -> Bool
+appEqual f (Equal a b) = f a b
+
+-- | Recurse through function to apply comparison to 'Equal'.
+class Equalable a where
+  -- | Type which should be compared for equality
+  type Result a :: *
+  -- | Result of comparison
+  type Compared a :: *
+  -- | Compare 
+  equalWith :: (Result a -> Result a -> Bool) -> a -> Compared a
+                
+instance Equalable (Equal a) where
+  type Result   (Equal a) = a
+  type Compared (Equal a) = Bool
+  equalWith = appEqual
+
+-- FIXME: Equalable is not composable. No way to compose two
+--        properties into one
+instance Equalable [Equal a] where
+  type Result   [Equal a] = a
+  type Compared [Equal a] = Bool
+  equalWith = all . appEqual
+  
+instance Equalable a => Equalable (x -> a) where
+  type Result   (x -> a) = Result a
+  type Compared (x -> a) = x -> Compared a
+  equalWith f fun = equalWith f . fun
+
+
+-- | Compare values using @==@ 
+eq :: (Equalable a, Eq (Result a)) => a -> Compared a
+eq = equalWith (==)
+
+-- | Convert values to types which could be compare
+eqOn :: (Equalable a, Eq b) => (Result a -> b) -> a -> Compared a
+eqOn f = equalWith ((==) `on` f)
+
+-- | Compare with custom function. Just a shorter sinonym for equalWith
+eqWith :: (Equalable a) => (Result a -> Result a -> Bool) -> a -> Compared a
+eqWith = equalWith
+
+
+-- | Data type is used to fix concrete data in properties
+data T a = T
+
+-- $examples
+-- 
+-- None so far

File Test/QuickCheck/Property/Functor.hs

 -- > fmap id = id
 -- > fmap f . fmap g = fmap (f . g)
 module Test.QuickCheck.Property.Functor (
-    module Test.QuickCheck.Property.Utils
+    module Test.QuickCheck.Property.Common
   , prop_FunctorId
   , prop_FunctorCompose
   ) where
 
-import Test.QuickCheck.Property.Utils
+import Test.QuickCheck.Property.Common
 
 -- | @fmap id = id@
 prop_FunctorId :: Functor f => T (f a) -> f a -> Equal (f a)

File Test/QuickCheck/Property/Generic.hs

 -- | Generic properties of functions
 module Test.QuickCheck.Property.Generic (
-    module Test.QuickCheck.Property.Utils
+    module Test.QuickCheck.Property.Common
     -- * General
   , prop_Reflexive
     -- * Monoids & group
   , prop_GroupInverse
   ) where
 
-import Test.QuickCheck.Property.Utils
+import Test.QuickCheck.Property.Common
 
 -- | Test that relation is reflective. 
 --

File Test/QuickCheck/Property/Monoid.hs

 -- | Properties for 'Monoid' type class
 module Test.QuickCheck.Property.Monoid (
-    module Test.QuickCheck.Property.Utils
+    module Test.QuickCheck.Property.Common
   , prop_MonoidLeft
   , prop_MonoidRight
   , prop_Mappend
 
 import Data.Monoid
 
-import Test.QuickCheck.Property.Utils
+import Test.QuickCheck.Property.Common
 import Test.QuickCheck.Property.Generic
 
 

File Test/QuickCheck/Property/Utils.hs

-{-# LANGUAGE TypeFamilies      #-}
-{-# LANGUAGE FlexibleContexts  #-}
-{-# LANGUAGE FlexibleInstances #-}
--- | 
--- /Fixing type/
---
--- All properties in this library are polymorphic. Because of it
--- following expression will be rejected by compiler (assuming that
--- @someFunction@ is polymorphic.
---
--- > quickCheck (prop_Associative someFunction)
---
--- Method for fixing type is nessesary.
---
--- /Comparig for equality/
---
--- A lot of QuickCheck properties have form @expression = another
--- expression@. It's natural to compare them for equality however not
--- all types have 'Eq' instance. For example functions and hence many
--- monads.
---
--- There are three generic ways to compare values for equality.
---
---  (1) Use '==' operator
---
---  2. Convert value to some type with Eq instance and compare
---     them. Caller must ensure that such conversion make sence
---
---  3. Most generic: use custom comparison function.
---
--- Functions 'eq', 'eqOn' and 'eqWith' provide this functionality.
-module Test.QuickCheck.Property.Utils (
-    -- * Comparison for equality
-    Equal(..)
-  , appEqual
-  , Equalable(..)
-  , eq
-  , eqOn
-  , eqWith
-    -- * Utils
-  , T(..)
-    -- * Examples
-  ) where
-
-import Data.Function (on)
-
-
--- | Values to be compared for equality
-data Equal a = Equal a a
-
--- | Perform comparison using custom function
-appEqual :: (a -> a -> Bool) -> Equal a -> Bool
-appEqual f (Equal a b) = f a b
-
--- | Recurse through function to apply comparison to 'Equal'.
-class Equalable a where
-  -- | Type which should be compared for equality
-  type Result a :: *
-  -- | Result of comparison
-  type Compared a :: *
-  -- | Compare 
-  equalWith :: (Result a -> Result a -> Bool) -> a -> Compared a
-                
-instance Equalable (Equal a) where
-  type Result   (Equal a) = a
-  type Compared (Equal a) = Bool
-  equalWith = appEqual
-
--- FIXME: Equalable is not composable. No way to compose two
---        properties into one
-instance Equalable [Equal a] where
-  type Result   [Equal a] = a
-  type Compared [Equal a] = Bool
-  equalWith = all . appEqual
-  
-instance Equalable a => Equalable (x -> a) where
-  type Result   (x -> a) = Result a
-  type Compared (x -> a) = x -> Compared a
-  equalWith f fun = equalWith f . fun
-
-
--- | Compare values using @==@ 
-eq :: (Equalable a, Eq (Result a)) => a -> Compared a
-eq = equalWith (==)
-
--- | Convert values to types which could be compare
-eqOn :: (Equalable a, Eq b) => (Result a -> b) -> a -> Compared a
-eqOn f = equalWith ((==) `on` f)
-
--- | Compare with custom function. Just a shorter sinonym for equalWith
-eqWith :: (Equalable a) => (Result a -> Result a -> Bool) -> a -> Compared a
-eqWith = equalWith
-
-
--- | Data type is used to fix concrete data in properties
-data T a = T
-
--- $examples
--- 
--- None so far

File quickcheck-properties.cabal

   Generic QuickCheck properties for standard type classes. Library
   provide set of generic properties for testing 
   .
-  See module 'Test.QuickCheck.Property.Utils' for general design of library 
+  See module 'Test.QuickCheck.Property.Common' for general design of library 
   and examples.
 
 Library
   Build-depends:       base >= 3 && < 5
-  Exposed-modules:     Test.QuickCheck.Property.Utils
+  Exposed-modules:     Test.QuickCheck.Property.Common
                        Test.QuickCheck.Property.Generic
                        Test.QuickCheck.Property.Monoid
                        Test.QuickCheck.Property.Functor