11module Test.Data.Array (testArray ) where
22
3- import Prelude
4- import Control.Monad.Eff.Console (log )
5- import Data.Array
3+ import Prelude ((*), zero , (/=), mod , (==), ($), (+), bind , show , (<), (&&), compare , flip , const , (<<<), map , negate , unit , Unit )
4+ import Control.Monad.Eff (Eff )
5+ import Control.Monad.Eff.Console (log , CONSOLE )
6+ import Data.Array (range , foldM , unzip , zip , zipWithA , zipWith , intersectBy , intersect , (\\), deleteBy , delete , unionBy , union , nubBy , nub , groupBy , group' , group , span , dropWhile , drop , takeWhile , take , sortBy , sort , catMaybes , mapMaybe , filterM , filter , concat , concatMap , reverse , alterAt , modifyAt , updateAt , deleteAt , insertAt , findLastIndex , findIndex , elemLastIndex , elemIndex , (!!), uncons , init , tail , last , head , insertBy , insert , snoc , (:), length , null , replicate , replicateM , singleton )
67import Data.Maybe (Maybe (..), isNothing )
78import Data.Maybe.Unsafe (fromJust )
89import Data.Tuple (Tuple (..))
9- import Test.Assert (assert )
10-
10+ import Test.Assert (assert , ASSERT )
11+
12+ testArray :: forall t .
13+ Eff
14+ ( console :: CONSOLE
15+ , assert :: ASSERT
16+ | t
17+ )
18+ Unit
1119testArray = do
1220
1321 log " singleton should construct an array with a single value"
@@ -121,12 +129,12 @@ testArray = do
121129 assert $ (elemLastIndex 4 [1 , 2 , 1 ]) == Nothing
122130
123131 log " findIndex should return the index of an item that a predicate returns true for in an array"
124- assert $ (findIndex (/= 1 ) [1 , 2 , 1 ]) == Just 1
125- assert $ (findIndex (== 3 ) [1 , 2 , 1 ]) == Nothing
132+ assert $ (findIndex (_ /= 1 ) [1 , 2 , 1 ]) == Just 1
133+ assert $ (findIndex (_ == 3 ) [1 , 2 , 1 ]) == Nothing
126134
127135 log " findLastIndex should return the last index of an item in an array"
128- assert $ (findLastIndex (/= 1 ) [2 , 1 , 2 ]) == Just 2
129- assert $ (findLastIndex (== 3 ) [2 , 1 , 2 ]) == Nothing
136+ assert $ (findLastIndex (_ /= 1 ) [2 , 1 , 2 ]) == Just 2
137+ assert $ (findLastIndex (_ == 3 ) [2 , 1 , 2 ]) == Nothing
130138
131139 log " insertAt should add an item at the specified index"
132140 assert $ (insertAt 0 1 [2 , 3 ]) == Just [1 , 2 , 3 ]
@@ -151,11 +159,11 @@ testArray = do
151159 assert $ (updateAt 1 9 nil) == Nothing
152160
153161 log " modifyAt should update an item at the specified index"
154- assert $ (modifyAt 0 (+ 1 ) [1 , 2 , 3 ]) == Just [2 , 2 , 3 ]
155- assert $ (modifyAt 1 (+ 1 ) [1 , 2 , 3 ]) == Just [1 , 3 , 3 ]
162+ assert $ (modifyAt 0 (_ + 1 ) [1 , 2 , 3 ]) == Just [2 , 2 , 3 ]
163+ assert $ (modifyAt 1 (_ + 1 ) [1 , 2 , 3 ]) == Just [1 , 3 , 3 ]
156164
157165 log " modifyAt should return Nothing if the index is out of range"
158- assert $ (modifyAt 1 (+ 1 ) nil) == Nothing
166+ assert $ (modifyAt 1 (_ + 1 ) nil) == Nothing
159167
160168 log " alterAt should update an item at the specified index when the function returns Just"
161169 assert $ (alterAt 0 (Just <<< (+ 1 )) [1 , 2 , 3 ]) == Just [2 , 2 , 3 ]
@@ -205,22 +213,22 @@ testArray = do
205213 assert $ (take 1 nil) == nil
206214
207215 log " takeWhile should keep all values that match a predicate from the front of an array"
208- assert $ (takeWhile (/= 2 ) [1 , 2 , 3 ]) == [1 ]
209- assert $ (takeWhile (/= 3 ) [1 , 2 , 3 ]) == [1 , 2 ]
210- assert $ (takeWhile (/= 1 ) nil) == nil
216+ assert $ (takeWhile (_ /= 2 ) [1 , 2 , 3 ]) == [1 ]
217+ assert $ (takeWhile (_ /= 3 ) [1 , 2 , 3 ]) == [1 , 2 ]
218+ assert $ (takeWhile (_ /= 1 ) nil) == nil
211219
212220 log " drop should remove the specified number of items from the front of an array"
213221 assert $ (drop 1 [1 , 2 , 3 ]) == [2 , 3 ]
214222 assert $ (drop 2 [1 , 2 , 3 ]) == [3 ]
215223 assert $ (drop 1 nil) == nil
216224
217225 log " dropWhile should remove all values that match a predicate from the front of an array"
218- assert $ (dropWhile (/= 1 ) [1 , 2 , 3 ]) == [1 , 2 , 3 ]
219- assert $ (dropWhile (/= 2 ) [1 , 2 , 3 ]) == [2 , 3 ]
220- assert $ (dropWhile (/= 1 ) nil) == nil
226+ assert $ (dropWhile (_ /= 1 ) [1 , 2 , 3 ]) == [1 , 2 , 3 ]
227+ assert $ (dropWhile (_ /= 2 ) [1 , 2 , 3 ]) == [2 , 3 ]
228+ assert $ (dropWhile (_ /= 1 ) nil) == nil
221229
222230 log " span should split an array in two based on a predicate"
223- let spanResult = span (< 4 ) [1 , 2 , 3 , 4 , 5 , 6 , 7 ]
231+ let spanResult = span (_ < 4 ) [1 , 2 , 3 , 4 , 5 , 6 , 7 ]
224232 assert $ spanResult.init == [1 , 2 , 3 ]
225233 assert $ spanResult.rest == [4 , 5 , 6 , 7 ]
226234
0 commit comments