Add my (old) testsuite
[darcs-mirrors/vector.git] / testsuite / Testsuite / Stream / AsList.hs
1 {-# LANGUAGE TypeSynonymInstances, TypeFamilies #-}
2 module Testsuite.Stream.AsList ( tests ) where
3
4 import Data.Vector.Fusion.Stream ( Stream )
5 import qualified Data.Vector.Fusion.Stream as Stream
6 import Data.List
7
8 import Testsuite.Utils.Property
9 import Testsuite.Utils.Test
10 import Test.QuickCheck
11 import Text.Show.Functions ()
12
13 instance Modelled (Stream a) where
14 type Model (Stream a) = [a]
15
16 model = Stream.toList
17 unmodel = Stream.fromList
18
19 prop_convert = arg_ty [A] $ \xs -> Stream.fromList xs ==? xs
20
21 prop_length = arg_ty [A] $ Stream.length ==? length
22 prop_null = arg_ty [A] $ Stream.null ==? null
23
24 prop_empty = (Stream.empty :: Stream A) ==? []
25 prop_singleton = arg_ty A $ Stream.singleton ==? (\x -> [x])
26 prop_replicate = arg2_ty A $ Stream.replicate ==? replicate
27 prop_cons = arg_ty A $ Stream.cons ==? (:)
28 prop_snoc = arg_ty [A] $ Stream.snoc ==? (\xs x -> xs ++ [x])
29 prop_append = arg_ty [A] $ (Stream.++) ==? (++)
30
31 prop_head = arg (not . null) $ arg_ty [A] $ Stream.head ==? head
32 prop_last = arg (not . null) $ arg_ty [A] $ Stream.last ==? last
33 prop_index = args2 (\xs i -> i >= 0 && i < length xs)
34 $ arg_ty [A] $ (Stream.!!) ==? (!!)
35
36 prop_extract = arg_ty [A] $ Stream.extract ==? (\xs i j -> take j (drop i xs))
37 prop_init = arg (not . null) $ arg_ty [A] $ Stream.init ==? init
38 prop_tail = arg (not . null) $ arg_ty [A] $ Stream.tail ==? tail
39 prop_take = arg2_ty [A] $ Stream.take ==? take
40 prop_drop = arg2_ty [A] $ Stream.drop ==? drop
41
42 prop_map = arg_ty (A :-> B) $ Stream.map ==? map
43 prop_zipWith = arg_ty (A :-> B :-> C) $ Stream.zipWith ==? zipWith
44
45 prop_filter = arg_ty (A :-> Bool) $ Stream.filter ==? filter
46 prop_takeWhile = arg_ty (A :-> Bool) $ Stream.takeWhile ==? takeWhile
47 prop_dropWhile = arg_ty (A :-> Bool) $ Stream.dropWhile ==? dropWhile
48
49 prop_elem = arg_ty A $ Stream.elem ==? elem
50 prop_notElem = arg_ty A $ Stream.notElem ==? notElem
51 prop_find = arg_ty (A :-> Bool) $ Stream.find ==? find
52 prop_findIndex = arg_ty (A :-> Bool) $ Stream.findIndex ==? findIndex
53
54 prop_foldl = arg_ty (A :-> B :-> A) Stream.foldl ==? foldl
55 prop_foldl1 = arg2 (not . null) $
56 arg_ty (A :-> A :-> A) Stream.foldl1 ==? foldl1
57 prop_foldl' = arg_ty (A :-> B :-> A) Stream.foldl' ==? foldl'
58 prop_foldl1' = arg2 (not . null) $
59 arg_ty (A :-> A :-> A) Stream.foldl1' ==? foldl1'
60 prop_foldr = arg_ty (A :-> B :-> B) Stream.foldr ==? foldr
61 prop_foldr1 = arg2 (not . null) $
62 arg_ty (A :-> A :-> A) Stream.foldr1 ==? foldr1
63
64 prop_prescanl = arg_ty (A :-> B :-> A)
65 Stream.prescanl ==? (\f z -> init . scanl f z)
66 prop_prescanl' = arg_ty (A :-> B :-> A)
67 Stream.prescanl' ==? (\f z -> init . scanl f z)
68 prop_postscanl = arg_ty (A :-> B :-> A)
69 Stream.postscanl ==? (\f z -> tail . scanl f z)
70 prop_postscanl' = arg_ty (A :-> B :-> A)
71 Stream.postscanl' ==? (\f z -> tail . scanl f z)
72 prop_scanl = arg_ty (A :-> B :-> A)
73 Stream.scanl ==? scanl
74 prop_scanl' = arg_ty (A :-> B :-> A)
75 Stream.scanl' ==? scanl
76 prop_scanl1 = arg2 (not . null) $
77 arg_ty (A :-> A :-> A)
78 Stream.scanl1 ==? scanl1
79 prop_scanl1' = arg2 (not . null) $
80 arg_ty (A :-> A :-> A)
81 Stream.scanl1' ==? scanl1
82
83 tests = "vs. list" $$? [
84 "convert" $? prop_convert
85
86 , "length" $? prop_length
87 , "null" $? prop_null
88
89 , "empty" $? prop_empty
90 , "singleton" $? prop_singleton
91 , "replicate" $? prop_replicate
92 , "cons" $? prop_cons
93 , "snoc" $? prop_snoc
94 , "(++)" $? prop_append
95
96 , "head" $? prop_head
97 , "last" $? prop_last
98 , "(!!)" $? prop_index
99
100 , "extract" $? prop_extract
101 , "init" $? prop_init
102 , "tail" $? prop_tail
103 , "take" $? prop_take
104 , "drop" $? prop_drop
105
106 , "map" $? prop_map
107 , "zipWith" $? prop_zipWith
108
109 , "filter" $? prop_filter
110 , "takeWhile" $? prop_takeWhile
111 , "dropWhile" $? prop_dropWhile
112
113 , "elem" $? prop_elem
114 , "notElem" $? prop_notElem
115 , "find" $? prop_find
116 , "findIndex" $? prop_findIndex
117
118 , "foldl" $? prop_foldl
119 , "foldl1" $? prop_foldl1
120 , "foldl'" $? prop_foldl'
121 , "foldl1'" $? prop_foldl1'
122 , "foldr" $? prop_foldr
123 , "foldr1" $? prop_foldr1
124
125 , "prescanl" $? prop_prescanl
126 , "prescanl'" $? prop_prescanl'
127 , "postscanl" $? prop_postscanl
128 , "postscanl'" $? prop_postscanl'
129 , "scanl" $? prop_scanl
130 , "scanl'" $? prop_scanl'
131 , "scanl1" $? prop_scanl1
132 , "scanl1'" $? prop_scanl1'
133 ]
134