on master help sign in
Merge pull request #791 from Boshen/add-list-and-dict-tests
ecaadcfEvan Czaplicki
tests/libraries/Test/Dict.elm+27−4
@@ -11,16 +11,39 @@ animals = Dict.fromList [ ("Tom", "cat"), ("Jerry", "mouse") ]
11
11
12tests : Test
12tests : Test
13tests =
13tests =
14− let getTests =
14+ let buildTests = suite "build Tests"
15+ [ test "empty" <| assertEqual (Dict.fromList []) (Dict.empty)
16+ , test "singleton" <| assertEqual (Dict.fromList [("k","v")]) (Dict.singleton "k" "v")
17+ , test "insert" <| assertEqual (Dict.fromList [("k","v")]) (Dict.insert "k" "v" Dict.empty)
18+ , test "insert replace" <| assertEqual (Dict.fromList [("k","vv")]) (Dict.insert "k" "vv" (Dict.singleton "k" "v"))
19+ , test "update" <| assertEqual (Dict.fromList [("k","vv")]) (Dict.update "k" (\v->Just "vv") (Dict.singleton "k" "v"))
20+ , test "update Nothing" <| assertEqual Dict.empty (Dict.update "k" (\v->Nothing) (Dict.singleton "k" "v"))
21+ , test "remove" <| assertEqual Dict.empty (Dict.remove "k" (Dict.singleton "k" "v"))
22+ , test "remove not found" <| assertEqual (Dict.singleton "k" "v") (Dict.remove "kk" (Dict.singleton "k" "v"))
23+ ]
24+ queryTests = suite "query Tests"
25+ [ test "member 1" <| assertEqual True (Dict.member "Tom" animals)
26+ , test "member 2" <| assertEqual False (Dict.member "Spike" animals)
15− [ test "get 1" <| assertEqual (Just "cat") (Dict.get "Tom" animals)
27+ , test "get 1" <| assertEqual (Just "cat") (Dict.get "Tom" animals)
16 , test "get 2" <| assertEqual Nothing (Dict.get "Spike" animals)
28 , test "get 2" <| assertEqual Nothing (Dict.get "Spike" animals)
17 , test "getOrElse 1" <| assertEqual "mouse" (Dict.getOrElse "dog" "Jerry" animals)
29 , test "getOrElse 1" <| assertEqual "mouse" (Dict.getOrElse "dog" "Jerry" animals)
18 , test "getOrElse 2" <| assertEqual "dog" (Dict.getOrElse "dog" "Spike" animals)
30 , test "getOrElse 2" <| assertEqual "dog" (Dict.getOrElse "dog" "Spike" animals)
19 , test "getOrFail" <| assertEqual "cat" (Dict.getOrFail "Tom" animals)
31 , test "getOrFail" <| assertEqual "cat" (Dict.getOrFail "Tom" animals)
20 ]
32 ]
21− filterTests =
33+ combineTests = suite "combine Tests"
34+ [ test "union" <| assertEqual animals (Dict.union (Dict.singleton "Jerry" "mouse") (Dict.singleton "Tom" "cat"))
35+ , test "union collison" <| assertEqual (Dict.singleton "Tom" "cat") (Dict.union (Dict.singleton "Tom" "cat") (Dict.singleton "Tom" "mouse"))
36+ , test "intersect" <| assertEqual (Dict.singleton "Tom" "cat") (Dict.intersect animals (Dict.singleton "Tom" "cat"))
37+ , test "diff" <| assertEqual (Dict.singleton "Jerry" "mouse") (Dict.diff animals (Dict.singleton "Tom" "cat"))
38+ ]
39+ transformTests = suite "transform Tests"
22 [ test "filter" <| assertEqual (Dict.singleton "Tom" "cat") (Dict.filter (\k v -> k == "Tom") animals)
40 [ test "filter" <| assertEqual (Dict.singleton "Tom" "cat") (Dict.filter (\k v -> k == "Tom") animals)
23 , test "partition" <| assertEqual (Dict.singleton "Tom" "cat", Dict.singleton "Jerry" "mouse") (Dict.partition (\k v -> k == "Tom") animals)
41 , test "partition" <| assertEqual (Dict.singleton "Tom" "cat", Dict.singleton "Jerry" "mouse") (Dict.partition (\k v -> k == "Tom") animals)
24 ]
42 ]
25 in
43 in
26− suite "Dict Tests" <| List.concat [ getTests, filterTests ]
44+ suite "Dict Tests"
45+ [ buildTests
46+ , queryTests
47+ , combineTests
48+ , transformTests
49+ ]
tests/libraries/Test/List.elm+54−1
@@ -1,6 +1,7 @@
1module Test.List (tests) where
1module Test.List (tests) where
2
2
3import List
3import List
4+import String
4
5
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
14
15
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+
15tests : Test
26tests : Test
16−tests =
27+tests =
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))
27 ]
38 ]
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+ ]
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)
31 ]
50 ]
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+ ]
32 in
76 in
33 suite "List Tests"
77 suite "List Tests"
34 [ partitionTests
78 [ partitionTests
35 , unzipTests
79 , unzipTests
80+ , concatTests
81+ , joinTests
36 , intersperseTests
82 , intersperseTests
83+ , zipTests
84+ , filterMapTests
85+ , concatMapTests
86+ , indexedMapTests
87+ , sortTests
88+ , sortByTests
89+ , sortWithTests
37 ]
90 ]