1
1
mirror of https://github.com/github/semantic.git synced 2024-12-28 17:32:05 +03:00
semantic/test/Data/Functor/Classes/Ord/Generic/Spec.hs
2017-10-03 09:29:15 -04:00

45 lines
1.3 KiB
Haskell

module Data.Functor.Classes.Ord.Generic.Spec where
import Data.Functor.Classes.Eq.Generic
import Data.Functor.Classes.Ord.Generic
import Data.Functor.Listable
import GHC.Generics
import Test.Hspec
import Test.Hspec.LeanCheck
spec :: Spec
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)
prop "equivalent to derived compare for sum types" $
\ a b -> genericLiftCompare compare a b `shouldBe` compare a (b :: Sum Int)
prop "equivalent to derived compare for recursive types" $
\ a b -> genericLiftCompare compare a b `shouldBe` compare a (b :: Tree Int)
data Product a = Product a a a
deriving (Eq, Generic1, Ord, Show)
instance Listable a => Listable (Product a) where
tiers = cons3 Product
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
data Tree a = Leaf a | Branch [Tree a]
deriving (Eq, Generic1, Ord, Show)
instance Listable a => Listable (Tree a) where
tiers = cons1 Leaf \/ cons1 Branch
instance Eq1 Tree where liftEq = genericLiftEq
instance Ord1 Tree where liftCompare = genericLiftCompare