[commit: dph] master: Updated old quickcheck tests. (2465b8b)
Ben Lippmeier
benl at ouroborus.net
Thu Jun 2 09:15:01 CEST 2011
Repository : ssh://darcs.haskell.org//srv/darcs/packages/dph
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/2465b8b79dfad6db6b923f841f3e36af1dd7ed9c
>---------------------------------------------------------------
commit 2465b8b79dfad6db6b923f841f3e36af1dd7ed9c
Author: George Roldugin <groldugin at cse.unsw.edu.au>
Date: Sun May 8 19:26:17 2011 +1000
Updated old quickcheck tests.
>---------------------------------------------------------------
examples/quickcheck/tests/Unlifted_Basics.hs | 52 ++++++++++++++++
examples/quickcheck/tests/Unlifted_Combinators.hs | 63 ++++++++++++++++++++
examples/quickcheck/tests/Unlifted_Subarrays.hs | 23 +++++++
examples/quickcheck/tests/Unlifted_Sums.hs | 65 +++++++++++++++++++++
4 files changed, 203 insertions(+), 0 deletions(-)
diff --git a/examples/quickcheck/tests/Unlifted_Basics.hs b/examples/quickcheck/tests/Unlifted_Basics.hs
new file mode 100644
index 0000000..756569b
--- /dev/null
+++ b/examples/quickcheck/tests/Unlifted_Basics.hs
@@ -0,0 +1,52 @@
+import Testsuite
+
+import Data.Array.Parallel.Unlifted as U
+import Prelude as P
+
+$(testcases [ "" <@ [t| ( Bool, Int ) |]
+ , "acc" <@ [t| ( Int ) |]
+ , "num" <@ [t| ( Int ) |]
+ , "ord" <@ [t| ( Bool, Int ) |]
+ , "enum" <@ [t| ( Bool, Int ) |]
+ ]
+ [d|
+ -- if this doesn't work nothing else will, so run this first
+ prop_toList_fromList :: (Eq a, Elt a) => [a] -> Bool
+ prop_toList_fromList xs = toList (fromList xs) == xs
+
+ prop_length :: Elt a => Array a -> Bool
+ prop_length arr = U.length arr == P.length (toList arr)
+
+ --prop_nullU :: UA a => UArr a -> Bool
+ --prop_nullU arr = nullU arr == (lengthU arr == 0)
+
+ prop_empty :: (Eq a, Elt a) => a -> Bool
+ prop_empty x = toList empty == tail [x]
+
+ --prop_unitsU :: Len -> Bool
+ --prop_unitsU (Len n) =
+ -- toList (unitsU n) == replicate n ()
+
+ prop_replicate :: (Eq a, Elt a) => Len -> a -> Bool
+ prop_replicate (Len n) x =
+ toList (U.replicate n x) == P.replicate n x
+
+ prop_index :: (Eq a, Elt a) => Array a -> Len -> Property
+ prop_index arr (Len i) =
+ i < U.length arr
+ ==> (arr !: i) == (toList arr !! i)
+
+ prop_append :: (Eq a, Elt a) => Array a -> Array a -> Bool
+ prop_append arr brr =
+ toList (arr +:+ brr) == toList arr ++ toList brr
+
+ -- Equality
+ -- --------
+
+ prop_eqU_1 :: (Eq a, Elt a) => Array a -> Bool
+ prop_eqU_1 arr = arr == arr
+
+ prop_eqU_2 :: (Eq a, Elt a) => Array a -> Array a -> Bool
+ prop_eqU_2 arr brr = (arr == brr) == (toList arr == toList brr)
+ |])
+
diff --git a/examples/quickcheck/tests/Unlifted_Combinators.hs b/examples/quickcheck/tests/Unlifted_Combinators.hs
new file mode 100644
index 0000000..124c34d
--- /dev/null
+++ b/examples/quickcheck/tests/Unlifted_Combinators.hs
@@ -0,0 +1,63 @@
+import Testsuite
+
+import Data.Array.Parallel.Unlifted as U
+import Prelude as P
+
+$(testcases [ "" <@ [t| ( Bool, Int ) |]
+ , "acc" <@ [t| ( Int ) |]
+ , "num" <@ [t| ( Int ) |]
+ , "ord" <@ [t| ( Bool, Int ) |]
+ , "enum" <@ [t| ( Bool, Int ) |]
+ ]
+ [d|
+ prop_map :: (Elt a, Eq b, Elt b) => (a -> b) -> Array a -> Bool
+ prop_map f arr =
+ toList (U.map f arr) == P.map f (toList arr)
+
+ prop_filter :: (Eq a, Elt a) => (a -> Bool) -> Array a -> Bool
+ prop_filter pred arr =
+ toList (U.filter pred arr) == P.filter pred (toList arr)
+
+ prop_pack :: (Eq a, Elt a) => Array a -> Array Bool -> Bool
+ prop_pack arr flags =
+ toList (U.pack arr flags) == [x | (x,flag) <- P.zip arr' flags', flag]
+ where arr' = toList arr
+ flags' = toList flags
+
+ prop_combine :: (Eq a, Elt a) => Array Bool -> Array a -> Array a -> Property
+ prop_combine sel arr brr =
+ (count sel True <= U.length arr && count sel False <= U.length brr)
+ ==> toList (combine sel arr brr) == combine' (toList sel) (toList arr) (toList brr)
+ where
+ -- combine' :: [Bool] -> [a] -> [a] -> [a]
+ combine' [] [] [] = []
+ combine' (True : ss) (x : xs) ys = x : combine' ss xs ys
+ combine' (False : ss) xs (y : ys) = y : combine' ss xs ys
+ combine' _ _ _ = []
+
+ -- missing: combine2
+
+ prop_zipWith :: (Elt a, Elt b, Eq c, Elt c) => (a -> b -> c) -> Array a -> Array b -> Bool
+ prop_zipWith f arr brr =
+ toList (U.zipWith f arr brr) == P.zipWith f (toList arr) (toList brr)
+
+ prop_zipWith3 :: (Elt a, Elt b, Elt c, Eq d, Elt d)
+ => (a -> b -> c -> d) -> Array a -> Array b -> Array c -> Bool
+ prop_zipWith3 f arr brr crr =
+ toList (U.zipWith3 f arr brr crr) == P.zipWith3 f (toList arr) (toList brr) (toList crr)
+
+ prop_fold :: (Elt a, Eq a) => (a -> a -> a) -> a -> Array a -> Bool
+ prop_fold f z arr =
+ U.fold f z arr == P.foldl f z (toList arr)
+
+ prop_fold1 :: (Elt a, Eq a) => (a -> a -> a) -> Array a -> Property
+ prop_fold1 f arr =
+ not (null $ toList arr)
+ ==> U.fold1 f arr == P.foldl1 f (toList arr)
+
+ prop_scan :: (Elt a, Eq a) => (a -> a -> a) -> a -> Array a -> Bool
+ prop_scan f z arr =
+ toList (U.scan f z arr) == P.init (P.scanl f z (toList arr))
+
+ |])
+
diff --git a/examples/quickcheck/tests/Unlifted_Subarrays.hs b/examples/quickcheck/tests/Unlifted_Subarrays.hs
new file mode 100644
index 0000000..51c3f83
--- /dev/null
+++ b/examples/quickcheck/tests/Unlifted_Subarrays.hs
@@ -0,0 +1,23 @@
+import Testsuite
+
+import Data.Array.Parallel.Unlifted as U
+import Prelude as P
+
+$(testcases [ "" <@ [t| ( Bool, Int ) |]
+ , "acc" <@ [t| ( Int ) |]
+ , "num" <@ [t| ( Int ) |]
+ , "ord" <@ [t| ( Bool, Int ) |]
+ , "enum" <@ [t| ( Bool, Int ) |]
+ ]
+ [d|
+ prop_extract :: (Eq a, Elt a) => Array a -> Len -> Len -> Property
+ prop_extract arr (Len i) (Len n) =
+ i <= U.length arr && n <= U.length arr - i
+ ==> toList (U.extract arr i n) == take n (P.drop i $ toList arr)
+
+ prop_drop :: (Eq a, Elt a) => Len -> Array a -> Property
+ prop_drop (Len n) arr =
+ n <= U.length arr
+ ==> toList (U.drop n arr) == P.drop n (toList arr)
+ |])
+
diff --git a/examples/quickcheck/tests/Unlifted_Sums.hs b/examples/quickcheck/tests/Unlifted_Sums.hs
new file mode 100644
index 0000000..9cf2115
--- /dev/null
+++ b/examples/quickcheck/tests/Unlifted_Sums.hs
@@ -0,0 +1,65 @@
+import Testsuite
+
+import Data.Array.Parallel.Unlifted as U
+import Prelude as P
+
+$(testcases [ "" <@ [t| ( Bool, Int ) |]
+ , "acc" <@ [t| ( Int ) |]
+ , "num" <@ [t| ( Int ) |]
+ , "ord" <@ [t| ( Bool, Int ) |]
+ , "enum" <@ [t| ( Bool, Int ) |]
+ ]
+ [d|
+ -- Searching
+ -- ---------
+{-
+ prop_elem :: (Eq e, Elt e) => e -> Array e -> Bool
+ prop_elem x arr =
+ U.elem x arr == P.elem x (toList arr)
+
+ prop_notElemU :: (Eq e, Elt e) => e -> Array e -> Bool
+ prop_notElemU x arr =
+ notElemU x arr == notElem x (toList arr)
+-}
+ -- Logic operations
+ -- ----------------
+
+ prop_and :: Array Bool -> Bool
+ prop_and arr =
+ U.and arr == P.and (toList arr)
+{-
+ prop_orU :: Array Bool -> Bool
+ prop_orU arr =
+ orU arr == or (toList arr)
+
+ prop_anyU :: Elt e => (e -> Bool) -> Array e -> Bool
+ prop_anyU f arr =
+ anyU f arr == any f (toList arr)
+
+ prop_allU :: Elt e => (e -> Bool) -> Array e -> Bool
+ prop_allU f arr =
+ allU f arr == all f (toList arr)
+-}
+ -- Arithmetic operations
+ -- ---------------------
+
+ prop_sum :: (Eq num, Elt num, Num num) => Array num -> Bool
+ prop_sum arr =
+ U.sum arr == P.sum (toList arr)
+{-
+ prop_productU :: (Eq num, Elt num, Num num) => Array num -> Bool
+ prop_productU arr =
+ productU arr == product (toList arr)
+
+ prop_maximumU :: (Ord ord, Elt ord) => Array ord -> Property
+ prop_maximumU arr =
+ not (nullU arr)
+ ==> maximumU arr == maximum (toList arr)
+
+ prop_minimumU :: (Ord ord, Elt ord) => Array ord -> Property
+ prop_minimumU arr =
+ not (nullU arr)
+ ==> minimumU arr == minimum (toList arr)
+-}
+ |])
+
More information about the Cvs-libraries
mailing list