Skip to content

Commit 6c5797d

Browse files
committed
adds test for "orderedness" of foldrWithIndex
1 parent 484181f commit 6c5797d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

test/Test/Data/Map.purs

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import Prelude
55
import Control.Alt ((<|>))
66
import Data.Array as A
77
import Data.Foldable (foldl, for_, all)
8+
import Data.FoldableWithIndex (foldrWithIndex)
89
import Data.Function (on)
910
import Data.FunctorWithIndex (mapWithIndex)
10-
import Data.List (List(Cons), groupBy, length, nubBy, singleton, sort, sortBy)
11+
import Data.List (List(..), groupBy, length, nubBy, singleton, sort, sortBy, (:))
1112
import Data.List.NonEmpty as NEL
1213
import Data.Map as M
1314
import Data.Map.Gen (genMap)
@@ -333,3 +334,8 @@ mapTests = do
333334
<> ", mmin: " <> show mmin
334335
<> ", mmax: " <> show mmax
335336
<> ", key: " <> show key
337+
338+
log "foldrWithIndex maintains order"
339+
quickCheck \(TestMap m :: TestMap Int Int) ->
340+
let outList = foldrWithIndex (\i a b -> (Tuple i a) : b) Nil m
341+
in outList == sort outList

0 commit comments

Comments
 (0)