on master help sign in
Fix Set tests and add a few List tests
7c6a0d9Max New
libraries/List.elm+7−2
@@ -170,8 +170,9 @@ not.
170 partition (\x -> x < 3) [0..5] == ([0,1,2], [3,4,5])
170 partition (\x -> x < 3) [0..5] == ([0,1,2], [3,4,5])
171 partition isEven [0..5] == ([0,2,4], [1,3,5])
171 partition isEven [0..5] == ([0,2,4], [1,3,5])
172-}
172-}
173+-- | TODO: foldify
173partition : (a -> Bool) -> [a] -> ([a],[a])
174partition : (a -> Bool) -> [a] -> ([a],[a])
174−partition pred lst =
175+partition pred lst =
175 case lst of
176 case lst of
176 [] -> ([],[])
177 [] -> ([],[])
177 x::xs -> let (bs,cs) = partition pred xs in
178 x::xs -> let (bs,cs) = partition pred xs in
@@ -194,7 +195,10 @@ If one list is longer, the extra elements are dropped.
194zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
195zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
195zipWith = Native.List.zipWith
196zipWith = Native.List.zipWith
196
197
197−{-| Decompose a list of tuples. -}
198+{-| Decompose a list of tuples.
199+ unzip [(0, True), (17, False), (1337, True)] == ([0,17,1337], [True,False,True])
200+-}
201+-- | TODO: foldify
198unzip : [(a,b)] -> ([a],[b])
202unzip : [(a,b)] -> ([a],[b])
199unzip pairs =
203unzip pairs =
200 case pairs of
204 case pairs of
@@ -213,6 +217,7 @@ join = Native.List.join
213
217
214 intersperse "on" ["turtles","turtles","turtles"] == ["turtles","on","turtles","on","turtles"]
218 intersperse "on" ["turtles","turtles","turtles"] == ["turtles","on","turtles","on","turtles"]
215-}
219-}
220+-- | TODO: foldify
216intersperse : a -> [a] -> [a]
221intersperse : a -> [a] -> [a]
217intersperse sep xs =
222intersperse sep xs =
218 case xs of
223 case xs of
tests/elm/Test.elm+6−4
@@ -9,13 +9,15 @@ import IO.IO (..)
9import IO.Runner (Request, Response)
9import IO.Runner (Request, Response)
10import IO.Runner as Run
10import IO.Runner as Run
11
11
12−import Test.String as String
13−import Test.Trampoline as Trampoline
14import Test.Array as Array
12import Test.Array as Array
15import Test.Dict as Dict
13import Test.Dict as Dict
16−
14+import Test.List as List
15+import Test.Set as Set
16+import Test.String as String
17+import Test.Trampoline as Trampoline
18+
17tests : [Test]
19tests : [Test]
18−tests = String.tests ++ Trampoline.tests ++ Array.tests ++ Dict.tests
20+tests = String.tests ++ Trampoline.tests ++ Array.tests ++ Dict.tests ++ Set.tests ++ List.tests
19
21
20console : IO ()
22console : IO ()
21console = runDisplay tests
23console = runDisplay tests
tests/elm/Test/List.elmnew file+25
@@ -0,0 +1,25 @@
1+module Test.List (tests) where
2+
3+import List
4+
5+import ElmTest.Assertion (..)
6+import ElmTest.Test (..)
7+
8+tests : [Test]
9+tests =
10+ let partitionTests =
11+ let p1 = id
12+ p2 x = x < 3
13+ isEven n = n `mod` 2 == 0
14+ in [ test "simple partition" <| assertEqual ([True],[False]) (List.partition p1 [False, True]),
15+ test "order check" <| assertEqual ([2,1], [5,6]) (List.partition p2 [2,5,6,1]),
16+ test "partition doc check 1" <| assertEqual ([0,1,2], [3,4,5]) (partition p2 [0..5]),
17+ test "partition doc check 2" <| assertEqual ([0,2,4], [1,3,5]) (partition isEven [0..5])
18+ ]
19+ unzipTests = [
20+ test "unzip doc check" <| assertEqual ([0,17,1337],[True,False,True]) (unzip [(0, True), (17, False), (1337, True)])
21+ ]
22+ intersperseTests = [
23+ test "intersperse doc check" <| assertEqual ["turtles","on","turtles","on","turtles"] (intersperse "on" ["turtles","turtles","turtles"])
24+ ]
25+ in List.concat [partitionTests, unzipTests, intersperseTests]
tests/elm/Test/Set.elm+6−5
@@ -1,18 +1,19 @@
1module Test.Set (tests) where
1module Test.Set (tests) where
2
2
3import Set
3import Set
4+import Set (Set)
4import List
5import List
5
6
6import ElmTest.Assertion (..)
7import ElmTest.Assertion (..)
7import ElmTest.Test (..)
8import ElmTest.Test (..)
8
9
9−set : Set
10+set : Set Int
10set = Set.fromList [1..100]
11set = Set.fromList [1..100]
11
12
12−setPart1 : Set
13+setPart1 : Set Int
13setPart1 = Set.fromList [1..50]
14setPart1 = Set.fromList [1..50]
14
15
15−setPart2 : Set
16+setPart2 : Set Int
16setPart2 = Set.fromList [51..100]
17setPart2 = Set.fromList [51..100]
17
18
18pred : Int -> Bool
19pred : Int -> Bool
@@ -21,6 +22,6 @@ pred x = x <= 50
21tests : [Test]
22tests : [Test]
22tests =
23tests =
23 let
24 let
24− filterTests = [assertEqual setPart1 <| filter pred set]
25+ filterTests = [test "Simple filter" <| assertEqual setPart1 <| Set.filter pred set]
25− partitionTests = [assertEqual (setPart1, setPart2) <| partition pred set]
26+ partitionTests = [test "Simple partition" <| assertEqual (setPart1, setPart2) <| Set.partition pred set]
26 in List.concat [partitionTests, filterTests]
27 in List.concat [partitionTests, filterTests]