2017-10-03 16:15:45 +03:00
|
|
|
module Data.Functor.Classes.Ord.Generic.Spec where
|
|
|
|
|
2017-10-03 16:23:44 +03:00
|
|
|
import Data.Functor.Classes.Ord.Generic
|
|
|
|
import Data.Functor.Listable
|
|
|
|
import GHC.Generics
|
2017-10-03 16:15:45 +03:00
|
|
|
import Test.Hspec
|
2017-10-03 16:23:44 +03:00
|
|
|
import Test.Hspec.LeanCheck
|
2017-10-03 16:15:45 +03:00
|
|
|
|
|
|
|
spec :: Spec
|
2017-10-03 16:23:44 +03:00
|
|
|
spec = parallel $ do
|
|
|
|
describe "genericLiftCompare" $ do
|
|
|
|
prop "equivalent to derived compare for product types" $
|
|
|
|
\ a b -> genericLiftCompare compare a b `shouldBe` compare a (b :: Product Int)
|
|
|
|
|
2017-10-03 16:25:39 +03:00
|
|
|
prop "equivalent to derived compare for sum types" $
|
|
|
|
\ a b -> genericLiftCompare compare a b `shouldBe` compare a (b :: Sum Int)
|
|
|
|
|
|
|
|
|
2017-10-03 16:23:44 +03:00
|
|
|
data Product a = Product a a a
|
|
|
|
deriving (Eq, Generic1, Ord, Show)
|
|
|
|
|
|
|
|
instance Listable a => Listable (Product a) where
|
|
|
|
tiers = cons3 Product
|
2017-10-03 16:25:39 +03:00
|
|
|
|
|
|
|
data Sum a = Sum1 a | Sum2 a | Sum3 a
|
|
|
|
deriving (Eq, Generic1, Ord, Show)
|
|
|
|
|
|
|
|
instance Listable a => Listable (Sum a) where
|
|
|
|
tiers = cons1 Sum1 \/ cons1 Sum2 \/ cons1 Sum3
|