Commit bd3e80f4 authored by dsf's avatar dsf Committed by Duncan Coutts
Browse files

Restore the lost unit tests for version numbers

These were dropped during the migration to github.  This patch restores
them, but note that they do not all pass!
parent 7a715a1b
......@@ -266,6 +266,7 @@ test-suite unit-tests
tasty,
tasty-hunit,
tasty-quickcheck,
pretty,
QuickCheck < 2.9,
Cabal
ghc-options: -Wall
......
This diff is collapsed.
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
module Test.Laws where
import Prelude hiding (Num((+), (*)))
import Data.Monoid (Monoid(..), Endo(..))
import qualified Data.Foldable as Foldable
idempotent_unary f x = f fx == fx where fx = f x
-- Basic laws on binary operators
idempotent_binary (+) x = x + x == x
commutative (+) x y = x + y == y + x
associative (+) x y z = (x + y) + z == x + (y + z)
distributive_left (*) (+) x y z = x * (y + z) == (x * y) + (x * z)
distributive_right (*) (+) x y z = (y + z) * x == (y * x) + (z * x)
-- | The first 'fmap' law
--
-- > fmap id == id
--
fmap_1 :: (Eq (f a), Functor f) => f a -> Bool
fmap_1 x = fmap id x == x
-- | The second 'fmap' law
--
-- > fmap (f . g) == fmap f . fmap g
--
fmap_2 :: (Eq (f c), Functor f) => (b -> c) -> (a -> b) -> f a -> Bool
fmap_2 f g x = fmap (f . g) x == (fmap f . fmap g) x
-- | The monoid identity law, 'mempty' is a left and right identity of
-- 'mappend':
--
-- > mempty `mappend` x = x
-- > x `mappend` mempty = x
--
monoid_1 :: (Eq a, Data.Monoid.Monoid a) => a -> Bool
monoid_1 x = mempty `mappend` x == x
&& x `mappend` mempty == x
-- | The monoid associativity law, 'mappend' must be associative.
--
-- > (x `mappend` y) `mappend` z = x `mappend` (y `mappend` z)
--
monoid_2 :: (Eq a, Data.Monoid.Monoid a) => a -> a -> a -> Bool
monoid_2 x y z = (x `mappend` y) `mappend` z
== x `mappend` (y `mappend` z)
-- | The 'mconcat' definition. It can be overidden for the sake of effeciency
-- but it must still satisfy the property given by the default definition:
--
-- > mconcat = foldr mappend mempty
--
monoid_3 :: (Eq a, Data.Monoid.Monoid a) => [a] -> Bool
monoid_3 xs = mconcat xs == foldr mappend mempty xs
-- | First 'Foldable' law
--
-- > Foldable.fold = Foldable.foldr mappend mempty
--
foldable_1 :: (Foldable.Foldable t, Monoid m, Eq m) => t m -> Bool
foldable_1 x = Foldable.fold x == Foldable.foldr mappend mempty x
-- | Second 'Foldable' law
--
-- > foldr f z t = appEndo (foldMap (Endo . f) t) z
--
foldable_2 :: (Foldable.Foldable t, Eq b)
=> (a -> b -> b) -> b -> t a -> Bool
foldable_2 f z t = Foldable.foldr f z t
== appEndo (Foldable.foldMap (Endo . f) t) z
module Test.QuickCheck.Utils where
import Test.QuickCheck.Gen
-- | Adjust the size of the generated value.
--
-- In general the size gets bigger and bigger linearly. For some types
-- it is not appropriate to generate ever bigger values but instead
-- to generate lots of intermediate sized values. You could do that using:
--
-- > adjustSize (\n -> min n 5)
--
-- Similarly, for some types the linear size growth may mean getting too big
-- too quickly relative to other values. So you may want to adjust how
-- quickly the size grows. For example dividing by a constant, or even
-- something like the integer square root or log.
--
-- > adjustSize (\n -> n `div` 2)
--
-- Putting this together we can make for example a relatively short list:
--
-- > adjustSize (\n -> min 5 (n `div` 3)) (listOf1 arbitrary)
--
-- Not only do we put a limit on the length but we also scale the growth to
-- prevent it from hitting the maximum size quite so early.
--
adjustSize :: (Int -> Int) -> Gen a -> Gen a
adjustSize adjust gen = sized (\n -> resize (adjust n) gen)
......@@ -8,6 +8,7 @@ import qualified UnitTests.Distribution.Compat.CreatePipe
import qualified UnitTests.Distribution.Compat.ReadP
import qualified UnitTests.Distribution.Simple.Program.Internal
import qualified UnitTests.Distribution.Utils.NubList
import qualified Test.Distribution.Version (versionTests, parseTests)
tests :: TestTree
tests = testGroup "Unit Tests" $
......@@ -19,6 +20,8 @@ tests = testGroup "Unit Tests" $
UnitTests.Distribution.Simple.Program.Internal.tests
, testGroup "Distribution.Utils.NubList"
UnitTests.Distribution.Utils.NubList.tests
, Test.Distribution.Version.versionTests
, Test.Distribution.Version.parseTests
]
main :: IO ()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment