1 {-# OPTIONS_GHC -fno-warn-orphans #-}
2 module QuickCheck.Value where
5 import Data.List (head)
7 import QuickCheck.Merit
8 import QuickCheck.Utils
10 import Control.Monad (Monad(..))
11 import Data.Function (($), (.))
12 import Data.Functor ((<$>))
14 import Test.Tasty.QuickCheck
15 import Data.Eq (Eq(..))
16 import Data.Ord (Ord(..))
17 import Prelude (Enum(..), Integral(..), Bounded(..))
19 quickcheck :: TestTree
22 [ testGroup "MajorityValue"
23 [ testProperty "compare" $ \(SameLength (x::MajorityValue G6,y)) ->
24 expandValue x`compare` expandValue y == x`compare`y
29 (Bounded g, Eq g, Integral g, Arbitrary g) =>
30 Arbitrary (MajorityValue g) where
31 arbitrary = head . (majorityValue <$>) <$> arbitraryMerits 1
32 shrink (MajorityValue vs) = MajorityValue <$> shrink vs
33 instance (Bounded g, Enum g) => Arbitrary (Middle g) where
35 lowG <- choose (fromEnum(minBound::g), fromEnum(maxBound::g))
36 highG <- choose (lowG, fromEnum(maxBound::g))
37 share <- choose (0, 1)
38 return $ Middle share (toEnum lowG) (toEnum highG)
40 (Arbitrary g, Bounded g, Enum g, Ord g) =>
41 Arbitrary (SameLength (MajorityValue g, MajorityValue g)) where
43 SameLength (x,y) <- arbitrary
44 return $ SameLength (MajorityValue x, MajorityValue y)
46 (Arbitrary g, Bounded g, Enum g, Ord g) =>
47 Arbitrary (SameLength ([Middle g], [Middle g])) where
49 SameLength (m0, m1) <- arbitrary
51 ( unMajorityValue $ majorityValue m0
52 , unMajorityValue $ majorityValue m1 )