Skip to content

Commit

Permalink
add more array test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lupino committed Oct 8, 2018
1 parent 73a61e7 commit bd945e3
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions examples/foldable-traversable/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,27 @@ import Data.Foldable (foldr, foldl)
import Data.FunctorWithIndex (mapDefault)
import Data.Traversable (traverse)

run :: forall a. Show a => String -> a -> Effect Unit
run label result = Console.log $ "[" <> label <> "]: " <> show result

oneTest :: Array Int -> Effect Unit
oneTest arr = do
Console.log $ "test with input: " <> show arr
run "foldr" $ foldr (+) 0 arr
run "foldl" $ foldl (+) 0 arr
run "mapDefault" $ mapDefault (\i -> i + 1) arr
run "traverse" =<< traverse pure arr


main :: Effect Unit
main = do
run "foldr" $ foldr (+) 0 [1,2,3,4,5,6,7,8,9]
run "foldl" $ foldl (+) 0 [1,2,3,4,5,6,7,8,9]
run "mapDefault" $ mapDefault (\i -> i + 1) [1,2,3,4,5,6,7,8,9]
run "traverse" =<< traverse pure [1,2,3,4,5,6,7,8,9]
where
run :: forall a. Show a => String -> a -> Effect Unit
run label result =
Console.log $
"[" <> label <> "]: " <> show result
oneTest []
oneTest [1]
oneTest [1, 2]
oneTest [1, 2, 3]
oneTest [1, 2, 3, 4]
oneTest [1, 2, 3, 4, 5]
oneTest [1, 2, 3, 4, 5, 6]
oneTest [1, 2, 3, 4, 5, 6, 7]
oneTest [1, 2, 3, 4, 5, 6, 7, 8]
oneTest [1, 2, 3, 4, 5, 6, 7, 8, 9]

0 comments on commit bd945e3

Please sign in to comment.