@@ -1,6 +1,7 @@
11module Test.List (tests) where
22
33import List
4+import String
45
56import ElmTest.Assertion (..)
67import ElmTest.Test (..)
@@ -12,8 +13,18 @@ falseList = repeat largeNumber False
1213lessThanThree x = x < 3
1314isEven n = n % 2 == 0
1415
16+alice = { name="Alice", height=1.62 }
17+bob = { name="Bob" , height=1.85 }
18+chuck = { name="Chuck", height=1.76 }
19+
20+flippedComparison a b =
21+ case compare a b of
22+ LT -> GT
23+ EQ -> EQ
24+ GT -> LT
25+
1526tests : Test
16−tests =
27+tests =
1728 let partitionTests = suite "partition Tests"
1829 [ test "simple partition" <| assertEqual ([True],[False]) (List.partition identity [False, True])
1930 , test "order check" <| assertEqual ([2,1], [5,6]) (List.partition lessThanThree [2,5,6,1])
@@ -25,13 +36,55 @@ tests =
2536 [ test "unzip doc check" <| assertEqual ([0,17,1337],[True,False,True]) (unzip [(0, True), (17, False), (1337, True)])
2637 , test "unzip stress test" <| assertEqual (trueList, falseList) (unzip (zip trueList falseList))
2738 ]
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"])
42+ ]
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]])
46+ ]
2847 intersperseTests = suite "intersperse Tests"
2948 [ test "intersperse doc check" <| assertEqual ["turtles","on","turtles","on","turtles"] (intersperse "on" ["turtles","turtles","turtles"])
3049 , test "intersperse stress test" <| assertEqual (tail <| List.concat <| zipWith (\x y -> [x,y]) falseList trueList) (intersperse False trueList)
3150 ]
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])
54+ ]
55+ filterMapTests = suite "filterMap Tests"
56+ [ test "filterMap doc check" <| assertEqual [3,5] (filterMap String.toInt ["3","4.0","5","hats"])
57+ ]
58+ concatMapTests = suite "concatMap Tests"
59+ [ test "simple concatMap check" <| assertEqual [1,1,2,2] (concatMap (repeat 2) [1,2])
60+ ]
61+ indexedMapTests = suite "indexedMap Tests"
62+ [ test "indexedMap doc check" <| assertEqual [(0,"Tom"),(1,"Sue"),(2,"Bob")] (indexedMap (,) ["Tom", "Sue", "Bob"])
63+ ]
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"])
67+ ]
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])
72+ ]
73+ sortWithTests = suite "sortWith Tests"
74+ [ test "sortWith doc check" <| assertEqual [5,4,3,2,1] (sortWith flippedComparison [1..5])
75+ ]
3276 in
3377 suite "List Tests"
3478 [ partitionTests
3579 , unzipTests
80+ , concatTests
81+ , joinTests
3682 , intersperseTests
83+ , zipTests
84+ , filterMapTests
85+ , concatMapTests
86+ , indexedMapTests
87+ , sortTests
88+ , sortByTests
89+ , sortWithTests
3790 ]