on master help sign in
Add tests for new Dict functions
50e8908Harry Garrood
tests/elm/Test/Dict.elmnew file+43
@@ -0,0 +1,43 @@
1+module Test.Dict (tests) where
2+
3+import Dict
4+import List
5+import Char
6+
7+import ElmTest.Assertion (..)
8+import ElmTest.Test (..)
9+
10+parseDigit : Char -> Int
11+parseDigit ch = Char.toCode ch - 48
12+
13+dict1List = [(1,'1'),(2,'2'),(3,'3'),(5,'5')]
14+
15+dict1 : Dict Int Char
16+dict1 = Dict.fromList dict1List
17+
18+dict1Part1 : Dict Int Char
19+dict1Part1 = Dict.fromList (take 2 dict1List)
20+
21+dict1Part2 : Dict Int Char
22+dict1Part2 = Dict.fromList (drop 2 dict1List)
23+
24+dict2List : Dict Int Char
25+dict2List = [(1,'2'),(3,'3'),(7,'4'),(8,'3')]
26+
27+dict2 : Dict Int Char
28+dict2 = Dict.fromList dict2List
29+
30+dict2Part1 : Dict Int Char
31+dict2Part1 = Dict.fromList (take 2 dict2List)
32+
33+dict2Part2 : Dict Int Char
34+dict2Part2 = Dict.fromList (drop 2 dict2List)
35+
36+tests : [Test]
37+tests =
38+ let
39+ partitionTests = [assertEqual (dict1Part1, dict1Part2) <| partition (\v -> v != "3" && v != "5") dict1]
40+ partitionWithKeyTests = [assertEqual (dict2Part1, dict2Part2) <| partition (\k v -> k <= parseDigit v)]
41+ filterTests = [assertEqual dict1Part2 <| filter (\v -> parseDigit v > 2) dict1]
42+ filterWithKeyTests = [assertEqual dict2Part2 <| filterWithKey (\k _ -> k > 6) dict2]
43+ in List.concat [partitionTests, partitionWithKeyTests, filterTests, filterWithKeyTests]