[commit: packages/containers] ghc-head: Add fromList tests to Map and IntMap. (24a226a)

git at git.haskell.org git at git.haskell.org
Fri Aug 30 13:33:44 CEST 2013


Repository : ssh://git@git.haskell.org/containers

On branch  : ghc-head
Link       : http://git.haskell.org/?p=packages/containers.git;a=commit;h=24a226afa7ad669672f58021c84079751dec6171

>---------------------------------------------------------------

commit 24a226afa7ad669672f58021c84079751dec6171
Author: Milan Straka <fox at ucw.cz>
Date:   Thu Aug 30 17:26:32 2012 +0200

    Add fromList tests to Map and IntMap.
    
    This test makes sure that fromList, fromAscList and
    fromDistinctAscList returns the same map.


>---------------------------------------------------------------

24a226afa7ad669672f58021c84079751dec6171
 tests/intmap-properties.hs |   10 ++++++++++
 tests/map-properties.hs    |   16 +++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/tests/intmap-properties.hs b/tests/intmap-properties.hs
index 4f5d06e..a5decbe 100644
--- a/tests/intmap-properties.hs
+++ b/tests/intmap-properties.hs
@@ -137,6 +137,7 @@ main = defaultMainWithOpts
              , testProperty "fromList then toList" prop_list
              , testProperty "toDescList"           prop_descList
              , testProperty "toAscList+toDescList" prop_ascDescList
+             , testProperty "fromList"             prop_fromList
              , testProperty "alter"                prop_alter
              , testProperty "index"                prop_index
              , testProperty "null"                 prop_null
@@ -853,6 +854,15 @@ prop_ascDescList :: [Int] -> Bool
 prop_ascDescList xs = toAscList m == reverse (toDescList m)
   where m = fromList $ zip xs $ repeat ()
 
+prop_fromList :: [Int] -> Bool
+prop_fromList xs
+  = case fromList (zip xs xs) of
+      t -> t == fromAscList (zip sort_xs sort_xs) &&
+           t == fromDistinctAscList (zip nub_sort_xs nub_sort_xs) &&
+           t == List.foldr (uncurry insert) empty (zip xs xs)
+  where sort_xs = sort xs
+        nub_sort_xs = List.map List.head $ List.group sort_xs
+
 ----------------------------------------------------------------
 
 prop_alter :: UMap -> Int -> Bool
diff --git a/tests/map-properties.hs b/tests/map-properties.hs
index 4b2817f..9975b0e 100644
--- a/tests/map-properties.hs
+++ b/tests/map-properties.hs
@@ -126,7 +126,7 @@ main = defaultMainWithOpts
          , testCase "minViewWithKey" test_minViewWithKey
          , testCase "maxViewWithKey" test_maxViewWithKey
          , testCase "valid" test_valid
-         , testProperty "fromList"             prop_fromList
+         , testProperty "valid"                prop_valid
          , testProperty "insert to singleton"  prop_singleton
          , testProperty "insert"               prop_insert
          , testProperty "insert then lookup"   prop_insertLookup
@@ -158,6 +158,7 @@ main = defaultMainWithOpts
          , testProperty "fromList then toList" prop_list
          , testProperty "toDescList"           prop_descList
          , testProperty "toAscList+toDescList" prop_ascDescList
+         , testProperty "fromList"             prop_fromList
          , testProperty "alter"                prop_alter
          , testProperty "index"                prop_index
          , testProperty "null"                 prop_null
@@ -831,8 +832,8 @@ test_valid = do
 -- QuickCheck
 ----------------------------------------------------------------
 
-prop_fromList :: UMap -> Bool
-prop_fromList t = valid t
+prop_valid :: UMap -> Bool
+prop_valid t = valid t
 
 prop_singleton :: Int -> Int -> Bool
 prop_singleton k x = insert k x empty == singleton k x
@@ -990,6 +991,15 @@ prop_ascDescList :: [Int] -> Bool
 prop_ascDescList xs = toAscList m == reverse (toDescList m)
   where m = fromList $ zip xs $ repeat ()
 
+prop_fromList :: [Int] -> Bool
+prop_fromList xs
+  = case fromList (zip xs xs) of
+      t -> t == fromAscList (zip sort_xs sort_xs) &&
+           t == fromDistinctAscList (zip nub_sort_xs nub_sort_xs) &&
+           t == List.foldr (uncurry insert) empty (zip xs xs)
+  where sort_xs = sort xs
+        nub_sort_xs = List.map List.head $ List.group sort_xs
+
 ----------------------------------------------------------------
 
 prop_alter :: UMap -> Int -> Bool





More information about the ghc-commits mailing list