on master help sign in
Fix Set tests and add a few List tests
commit7c6a0d92062255eabc3c63f3445aba84950edfa5 authorMax New <maxsnew@gmail.com> dateThu 24 Apr 2014, 14:37 (13 years ago) parent3fe77a6
4 files changed+44−11
libraries/List.elm+7−2 tests/elm/Test.elm+6−4 tests/elm/Test/List.elm+25 tests/elm/Test/Set.elm+6−5
libraries/List.elm+7−2
@@ -170,8 +170,9 @@ not.
170170 partition (\x -> x < 3) [0..5] == ([0,1,2], [3,4,5])
171171 partition isEven [0..5] == ([0,2,4], [1,3,5])
172172-}
173+-- | TODO: foldify
173174partition : (a -> Bool) -> [a] -> ([a],[a])
174−partition pred lst =
175+partition pred lst =
175176 case lst of
176177 [] -> ([],[])
177178 x::xs -> let (bs,cs) = partition pred xs in
@@ -194,7 +195,10 @@ If one list is longer, the extra elements are dropped.
194195zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
195196zipWith = Native.List.zipWith
196197
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
198202unzip : [(a,b)] -> ([a],[b])
199203unzip pairs =
200204 case pairs of
@@ -213,6 +217,7 @@ join = Native.List.join
213217
214218 intersperse "on" ["turtles","turtles","turtles"] == ["turtles","on","turtles","on","turtles"]
215219-}
220+-- | TODO: foldify
216221intersperse : a -> [a] -> [a]
217222intersperse sep xs =
218223 case xs of
tests/elm/Test.elm+6−4
@@ -9,13 +9,15 @@ import IO.IO (..)
99import IO.Runner (Request, Response)
1010import IO.Runner as Run
1111
12−import Test.String as String
13−import Test.Trampoline as Trampoline
1412import Test.Array as Array
1513import 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+
1719tests : [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
1921
2022console : IO ()
2123console = 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 @@
11module Test.Set (tests) where
22
33import Set
4+import Set (Set)
45import List
56
67import ElmTest.Assertion (..)
78import ElmTest.Test (..)
89
9−set : Set
10+set : Set Int
1011set = Set.fromList [1..100]
1112
12−setPart1 : Set
13+setPart1 : Set Int
1314setPart1 = Set.fromList [1..50]
1415
15−setPart2 : Set
16+setPart2 : Set Int
1617setPart2 = Set.fromList [51..100]
1718
1819pred : Int -> Bool
@@ -21,6 +22,6 @@ pred x = x <= 50
2122tests : [Test]
2223tests =
2324 let
24− filterTests = [assertEqual setPart1 <| filter pred set]
25− partitionTests = [assertEqual (setPart1, setPart2) <| partition pred set]
25+ filterTests = [test "Simple filter" <| assertEqual setPart1 <| Set.filter pred set]
26+ partitionTests = [test "Simple partition" <| assertEqual (setPart1, setPart2) <| Set.partition pred set]
2627 in List.concat [partitionTests, filterTests]