Skip to content

Commit

Permalink
Add more quickcheck properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
George Roldugin committed May 31, 2011
1 parent 7652618 commit 47cb9fa
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
16 changes: 16 additions & 0 deletions examples/quickcheck/tests/Unlifted_Basics.hs
@@ -1,3 +1,4 @@

import Testsuite

import Data.Array.Parallel.Unlifted as U
Expand Down Expand Up @@ -31,6 +32,17 @@ $(testcases [ "" <@ [t| ( Bool, Int ) |]
prop_replicate (Len n) x =
toList (U.replicate n x) == P.replicate n x

prop_repeat :: (Eq a, Elt a) => Len -> Len -> Array a -> Bool
prop_repeat (Len n) (Len dummy) arr =
toList (U.repeat n dummy arr) == (P.concat $ P.replicate n (toList arr))

prop_interleave :: (Eq a, Elt a) => Array a -> Array a -> Bool
prop_interleave arr brr =
toList (U.interleave arr brr) == interleave (toList arr) (toList brr)
where interleave (x:xs) (y:ys) = x : y : (interleave xs ys)
interleave (x:_) _ = [x]
interleave _ _ = []

prop_index :: (Eq a, Elt a) => Array a -> Len -> Property
prop_index arr (Len i) =
i < U.length arr
Expand All @@ -40,6 +52,10 @@ $(testcases [ "" <@ [t| ( Bool, Int ) |]
prop_append arr brr =
toList (arr +:+ brr) == toList arr ++ toList brr

prop_indexed :: (Eq a, Elt a) => Array a -> Bool
prop_indexed arr =
toList (indexed arr) == P.zip [0..U.length arr - 1] (toList arr)

-- Equality
-- --------

Expand Down
28 changes: 24 additions & 4 deletions examples/quickcheck/tests/Unlifted_Combinators.hs
Expand Up @@ -37,6 +37,23 @@ $(testcases [ "" <@ [t| ( Bool, Int ) |]

-- missing: combine2

prop_zip :: (Eq a, Elt a, Eq b, Elt b) => Array a -> Array b -> Bool
prop_zip arr brr =
toList (U.zip arr brr) == P.zip (toList arr) (toList brr)

prop_unzip :: (Eq a, Elt a, Eq b, Elt b) => Array (a, b) -> Bool
prop_unzip abrr =
(toList arr, toList brr) == P.unzip (toList abrr)
where (arr, brr) = U.unzip abrr

prop_fsts :: (Eq a, Elt a, Elt b) => Array (a, b) -> Bool
prop_fsts arr =
fsts arr == fst (U.unzip arr)

prop_snds :: (Elt a, Eq b, Elt b) => Array (a, b) -> Bool
prop_snds arr =
snds arr == snd (U.unzip arr)

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)
Expand All @@ -46,15 +63,18 @@ $(testcases [ "" <@ [t| ( Bool, Int ) |]
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)
-- TODO: Guarrantee associativity of the passed function
-- 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)

-- TODO: Guarrantee associativity of the passed function
prop_fold1 :: (Elt a, Eq a) => (a -> a -> a) -> Array a -> Property
prop_fold1 f arr =
not (null $ toList arr)
arr /= empty
==> U.fold1 f arr == P.foldl1 f (toList arr)

-- TODO: Guarrantee associativity of the passed function
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))
Expand Down
15 changes: 15 additions & 0 deletions examples/quickcheck/tests/Unlifted_Permutes.hs
Expand Up @@ -39,5 +39,20 @@ $(testcases [ "" <@ [t| ( Bool, Int ) |]

pairs' = if n <= 0 then U.zip empty empty
else U.map (\(i,x) -> (i `mod` n, x)) pairs

prop_update :: (Eq a, Elt a) => Array a -> Array (Int, a) -> Bool
prop_update arr pairs =
toList (U.update arr pairs') == update (toList arr) (toList pairs')
where
-- update :: [a] -> [(Int, a)] -> [a]
update xs [] = xs
update xs ((i,x):ps) = update (set xs i x) ps
-- set :: [a] -> Int -> a -> [a]
set xs i x = (P.take i xs) ++ [x] ++ (P.drop (i+1) xs)

pairs' = if n <= 0 then U.zip empty empty
else U.map (\(i,x) -> (i `mod` n, x)) pairs
n = U.length arr

|])

0 comments on commit 47cb9fa

Please sign in to comment.