-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathListsTests.hs
197 lines (173 loc) · 5.29 KB
/
ListsTests.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
{-# OPTIONS_GHC -Wall #-}
module ListTests where
import Testing
import Lists as L
import Data.List as DL
headTest :: Test
headTest = Test "head" (ap testEq L.head) [
([1, 2, 3], 1),
([10], 10),
([], throwsError)
]
tailTest :: Test
tailTest = Test "tail" (ap testEq L.tail) [
([1, 2, 3], [2, 3]),
([10], []),
([], throwsError)
]
appendTest :: Test
appendTest = Test "append" (ap2 testEq L.append) [
([1, 2, 3], [4, 5, 6], [1, 2, 3, 4, 5, 6]),
([1, 2, 3], [], [1, 2, 3]),
([], [1, 2, 3], [1, 2, 3]),
([], [], [])
]
elementAtTest :: Test
elementAtTest = Test "elementAt" (ap2 testEq L.elementAt) [
(0, [1, 2, 3], 1),
(1, [1, 2, 3], 2),
(2, [1, 2, 3], 3),
(4, [1, 2, 3], throwsError),
(-1, [1, 2, 3], throwsError)
]
nullTest :: Test
nullTest = Test "null" (ap testEq L.null) [
([], True),
([0], False),
([1,2,3], False)
]
lengthTest :: Test
lengthTest = Test "length" (ap testEq L.length) [
([], 0),
([0], 1),
([1,2,3], 3)
]
reverseTest :: Test
reverseTest = Test "reverse" (ap testEq L.reverse) [
([], []),
([0], [0]),
([1,2,3], [3, 2, 1])
]
replicateTest :: Test
replicateTest = Test "replicate" (ap2 testEq L.replicate) [
(-1, 1, []),
(0, 1, []),
(1, 1, [1]),
(5, 2, [2, 2, 2, 2, 2])
]
interleaveTest :: Test
interleaveTest = Test "interleave" (ap2 testEq L.interleave) [
([], [1, 2, 3], []),
([1, 2, 3], [], [1]),
([1, 2, 3], [4, 5, 6, 7], [1, 4, 2, 5, 3, 6]),
([1, 2, 3, 4], [5, 6, 7], [1, 5, 2, 6, 3, 7, 4])
]
concatTest :: Test
concatTest = Test "concat" (ap testEq L.concat) [
([], []),
([[1, 2]], [1, 2]),
([[1, 2], [3, 4]], [1, 2, 3, 4]),
([[1, 2], [3], []], [1, 2, 3])
]
sumTest :: Test
sumTest = Test "sum" (ap testEq L.sum) [
([], 0),
([1, 2], 3),
([1, 2, 4, -10], -3),
([-20], -20)
]
maximumTest :: Test
maximumTest = Test "maximum" (ap testEq L.maximum) [
([], throwsError),
([1, 2], 2),
([1, 2, 4, -10], 4),
([-20, -10, -5], -5)
]
takeTest :: Test
takeTest = Test "take" (ap2 testEq L.take) [
( 10, [], []),
(-10, [1, 2], []),
( 2, [1, 2, 3, 4], [1, 2]),
( 0, [1, 2, 3, 4], []),
( 10, [1, 2, 3, 4], [1, 2, 3, 4])
]
dropTest :: Test
dropTest = Test "drop" (ap2 testEq L.drop) [
(10, [], []),
(-10, [1, 2], [1, 2]),
( 2, [1, 2, 3, 4], [3, 4]),
( 0, [1, 2, 3, 4], [1, 2, 3, 4]),
(10, [1, 2, 3, 4], [])
]
elemTest :: Test
elemTest = Test "elem" (ap2 testEq L.elem) [
(10, [], False),
( 1, [1, 2], True),
( 4, [1, 2, 3, 4], True),
( 5, [1, 2, 3, 4], False)
]
nubTest :: Test
nubTest = Test "nub" (ap (before testEq DL.sort) L.nub) [
([], []),
([1, 2, 3], [1, 2, 3]),
([1, 2, 2, 1, 3, 5, 5], [1, 2, 3, 5])
]
deleteTest :: Test
deleteTest = Test "delete" (ap2 testEq L.delete) [
(10, [], []),
( 1, [1, 2, 3], [2, 3]),
( 2, [1, 2, 2, 3], [1, 2, 3]),
( 5, [1, 2, 2, 3], [1, 2, 2, 3])
]
differenceTest :: Test
differenceTest = Test "difference" (ap2 (before testEq DL.sort) L.difference) [
([], [], []),
([1, 2, 3], [], [1, 2, 3]),
([], [1, 2, 3], []),
([1, 2, 3], [4, 5, 6], [1, 2, 3]),
([1, 2, 3], [1, 2, 3], []),
([1, 2, 2, 3, 3], [1, 3, 4], [2, 2, 3]),
([1, 2, 2, 3, 3], [1, 3, 3], [2, 2])
]
unionTest :: Test
unionTest = Test "union" (ap2 (before testEq DL.sort) L.union) [
([], [], []),
([1, 2, 3], [], [1, 2, 3]),
([], [1, 2, 3], [1, 2, 3]),
([1, 2, 3], [4, 5, 6], [1, 2, 3, 4, 5, 6]),
([1, 2, 3], [1, 2, 3], [1, 2, 3]),
([1, 2, 2, 3, 3], [1, 3, 3], [1, 2, 2, 3, 3]),
([1, 2, 2, 3, 3], [1, 3, 4], [1, 2, 2, 3, 3, 4])
]
intersectTest :: Test
intersectTest = Test "intersect" (ap2 (before testEq DL.sort) L.intersect) [
([], [], []),
([1, 2, 3], [], []),
([], [1, 2, 3], []),
([1, 2, 3], [4, 5, 6], []),
([1, 2, 3], [1, 2, 3], [1, 2, 3]),
([1, 2, 2, 3, 3], [1, 3, 3], [1, 3, 3]),
([1, 2, 2, 3, 3], [1, 3, 4], [1, 3, 3])
]
allTests :: [Test]
allTests = [ headTest
, tailTest
, appendTest
, elementAtTest
, nullTest
, lengthTest
, reverseTest
, replicateTest
, interleaveTest
, concatTest
, sumTest
, maximumTest
, takeTest
, dropTest
, elemTest
, nubTest
, deleteTest
, differenceTest
, unionTest
, intersectTest
]