@@ -46,6 +46,25 @@ testArrayST = do
46
46
47
47
assert $ STA .run (STA .unsafeThaw [1 , 2 , 3 ]) == [1 , 2 , 3 ]
48
48
49
+ log " pop should remove elements from an STArray"
50
+
51
+ assert $ STA .run (do
52
+ arr <- STA .thaw [1 , 2 , 3 ]
53
+ void $ STA .pop arr
54
+ pure arr) == [1 , 2 ]
55
+
56
+ log " pop should return the last element of an STArray"
57
+
58
+ assert $ ST .run (do
59
+ arr <- STA .thaw [1 , 2 , 3 ]
60
+ STA .pop arr) == Just 3
61
+
62
+ log " pop should return Nothing when given an empty array"
63
+
64
+ assert $ isNothing $ ST .run (do
65
+ arr <- STA .empty
66
+ STA .pop arr)
67
+
49
68
log " push should append a value to the end of the array"
50
69
51
70
assert $ STA .run (do
@@ -145,6 +164,62 @@ testArrayST = do
145
164
void $ STA .poke 1 2 arr
146
165
pure arr) == [1 ]
147
166
167
+ log " shift should remove elements from an STArray"
168
+
169
+ assert $ STA .run (do
170
+ arr <- STA .thaw [1 , 2 , 3 ]
171
+ void $ STA .shift arr
172
+ pure arr) == [2 , 3 ]
173
+
174
+ log " shift should return the first element of an STArray"
175
+
176
+ assert $ ST .run (do
177
+ arr <- STA .thaw [1 , 2 , 3 ]
178
+ STA .shift arr) == Just 1
179
+
180
+ log " shift should return Nothing when given an empty array"
181
+
182
+ assert $ isNothing $ ST .run (do
183
+ arr <- STA .empty
184
+ STA .shift arr)
185
+
186
+ log " unshift should append a value to the front of the array"
187
+
188
+ assert $ STA .run (do
189
+ arr <- STA .empty
190
+ void $ STA .unshift 1 arr
191
+ void $ STA .unshift 2 arr
192
+ pure arr) == [2 , 1 ]
193
+
194
+ assert $ STA .run (do
195
+ arr <- STA .thaw [1 , 2 , 3 ]
196
+ void $ STA .unshift 4 arr
197
+ pure arr) == [4 , 1 , 2 , 3 ]
198
+
199
+ log " unshift should return the new length of the array"
200
+
201
+ assert $ ST .run (do
202
+ arr <- STA .thaw [unit, unit, unit]
203
+ STA .unshift unit arr) == 4
204
+
205
+ log " unshiftAll should append multiple values to the front of the array"
206
+
207
+ assert $ STA .run (do
208
+ arr <- STA .empty
209
+ void $ STA .unshiftAll [1 , 2 ] arr
210
+ pure arr) == [1 , 2 ]
211
+
212
+ assert $ STA .run (do
213
+ arr <- STA .thaw [1 , 2 , 3 ]
214
+ void $ STA .unshiftAll [4 , 5 , 6 ] arr
215
+ pure arr) == [4 , 5 , 6 , 1 , 2 , 3 ]
216
+
217
+ log " unshiftAll should return the new length of the array"
218
+
219
+ assert $ ST .run (do
220
+ arr <- STA .thaw [unit, unit, unit]
221
+ STA .unshiftAll [unit, unit] arr) == 5
222
+
148
223
log " sort should reorder a list into ascending order based on the result of compare"
149
224
assert $ STA .run (
150
225
STA .sort =<< STA .unsafeThaw [1 , 3 , 2 , 5 , 6 , 4 ]
0 commit comments