@@ -1,6 +1,7 @@
1module Test.List (tests) where
1module Test.List (tests) where
5import ElmTest.Assertion (..)
6import ElmTest.Assertion (..)
6import ElmTest.Test (..)
7import ElmTest.Test (..)
@@ -12,8 +13,18 @@ falseList = repeat largeNumber False
12lessThanThree x = x < 3
13lessThanThree x = x < 3
13isEven n = n % 2 == 0
14isEven n = n % 2 == 0
16+alice = { name="Alice", height=1.62 }
17+bob = { name="Bob" , height=1.85 }
18+chuck = { name="Chuck", height=1.76 }
20+flippedComparison a b =
15tests : Test
26tests : Test
17 let partitionTests = suite "partition Tests"
28 let partitionTests = suite "partition Tests"
18 [ test "simple partition" <| assertEqual ([True],[False]) (List.partition identity [False, True])
29 [ test "simple partition" <| assertEqual ([True],[False]) (List.partition identity [False, True])
19 , test "order check" <| assertEqual ([2,1], [5,6]) (List.partition lessThanThree [2,5,6,1])
30 , test "order check" <| assertEqual ([2,1], [5,6]) (List.partition lessThanThree [2,5,6,1])
@@ -25,13 +36,55 @@ tests =
25 [ test "unzip doc check" <| assertEqual ([0,17,1337],[True,False,True]) (unzip [(0, True), (17, False), (1337, True)])
36 [ test "unzip doc check" <| assertEqual ([0,17,1337],[True,False,True]) (unzip [(0, True), (17, False), (1337, True)])
26 , test "unzip stress test" <| assertEqual (trueList, falseList) (unzip (zip trueList falseList))
37 , test "unzip stress test" <| assertEqual (trueList, falseList) (unzip (zip trueList falseList))
39+ concatTests = suite "concat Tests"
40+ [ test "concat doc check 1" <| assertEqual [1,2,3,4,5] (concat [[1,2],[3],[4,5]])
41+ , test "concat doc check 2" <| assertEqual "treehouse" (concat ["tree","house"])
43+ joinTests = suite "join Tests"
44+ [ test "join doc check" <| assertEqual "Hawaiian" (join "a" ["H","w","ii","n"])
45+ , test "join list check" <| assertEqual [1,0,2,0,3] (join [0] [[1],[2],[3]])
28 intersperseTests = suite "intersperse Tests"
47 intersperseTests = suite "intersperse Tests"
29 [ test "intersperse doc check" <| assertEqual ["turtles","on","turtles","on","turtles"] (intersperse "on" ["turtles","turtles","turtles"])
48 [ test "intersperse doc check" <| assertEqual ["turtles","on","turtles","on","turtles"] (intersperse "on" ["turtles","turtles","turtles"])
30 , test "intersperse stress test" <| assertEqual (tail <| List.concat <| zipWith (\x y -> [x,y]) falseList trueList) (intersperse False trueList)
49 , test "intersperse stress test" <| assertEqual (tail <| List.concat <| zipWith (\x y -> [x,y]) falseList trueList) (intersperse False trueList)
51+ zipTests = suite "zip Tests"
52+ [ test "zip doc check 1" <| assertEqual [(1,6),(2,7)] (zip [1,2,3] [6,7])
53+ , test "zip doc check 2" <| assertEqual (zipWith (,) [1,2,3] [6,7]) (zip [1,2,3] [6,7])
55+ filterMapTests = suite "filterMap Tests"
56+ [ test "filterMap doc check" <| assertEqual [3,5] (filterMap String.toInt ["3","4.0","5","hats"])
58+ concatMapTests = suite "concatMap Tests"
59+ [ test "simple concatMap check" <| assertEqual [1,1,2,2] (concatMap (repeat 2) [1,2])
61+ indexedMapTests = suite "indexedMap Tests"
62+ [ test "indexedMap doc check" <| assertEqual [(0,"Tom"),(1,"Sue"),(2,"Bob")] (indexedMap (,) ["Tom", "Sue", "Bob"])
64+ sortTests = suite "sort Tests"
65+ [ test "sort doc check" <| assertEqual [1,3,5] (sort [3,1,5])
66+ , test "sort string check" <| assertEqual ["a","c","e"] (sort ["c","a","e"])
68+ sortByTests = suite "sortBy Tests"
69+ [ test "sortBy doc check" <| assertEqual ["cat","mouse"] (sortBy String.length ["mouse","cat"])
70+ , test "sortby derived property check 1" <| assertEqual [alice,bob,chuck] (sortBy .name [chuck,alice,bob])
71+ , test "sortby derived property check 2" <| assertEqual [alice,chuck,bob] (sortBy .height [chuck,alice,bob])
73+ sortWithTests = suite "sortWith Tests"
74+ [ test "sortWith doc check" <| assertEqual [5,4,3,2,1] (sortWith flippedComparison [1..5])
33 suite "List Tests"
77 suite "List Tests"
34 [ partitionTests
78 [ partitionTests
35 , unzipTests
79 , unzipTests
36 , intersperseTests
82 , intersperseTests