1 -- to suppress WARNING in "Distribution.Compat.Prelude.Internal"
2 {-# OPTIONS_GHC -fno-warn-deprecations #-}
3 module UnitTests
.Distribution
.Utils
.NubList
8 import Distribution
.Compat
.Prelude
.Internal
10 import Distribution
.Utils
.NubList
12 import Test
.Tasty
.HUnit
13 import Test
.Tasty
.QuickCheck
17 [ testCase
"NubList retains ordering example" testOrdering
18 , testCase
"NubList removes duplicates example" testDeDupe
19 , testProperty
"NubList retains ordering" prop_Ordering
20 , testProperty
"NubList removes duplicates" prop_DeDupe
21 , testProperty
"fromNubList . toNubList = nub" prop_Nub
22 , testProperty
"Monoid NubList Identity" prop_Identity
23 , testProperty
"Monoid NubList Associativity" prop_Associativity
25 , testProperty
"NubListR removes duplicates from the right" prop_DeDupeR
29 -- This list must not have duplicate entries.
30 someIntList
= [ 1, 3, 4, 2, 0, 7, 6, 5, 9, -1 ]
32 testOrdering
:: Assertion
34 assertBool
"Maintains element ordering:" $
35 fromNubList
(toNubList someIntList
) == someIntList
37 testDeDupe
:: Assertion
39 assertBool
"De-duplicates a list:" $
40 fromNubList
(toNubList
(someIntList
++ someIntList
)) == someIntList
42 -- ---------------------------------------------------------------------------
43 -- QuickCheck properties for NubList
45 prop_Ordering
:: [Int] -> Property
47 mempty
<> toNubList xs
' === toNubList xs
' <> mempty
51 prop_DeDupe
:: [Int] -> Property
53 fromNubList
(toNubList
(xs
' ++ xs
)) === xs
' -- Note, we append primeless xs
57 prop_DeDupeR
:: [Int] -> Property
59 fromNubListR
(toNubListR
(xs
++ xs
')) === xs
' -- Note, we prepend primeless xs
63 prop_Nub
:: [Int] -> Property
64 prop_Nub xs
= rhs
=== lhs
66 rhs
= fromNubList
(toNubList xs
)
69 prop_Identity
:: [Int] -> Bool
71 mempty `mappend` toNubList xs
== toNubList xs `mappend` mempty
73 prop_Associativity
:: [Int] -> [Int] -> [Int] -> Bool
74 prop_Associativity xs ys zs
=
75 (toNubList xs `mappend` toNubList ys
) `mappend` toNubList zs
76 == toNubList xs `mappend`
(toNubList ys `mappend` toNubList zs
)