mirror of
https://github.com/github/semantic.git
synced 2024-12-01 00:33:59 +03:00
Test that genericLiftCompare gives equivalent behaviour to compare for recursive types.
This commit is contained in:
parent
5a024b40f7
commit
ac3646f925
@ -1,5 +1,6 @@
|
||||
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
|
||||
@ -15,6 +16,9 @@ spec = parallel $ do
|
||||
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)
|
||||
@ -27,3 +31,12 @@ data Sum a = Sum1 a | Sum2 a | Sum3 a
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user