Adapt tests to new names and modules
[darcs-mirrors/vector.git] / tests / Tests / Vector.hs
1 module Tests.Vector (tests) where
2
3 import Boilerplater
4 import Utilities
5
6 import qualified Data.Vector.Generic as V
7 import qualified Data.Vector
8 import qualified Data.Vector.Primitive
9 import qualified Data.Vector.Storable
10 import qualified Data.Vector.Unboxed
11 import qualified Data.Vector.Fusion.Bundle as S
12
13 import Test.QuickCheck
14
15 import Test.Framework
16 import Test.Framework.Providers.QuickCheck2
17
18 import Text.Show.Functions ()
19 import Data.List
20 import Data.Monoid
21 import qualified Control.Applicative as Applicative
22 import System.Random (Random)
23
24 #define COMMON_CONTEXT(a, v) \
25 VANILLA_CONTEXT(a, v), VECTOR_CONTEXT(a, v)
26
27 #define VANILLA_CONTEXT(a, v) \
28 Eq a, Show a, Arbitrary a, CoArbitrary a, TestData a, Model a ~ a, EqTest a ~ Property
29
30 #define VECTOR_CONTEXT(a, v) \
31 Eq (v a), Show (v a), Arbitrary (v a), CoArbitrary (v a), TestData (v a), Model (v a) ~ [a], EqTest (v a) ~ Property, V.Vector v a
32
33 -- TODO: implement Vector equivalents of list functions for some of the commented out properties
34
35 -- TODO: test and implement some of these other Prelude functions:
36 -- mapM *
37 -- mapM_ *
38 -- sequence
39 -- sequence_
40 -- sum *
41 -- product *
42 -- scanl *
43 -- scanl1 *
44 -- scanr *
45 -- scanr1 *
46 -- lookup *
47 -- lines
48 -- words
49 -- unlines
50 -- unwords
51 -- NB: this is an exhaustive list of all Prelude list functions that make sense for vectors.
52 -- Ones with *s are the most plausible candidates.
53
54 -- TODO: add tests for the other extra functions
55 -- IVector exports still needing tests:
56 -- copy,
57 -- slice,
58 -- (//), update, bpermute,
59 -- prescanl, prescanl',
60 -- new,
61 -- unsafeSlice, unsafeIndex,
62 -- vlength, vnew
63
64 -- TODO: test non-IVector stuff?
65
66 testSanity :: forall a v. (COMMON_CONTEXT(a, v)) => v a -> [Test]
67 testSanity _ = [
68 testProperty "fromList.toList == id" prop_fromList_toList,
69 testProperty "toList.fromList == id" prop_toList_fromList,
70 testProperty "unstream.stream == id" prop_unstream_stream,
71 testProperty "stream.unstream == id" prop_stream_unstream
72 ]
73 where
74 prop_fromList_toList (v :: v a) = (V.fromList . V.toList) v == v
75 prop_toList_fromList (l :: [a]) = ((V.toList :: v a -> [a]) . V.fromList) l == l
76 prop_unstream_stream (v :: v a) = (V.unstream . V.stream) v == v
77 prop_stream_unstream (s :: S.Bundle v a) = ((V.stream :: v a -> S.Bundle v a) . V.unstream) s == s
78
79 testPolymorphicFunctions :: forall a v. (COMMON_CONTEXT(a, v), VECTOR_CONTEXT(Int, v)) => v a -> [Test]
80 testPolymorphicFunctions _ = $(testProperties [
81 'prop_eq,
82
83 -- Length information
84 'prop_length, 'prop_null,
85
86 -- Indexing (FIXME)
87 'prop_index, 'prop_safeIndex, 'prop_head, 'prop_last,
88 'prop_unsafeIndex, 'prop_unsafeHead, 'prop_unsafeLast,
89
90 -- Monadic indexing (FIXME)
91 {- 'prop_indexM, 'prop_headM, 'prop_lastM,
92 'prop_unsafeIndexM, 'prop_unsafeHeadM, 'prop_unsafeLastM, -}
93
94 -- Subvectors (FIXME)
95 'prop_slice, 'prop_init, 'prop_tail, 'prop_take, 'prop_drop,
96 'prop_splitAt,
97 {- 'prop_unsafeSlice, 'prop_unsafeInit, 'prop_unsafeTail,
98 'prop_unsafeTake, 'prop_unsafeDrop, -}
99
100 -- Initialisation (FIXME)
101 'prop_empty, 'prop_singleton, 'prop_replicate,
102 'prop_generate, 'prop_iterateN,
103
104 -- Monadic initialisation (FIXME)
105 {- 'prop_replicateM, 'prop_generateM, 'prop_create, -}
106
107 -- Unfolding (FIXME)
108 {- 'prop_unfoldr, prop_unfoldrN, -}
109 'prop_constructN, 'prop_constructrN,
110
111 -- Enumeration? (FIXME?)
112
113 -- Concatenation (FIXME)
114 'prop_cons, 'prop_snoc, 'prop_append,
115 'prop_concat,
116
117 -- Restricting memory usage
118 'prop_force,
119
120
121 -- Bulk updates (FIXME)
122 'prop_upd,
123 {- 'prop_update, 'prop_update_,
124 'prop_unsafeUpd, 'prop_unsafeUpdate, 'prop_unsafeUpdate_, -}
125
126 -- Accumulations (FIXME)
127 'prop_accum,
128 {- 'prop_accumulate, 'prop_accumulate_,
129 'prop_unsafeAccum, 'prop_unsafeAccumulate, 'prop_unsafeAccumulate_, -}
130
131 -- Permutations
132 'prop_reverse, 'prop_backpermute,
133 {- 'prop_unsafeBackpermute, -}
134
135 -- Elementwise indexing
136 {- 'prop_indexed, -}
137
138 -- Mapping
139 'prop_map, 'prop_imap, 'prop_concatMap,
140
141 -- Monadic mapping
142 {- 'prop_mapM, 'prop_mapM_, 'prop_forM, 'prop_forM_, -}
143
144 -- Zipping
145 'prop_zipWith, 'prop_zipWith3, {- ... -}
146 'prop_izipWith, 'prop_izipWith3, {- ... -}
147 {- 'prop_zip, ... -}
148
149 -- Monadic zipping
150 {- 'prop_zipWithM, 'prop_zipWithM_, -}
151
152 -- Unzipping
153 {- 'prop_unzip, ... -}
154
155 -- Filtering
156 'prop_filter, 'prop_ifilter, {- prop_filterM, -}
157 'prop_takeWhile, 'prop_dropWhile,
158
159 -- Paritioning
160 'prop_partition, {- 'prop_unstablePartition, -}
161 'prop_span, 'prop_break,
162
163 -- Searching
164 'prop_elem, 'prop_notElem,
165 'prop_find, 'prop_findIndex, 'prop_findIndices,
166 'prop_elemIndex, 'prop_elemIndices,
167
168 -- Folding
169 'prop_foldl, 'prop_foldl1, 'prop_foldl', 'prop_foldl1',
170 'prop_foldr, 'prop_foldr1, 'prop_foldr', 'prop_foldr1',
171 'prop_ifoldl, 'prop_ifoldl', 'prop_ifoldr, 'prop_ifoldr',
172
173 -- Specialised folds
174 'prop_all, 'prop_any,
175 {- 'prop_maximumBy, 'prop_minimumBy,
176 'prop_maxIndexBy, 'prop_minIndexBy, -}
177
178 -- Monadic folds
179 {- ... -}
180
181 -- Monadic sequencing
182 {- ... -}
183
184 -- Scans
185 'prop_prescanl, 'prop_prescanl',
186 'prop_postscanl, 'prop_postscanl',
187 'prop_scanl, 'prop_scanl', 'prop_scanl1, 'prop_scanl1',
188
189 'prop_prescanr, 'prop_prescanr',
190 'prop_postscanr, 'prop_postscanr',
191 'prop_scanr, 'prop_scanr', 'prop_scanr1, 'prop_scanr1'
192 ])
193 where
194 -- Prelude
195 prop_eq :: P (v a -> v a -> Bool) = (==) `eq` (==)
196
197 prop_length :: P (v a -> Int) = V.length `eq` length
198 prop_null :: P (v a -> Bool) = V.null `eq` null
199
200 prop_empty :: P (v a) = V.empty `eq` []
201 prop_singleton :: P (a -> v a) = V.singleton `eq` singleton
202 prop_replicate :: P (Int -> a -> v a)
203 = (\n _ -> n < 1000) ===> V.replicate `eq` replicate
204 prop_cons :: P (a -> v a -> v a) = V.cons `eq` (:)
205 prop_snoc :: P (v a -> a -> v a) = V.snoc `eq` snoc
206 prop_append :: P (v a -> v a -> v a) = (V.++) `eq` (++)
207 prop_concat :: P ([v a] -> v a) = V.concat `eq` concat
208 prop_force :: P (v a -> v a) = V.force `eq` id
209 prop_generate :: P (Int -> (Int -> a) -> v a)
210 = (\n _ -> n < 1000) ===> V.generate `eq` generate
211 prop_iterateN :: P (Int -> (a -> a) -> a -> v a)
212 = (\n _ _ -> n < 1000) ===> V.iterateN `eq` (\n f -> take n . iterate f)
213
214 prop_head :: P (v a -> a) = not . V.null ===> V.head `eq` head
215 prop_last :: P (v a -> a) = not . V.null ===> V.last `eq` last
216 prop_index = \xs ->
217 not (V.null xs) ==>
218 forAll (choose (0, V.length xs-1)) $ \i ->
219 unP prop xs i
220 where
221 prop :: P (v a -> Int -> a) = (V.!) `eq` (!!)
222 prop_safeIndex :: P (v a -> Int -> Maybe a) = (V.!?) `eq` fn
223 where
224 fn xs i = case drop i xs of
225 x:_ | i >= 0 -> Just x
226 _ -> Nothing
227 prop_unsafeHead :: P (v a -> a) = not . V.null ===> V.unsafeHead `eq` head
228 prop_unsafeLast :: P (v a -> a) = not . V.null ===> V.unsafeLast `eq` last
229 prop_unsafeIndex = \xs ->
230 not (V.null xs) ==>
231 forAll (choose (0, V.length xs-1)) $ \i ->
232 unP prop xs i
233 where
234 prop :: P (v a -> Int -> a) = V.unsafeIndex `eq` (!!)
235
236 prop_slice = \xs ->
237 forAll (choose (0, V.length xs)) $ \i ->
238 forAll (choose (0, V.length xs - i)) $ \n ->
239 unP prop i n xs
240 where
241 prop :: P (Int -> Int -> v a -> v a) = V.slice `eq` slice
242
243 prop_tail :: P (v a -> v a) = not . V.null ===> V.tail `eq` tail
244 prop_init :: P (v a -> v a) = not . V.null ===> V.init `eq` init
245 prop_take :: P (Int -> v a -> v a) = V.take `eq` take
246 prop_drop :: P (Int -> v a -> v a) = V.drop `eq` drop
247 prop_splitAt :: P (Int -> v a -> (v a, v a)) = V.splitAt `eq` splitAt
248
249 prop_accum = \f xs ->
250 forAll (index_value_pairs (V.length xs)) $ \ps ->
251 unP prop f xs ps
252 where
253 prop :: P ((a -> a -> a) -> v a -> [(Int,a)] -> v a)
254 = V.accum `eq` accum
255
256 prop_upd = \xs ->
257 forAll (index_value_pairs (V.length xs)) $ \ps ->
258 unP prop xs ps
259 where
260 prop :: P (v a -> [(Int,a)] -> v a) = (V.//) `eq` (//)
261
262 prop_backpermute = \xs ->
263 forAll (indices (V.length xs)) $ \is ->
264 unP prop xs (V.fromList is)
265 where
266 prop :: P (v a -> v Int -> v a) = V.backpermute `eq` backpermute
267
268 prop_reverse :: P (v a -> v a) = V.reverse `eq` reverse
269
270 prop_map :: P ((a -> a) -> v a -> v a) = V.map `eq` map
271 prop_zipWith :: P ((a -> a -> a) -> v a -> v a -> v a) = V.zipWith `eq` zipWith
272 prop_zipWith3 :: P ((a -> a -> a -> a) -> v a -> v a -> v a -> v a)
273 = V.zipWith3 `eq` zipWith3
274 prop_imap :: P ((Int -> a -> a) -> v a -> v a) = V.imap `eq` imap
275 prop_izipWith :: P ((Int -> a -> a -> a) -> v a -> v a -> v a) = V.izipWith `eq` izipWith
276 prop_izipWith3 :: P ((Int -> a -> a -> a -> a) -> v a -> v a -> v a -> v a)
277 = V.izipWith3 `eq` izipWith3
278
279 prop_filter :: P ((a -> Bool) -> v a -> v a) = V.filter `eq` filter
280 prop_ifilter :: P ((Int -> a -> Bool) -> v a -> v a) = V.ifilter `eq` ifilter
281 prop_takeWhile :: P ((a -> Bool) -> v a -> v a) = V.takeWhile `eq` takeWhile
282 prop_dropWhile :: P ((a -> Bool) -> v a -> v a) = V.dropWhile `eq` dropWhile
283 prop_partition :: P ((a -> Bool) -> v a -> (v a, v a))
284 = V.partition `eq` partition
285 prop_span :: P ((a -> Bool) -> v a -> (v a, v a)) = V.span `eq` span
286 prop_break :: P ((a -> Bool) -> v a -> (v a, v a)) = V.break `eq` break
287
288 prop_elem :: P (a -> v a -> Bool) = V.elem `eq` elem
289 prop_notElem :: P (a -> v a -> Bool) = V.notElem `eq` notElem
290 prop_find :: P ((a -> Bool) -> v a -> Maybe a) = V.find `eq` find
291 prop_findIndex :: P ((a -> Bool) -> v a -> Maybe Int)
292 = V.findIndex `eq` findIndex
293 prop_findIndices :: P ((a -> Bool) -> v a -> v Int)
294 = V.findIndices `eq` findIndices
295 prop_elemIndex :: P (a -> v a -> Maybe Int) = V.elemIndex `eq` elemIndex
296 prop_elemIndices :: P (a -> v a -> v Int) = V.elemIndices `eq` elemIndices
297
298 prop_foldl :: P ((a -> a -> a) -> a -> v a -> a) = V.foldl `eq` foldl
299 prop_foldl1 :: P ((a -> a -> a) -> v a -> a) = notNull2 ===>
300 V.foldl1 `eq` foldl1
301 prop_foldl' :: P ((a -> a -> a) -> a -> v a -> a) = V.foldl' `eq` foldl'
302 prop_foldl1' :: P ((a -> a -> a) -> v a -> a) = notNull2 ===>
303 V.foldl1' `eq` foldl1'
304 prop_foldr :: P ((a -> a -> a) -> a -> v a -> a) = V.foldr `eq` foldr
305 prop_foldr1 :: P ((a -> a -> a) -> v a -> a) = notNull2 ===>
306 V.foldr1 `eq` foldr1
307 prop_foldr' :: P ((a -> a -> a) -> a -> v a -> a) = V.foldr' `eq` foldr
308 prop_foldr1' :: P ((a -> a -> a) -> v a -> a) = notNull2 ===>
309 V.foldr1' `eq` foldr1
310 prop_ifoldl :: P ((a -> Int -> a -> a) -> a -> v a -> a)
311 = V.ifoldl `eq` ifoldl
312 prop_ifoldl' :: P ((a -> Int -> a -> a) -> a -> v a -> a)
313 = V.ifoldl' `eq` ifoldl
314 prop_ifoldr :: P ((Int -> a -> a -> a) -> a -> v a -> a)
315 = V.ifoldr `eq` ifoldr
316 prop_ifoldr' :: P ((Int -> a -> a -> a) -> a -> v a -> a)
317 = V.ifoldr' `eq` ifoldr
318
319 prop_all :: P ((a -> Bool) -> v a -> Bool) = V.all `eq` all
320 prop_any :: P ((a -> Bool) -> v a -> Bool) = V.any `eq` any
321
322 prop_prescanl :: P ((a -> a -> a) -> a -> v a -> v a)
323 = V.prescanl `eq` prescanl
324 prop_prescanl' :: P ((a -> a -> a) -> a -> v a -> v a)
325 = V.prescanl' `eq` prescanl
326 prop_postscanl :: P ((a -> a -> a) -> a -> v a -> v a)
327 = V.postscanl `eq` postscanl
328 prop_postscanl' :: P ((a -> a -> a) -> a -> v a -> v a)
329 = V.postscanl' `eq` postscanl
330 prop_scanl :: P ((a -> a -> a) -> a -> v a -> v a)
331 = V.scanl `eq` scanl
332 prop_scanl' :: P ((a -> a -> a) -> a -> v a -> v a)
333 = V.scanl' `eq` scanl
334 prop_scanl1 :: P ((a -> a -> a) -> v a -> v a) = notNull2 ===>
335 V.scanl1 `eq` scanl1
336 prop_scanl1' :: P ((a -> a -> a) -> v a -> v a) = notNull2 ===>
337 V.scanl1' `eq` scanl1
338
339 prop_prescanr :: P ((a -> a -> a) -> a -> v a -> v a)
340 = V.prescanr `eq` prescanr
341 prop_prescanr' :: P ((a -> a -> a) -> a -> v a -> v a)
342 = V.prescanr' `eq` prescanr
343 prop_postscanr :: P ((a -> a -> a) -> a -> v a -> v a)
344 = V.postscanr `eq` postscanr
345 prop_postscanr' :: P ((a -> a -> a) -> a -> v a -> v a)
346 = V.postscanr' `eq` postscanr
347 prop_scanr :: P ((a -> a -> a) -> a -> v a -> v a)
348 = V.scanr `eq` scanr
349 prop_scanr' :: P ((a -> a -> a) -> a -> v a -> v a)
350 = V.scanr' `eq` scanr
351 prop_scanr1 :: P ((a -> a -> a) -> v a -> v a) = notNull2 ===>
352 V.scanr1 `eq` scanr1
353 prop_scanr1' :: P ((a -> a -> a) -> v a -> v a) = notNull2 ===>
354 V.scanr1' `eq` scanr1
355
356 prop_concatMap = forAll arbitrary $ \xs ->
357 forAll (sized (\n -> resize (n `div` V.length xs) arbitrary)) $ \f -> unP prop f xs
358 where
359 prop :: P ((a -> v a) -> v a -> v a) = V.concatMap `eq` concatMap
360
361 --prop_span = (V.span :: (a -> Bool) -> v a -> (v a, v a)) `eq2` span
362 --prop_break = (V.break :: (a -> Bool) -> v a -> (v a, v a)) `eq2` break
363 --prop_splitAt = (V.splitAt :: Int -> v a -> (v a, v a)) `eq2` splitAt
364 --prop_all = (V.all :: (a -> Bool) -> v a -> Bool) `eq2` all
365 --prop_any = (V.any :: (a -> Bool) -> v a -> Bool) `eq2` any
366
367 -- Data.List
368 --prop_findIndices = V.findIndices `eq2` (findIndices :: (a -> Bool) -> v a -> v Int)
369 --prop_isPrefixOf = V.isPrefixOf `eq2` (isPrefixOf :: v a -> v a -> Bool)
370 --prop_elemIndex = V.elemIndex `eq2` (elemIndex :: a -> v a -> Maybe Int)
371 --prop_elemIndices = V.elemIndices `eq2` (elemIndices :: a -> v a -> v Int)
372 --
373 --prop_mapAccumL = eq3
374 -- (V.mapAccumL :: (X -> W -> (X,W)) -> X -> B -> (X, B))
375 -- ( mapAccumL :: (X -> W -> (X,W)) -> X -> [W] -> (X, [W]))
376 --
377 --prop_mapAccumR = eq3
378 -- (V.mapAccumR :: (X -> W -> (X,W)) -> X -> B -> (X, B))
379 -- ( mapAccumR :: (X -> W -> (X,W)) -> X -> [W] -> (X, [W]))
380
381 -- Because the vectors are strict, we need to be totally sure that the unfold eventually terminates. This
382 -- is achieved by injecting our own bit of state into the unfold - the maximum number of unfolds allowed.
383 limitUnfolds f (theirs, ours) | ours >= 0
384 , Just (out, theirs') <- f theirs = Just (out, (theirs', ours - 1))
385 | otherwise = Nothing
386 prop_unfoldr :: P (Int -> (Int -> Maybe (a,Int)) -> Int -> v a)
387 = (\n f a -> V.unfoldr (limitUnfolds f) (a, n))
388 `eq` (\n f a -> unfoldr (limitUnfolds f) (a, n))
389
390 prop_constructN = \f -> forAll (choose (0,20)) $ \n -> unP prop n f
391 where
392 prop :: P (Int -> (v a -> a) -> v a) = V.constructN `eq` constructN []
393
394 constructN xs 0 _ = xs
395 constructN xs n f = constructN (xs ++ [f xs]) (n-1) f
396
397 prop_constructrN = \f -> forAll (choose (0,20)) $ \n -> unP prop n f
398 where
399 prop :: P (Int -> (v a -> a) -> v a) = V.constructrN `eq` constructrN []
400
401 constructrN xs 0 _ = xs
402 constructrN xs n f = constructrN (f xs : xs) (n-1) f
403
404 testTuplyFunctions:: forall a v. (COMMON_CONTEXT(a, v), VECTOR_CONTEXT((a, a), v), VECTOR_CONTEXT((a, a, a), v)) => v a -> [Test]
405 testTuplyFunctions _ = $(testProperties ['prop_zip, 'prop_zip3, 'prop_unzip, 'prop_unzip3])
406 where
407 prop_zip :: P (v a -> v a -> v (a, a)) = V.zip `eq` zip
408 prop_zip3 :: P (v a -> v a -> v a -> v (a, a, a)) = V.zip3 `eq` zip3
409 prop_unzip :: P (v (a, a) -> (v a, v a)) = V.unzip `eq` unzip
410 prop_unzip3 :: P (v (a, a, a) -> (v a, v a, v a)) = V.unzip3 `eq` unzip3
411
412 testOrdFunctions :: forall a v. (COMMON_CONTEXT(a, v), Ord a, Ord (v a)) => v a -> [Test]
413 testOrdFunctions _ = $(testProperties
414 ['prop_compare,
415 'prop_maximum, 'prop_minimum,
416 'prop_minIndex, 'prop_maxIndex ])
417 where
418 prop_compare :: P (v a -> v a -> Ordering) = compare `eq` compare
419 prop_maximum :: P (v a -> a) = not . V.null ===> V.maximum `eq` maximum
420 prop_minimum :: P (v a -> a) = not . V.null ===> V.minimum `eq` minimum
421 prop_minIndex :: P (v a -> Int) = not . V.null ===> V.minIndex `eq` minIndex
422 prop_maxIndex :: P (v a -> Int) = not . V.null ===> V.maxIndex `eq` maxIndex
423
424 testEnumFunctions :: forall a v. (COMMON_CONTEXT(a, v), Enum a, Ord a, Num a, Random a) => v a -> [Test]
425 testEnumFunctions _ = $(testProperties
426 [ 'prop_enumFromN, 'prop_enumFromThenN,
427 'prop_enumFromTo, 'prop_enumFromThenTo])
428 where
429 prop_enumFromN :: P (a -> Int -> v a)
430 = (\_ n -> n < 1000)
431 ===> V.enumFromN `eq` (\x n -> take n $ scanl (+) x $ repeat 1)
432
433 prop_enumFromThenN :: P (a -> a -> Int -> v a)
434 = (\_ _ n -> n < 1000)
435 ===> V.enumFromStepN `eq` (\x y n -> take n $ scanl (+) x $ repeat y)
436
437 prop_enumFromTo = \m ->
438 forAll (choose (-2,100)) $ \n ->
439 unP prop m (m+n)
440 where
441 prop :: P (a -> a -> v a) = V.enumFromTo `eq` enumFromTo
442
443 prop_enumFromThenTo = \i j ->
444 j /= i ==>
445 forAll (choose (ks i j)) $ \k ->
446 unP prop i j k
447 where
448 prop :: P (a -> a -> a -> v a) = V.enumFromThenTo `eq` enumFromThenTo
449
450 ks i j | j < i = (i-d*100, i+d*2)
451 | otherwise = (i-d*2, i+d*100)
452 where
453 d = abs (j-i)
454
455 testMonoidFunctions :: forall a v. (COMMON_CONTEXT(a, v), Monoid (v a)) => v a -> [Test]
456 testMonoidFunctions _ = $(testProperties
457 [ 'prop_mempty, 'prop_mappend, 'prop_mconcat ])
458 where
459 prop_mempty :: P (v a) = mempty `eq` mempty
460 prop_mappend :: P (v a -> v a -> v a) = mappend `eq` mappend
461 prop_mconcat :: P ([v a] -> v a) = mconcat `eq` mconcat
462
463 testFunctorFunctions :: forall a v. (COMMON_CONTEXT(a, v), Functor v) => v a -> [Test]
464 testFunctorFunctions _ = $(testProperties
465 [ 'prop_fmap ])
466 where
467 prop_fmap :: P ((a -> a) -> v a -> v a) = fmap `eq` fmap
468
469 testMonadFunctions :: forall a v. (COMMON_CONTEXT(a, v), Monad v) => v a -> [Test]
470 testMonadFunctions _ = $(testProperties
471 [ 'prop_return, 'prop_bind ])
472 where
473 prop_return :: P (a -> v a) = return `eq` return
474 prop_bind :: P (v a -> (a -> v a) -> v a) = (>>=) `eq` (>>=)
475
476 testApplicativeFunctions :: forall a v. (COMMON_CONTEXT(a, v), V.Vector v (a -> a), Applicative.Applicative v) => v a -> [Test]
477 testApplicativeFunctions _ = $(testProperties
478 [ 'prop_applicative_pure, 'prop_applicative_appl ])
479 where
480 prop_applicative_pure :: P (a -> v a)
481 = Applicative.pure `eq` Applicative.pure
482 prop_applicative_appl :: [a -> a] -> P (v a -> v a)
483 = \fs -> (Applicative.<*>) (V.fromList fs) `eq` (Applicative.<*>) fs
484
485 testAlternativeFunctions :: forall a v. (COMMON_CONTEXT(a, v), Applicative.Alternative v) => v a -> [Test]
486 testAlternativeFunctions _ = $(testProperties
487 [ 'prop_alternative_empty, 'prop_alternative_or ])
488 where
489 prop_alternative_empty :: P (v a) = Applicative.empty `eq` Applicative.empty
490 prop_alternative_or :: P (v a -> v a -> v a)
491 = (Applicative.<|>) `eq` (Applicative.<|>)
492
493 testBoolFunctions :: forall v. (COMMON_CONTEXT(Bool, v)) => v Bool -> [Test]
494 testBoolFunctions _ = $(testProperties ['prop_and, 'prop_or])
495 where
496 prop_and :: P (v Bool -> Bool) = V.and `eq` and
497 prop_or :: P (v Bool -> Bool) = V.or `eq` or
498
499 testNumFunctions :: forall a v. (COMMON_CONTEXT(a, v), Num a) => v a -> [Test]
500 testNumFunctions _ = $(testProperties ['prop_sum, 'prop_product])
501 where
502 prop_sum :: P (v a -> a) = V.sum `eq` sum
503 prop_product :: P (v a -> a) = V.product `eq` product
504
505 testNestedVectorFunctions :: forall a v. (COMMON_CONTEXT(a, v)) => v a -> [Test]
506 testNestedVectorFunctions _ = $(testProperties [])
507 where
508 -- Prelude
509 --prop_concat = (V.concat :: [v a] -> v a) `eq1` concat
510
511 -- Data.List
512 --prop_transpose = V.transpose `eq1` (transpose :: [v a] -> [v a])
513 --prop_group = V.group `eq1` (group :: v a -> [v a])
514 --prop_inits = V.inits `eq1` (inits :: v a -> [v a])
515 --prop_tails = V.tails `eq1` (tails :: v a -> [v a])
516
517 testGeneralBoxedVector :: forall a. (COMMON_CONTEXT(a, Data.Vector.Vector), Ord a) => Data.Vector.Vector a -> [Test]
518 testGeneralBoxedVector dummy = concatMap ($ dummy) [
519 testSanity,
520 testPolymorphicFunctions,
521 testOrdFunctions,
522 testTuplyFunctions,
523 testNestedVectorFunctions,
524 testMonoidFunctions,
525 testFunctorFunctions,
526 testMonadFunctions,
527 testApplicativeFunctions,
528 testAlternativeFunctions
529 ]
530
531 testBoolBoxedVector dummy = concatMap ($ dummy)
532 [
533 testGeneralBoxedVector
534 , testBoolFunctions
535 ]
536
537 testNumericBoxedVector :: forall a. (COMMON_CONTEXT(a, Data.Vector.Vector), Ord a, Num a, Enum a, Random a) => Data.Vector.Vector a -> [Test]
538 testNumericBoxedVector dummy = concatMap ($ dummy)
539 [
540 testGeneralBoxedVector
541 , testNumFunctions
542 , testEnumFunctions
543 ]
544
545
546 testGeneralPrimitiveVector :: forall a. (COMMON_CONTEXT(a, Data.Vector.Primitive.Vector), Data.Vector.Primitive.Prim a, Ord a) => Data.Vector.Primitive.Vector a -> [Test]
547 testGeneralPrimitiveVector dummy = concatMap ($ dummy) [
548 testSanity,
549 testPolymorphicFunctions,
550 testOrdFunctions,
551 testMonoidFunctions
552 ]
553
554 testNumericPrimitiveVector :: forall a. (COMMON_CONTEXT(a, Data.Vector.Primitive.Vector), Data.Vector.Primitive.Prim a, Ord a, Num a, Enum a, Random a) => Data.Vector.Primitive.Vector a -> [Test]
555 testNumericPrimitiveVector dummy = concatMap ($ dummy)
556 [
557 testGeneralPrimitiveVector
558 , testNumFunctions
559 , testEnumFunctions
560 ]
561
562
563 testGeneralStorableVector :: forall a. (COMMON_CONTEXT(a, Data.Vector.Storable.Vector), Data.Vector.Storable.Storable a, Ord a) => Data.Vector.Storable.Vector a -> [Test]
564 testGeneralStorableVector dummy = concatMap ($ dummy) [
565 testSanity,
566 testPolymorphicFunctions,
567 testOrdFunctions,
568 testMonoidFunctions
569 ]
570
571 testNumericStorableVector :: forall a. (COMMON_CONTEXT(a, Data.Vector.Storable.Vector), Data.Vector.Storable.Storable a, Ord a, Num a, Enum a, Random a) => Data.Vector.Storable.Vector a -> [Test]
572 testNumericStorableVector dummy = concatMap ($ dummy)
573 [
574 testGeneralStorableVector
575 , testNumFunctions
576 , testEnumFunctions
577 ]
578
579
580 testGeneralUnboxedVector :: forall a. (COMMON_CONTEXT(a, Data.Vector.Unboxed.Vector), Data.Vector.Unboxed.Unbox a, Ord a) => Data.Vector.Unboxed.Vector a -> [Test]
581 testGeneralUnboxedVector dummy = concatMap ($ dummy) [
582 testSanity,
583 testPolymorphicFunctions,
584 testOrdFunctions,
585 testMonoidFunctions
586 ]
587
588 testUnitUnboxedVector dummy = concatMap ($ dummy)
589 [
590 testGeneralUnboxedVector
591 ]
592
593 testBoolUnboxedVector dummy = concatMap ($ dummy)
594 [
595 testGeneralUnboxedVector
596 , testBoolFunctions
597 ]
598
599 testNumericUnboxedVector :: forall a. (COMMON_CONTEXT(a, Data.Vector.Unboxed.Vector), Data.Vector.Unboxed.Unbox a, Ord a, Num a, Enum a, Random a) => Data.Vector.Unboxed.Vector a -> [Test]
600 testNumericUnboxedVector dummy = concatMap ($ dummy)
601 [
602 testGeneralUnboxedVector
603 , testNumFunctions
604 , testEnumFunctions
605 ]
606
607 testTupleUnboxedVector :: forall a. (COMMON_CONTEXT(a, Data.Vector.Unboxed.Vector), Data.Vector.Unboxed.Unbox a, Ord a) => Data.Vector.Unboxed.Vector a -> [Test]
608 testTupleUnboxedVector dummy = concatMap ($ dummy)
609 [
610 testGeneralUnboxedVector
611 ]
612
613 tests = [
614 testGroup "Data.Vector.Vector (Bool)" (testBoolBoxedVector (undefined :: Data.Vector.Vector Bool)),
615 testGroup "Data.Vector.Vector (Int)" (testNumericBoxedVector (undefined :: Data.Vector.Vector Int)),
616
617 testGroup "Data.Vector.Primitive.Vector (Int)" (testNumericPrimitiveVector (undefined :: Data.Vector.Primitive.Vector Int)),
618 testGroup "Data.Vector.Primitive.Vector (Double)" (testNumericPrimitiveVector (undefined :: Data.Vector.Primitive.Vector Double)),
619
620 testGroup "Data.Vector.Storable.Vector (Int)" (testNumericStorableVector (undefined :: Data.Vector.Storable.Vector Int)),
621 testGroup "Data.Vector.Storable.Vector (Double)" (testNumericStorableVector (undefined :: Data.Vector.Storable.Vector Double)),
622
623 testGroup "Data.Vector.Unboxed.Vector ()" (testUnitUnboxedVector (undefined :: Data.Vector.Unboxed.Vector ())),
624 testGroup "Data.Vector.Unboxed.Vector (Int)" (testNumericUnboxedVector (undefined :: Data.Vector.Unboxed.Vector Int)),
625 testGroup "Data.Vector.Unboxed.Vector (Double)" (testNumericUnboxedVector (undefined :: Data.Vector.Unboxed.Vector Double)),
626 testGroup "Data.Vector.Unboxed.Vector (Int,Bool)" (testTupleUnboxedVector (undefined :: Data.Vector.Unboxed.Vector (Int,Bool))),
627 testGroup "Data.Vector.Unboxed.Vector (Int,Bool,Int)" (testTupleUnboxedVector (undefined :: Data.Vector.Unboxed.Vector (Int,Bool,Int)))
628
629 ]
630