055c62677203177038654705152ab6975bdd7600
[packages/containers.git] / tests / listutils-properties.hs
1 module Main where
2
3 import Data.List (nub, nubBy)
4 import Data.Containers.ListUtils
5 import Test.Framework
6 import Test.Framework.Providers.QuickCheck2
7 import Test.QuickCheck (Property, (===))
8 import Test.QuickCheck.Function (Fun, apply)
9 import Test.QuickCheck.Poly (A, OrdA, B, OrdB, C)
10
11 main :: IO ()
12 main = defaultMain
13 [ testProperty "nubOrd" prop_nubOrd
14 , testProperty "nubOrdOn" prop_nubOrdOn
15 , testProperty "nubOrdOn fusion" prop_nubOrdOnFusion
16 , testProperty "nubInt" prop_nubInt
17 , testProperty "nubIntOn" prop_nubIntOn
18 , testProperty "nubIntOn fusion" prop_nubIntOnFusion
19 ]
20
21
22 prop_nubOrd :: [OrdA] -> Property
23 prop_nubOrd xs = nubOrd xs === nub xs
24
25 prop_nubInt :: [Int] -> Property
26 prop_nubInt xs = nubInt xs === nub xs
27
28 prop_nubOrdOn :: Fun A OrdB -> [A] -> Property
29 prop_nubOrdOn f' xs =
30 nubOrdOn f xs === nubBy (\x y -> f x == f y) xs
31 where f = apply f'
32
33 prop_nubIntOn :: Fun A Int -> [A] -> Property
34 prop_nubIntOn f' xs =
35 nubIntOn f xs === nubBy (\x y -> f x == f y) xs
36 where f = apply f'
37
38 prop_nubOrdOnFusion :: Fun B C
39 -> Fun B OrdB
40 -> Fun A B
41 -> [A] -> Property
42 prop_nubOrdOnFusion f' g' h' xs =
43 (map f . nubOrdOn g . map h $ xs)
44 === (map f . nubBy (\x y -> g x == g y) . map h $ xs)
45 where
46 f = apply f'
47 g = apply g'
48 h = apply h'
49
50 prop_nubIntOnFusion :: Fun B C
51 -> Fun B Int
52 -> Fun A B
53 -> [A] -> Property
54 prop_nubIntOnFusion f' g' h' xs =
55 (map f . nubIntOn g . map h $ xs)
56 === (map f . nubBy (\x y -> g x == g y) . map h $ xs)
57 where
58 f = apply f'
59 g = apply g'
60 h = apply h'