on master help sign in
Use new test suite support from Elm-Test
be97968Max New
tests/elm/Test.elm+8−2
@@ -16,8 +16,14 @@ import Test.Set as Set
16import Test.String as String
16import Test.String as String
17import Test.Trampoline as Trampoline
17import Test.Trampoline as Trampoline
18
18
19−tests : [Test]
19+tests : Test
20−tests = String.tests ++ Trampoline.tests ++ Array.tests ++ Dict.tests ++ Set.tests ++ List.tests
20+tests = Suite "Elm Standard Library Tests" [ List.tests,
21+ String.tests,
22+ Trampoline.tests,
23+ Array.tests,
24+ Dict.tests,
25+ Set.tests
26+ ]
21
27
22console : IO ()
28console : IO ()
23console = runDisplay tests
29console = runDisplay tests
tests/elm/Test/Array.elm+7−7
@@ -6,9 +6,9 @@ import Array
6import ElmTest.Assertion (..)
6import ElmTest.Assertion (..)
7import ElmTest.Test (..)
7import ElmTest.Test (..)
8
8
9−tests : [Test]
9+tests : Test
10tests =
10tests =
11− let creationTests =
11+ let creationTests = Suite "Creation"
12 [ test "empty" <| assertEqual Array.empty (Array.fromList [])
12 [ test "empty" <| assertEqual Array.empty (Array.fromList [])
13 , test "initialize" <| assertEqual (Array.initialize 4 id) (Array.fromList [0,1,2,3])
13 , test "initialize" <| assertEqual (Array.initialize 4 id) (Array.fromList [0,1,2,3])
14 , test "initialize 2" <| assertEqual (Array.initialize 4 (\n -> n*n)) (Array.fromList [0,1,4,9])
14 , test "initialize 2" <| assertEqual (Array.initialize 4 (\n -> n*n)) (Array.fromList [0,1,4,9])
@@ -20,13 +20,13 @@ tests =
20 , test "repeat 3" <| assertEqual (Array.repeat 3 "cat") (Array.fromList ["cat","cat","cat"])
20 , test "repeat 3" <| assertEqual (Array.repeat 3 "cat") (Array.fromList ["cat","cat","cat"])
21 , test "fromList" <| assertEqual (Array.fromList []) Array.empty
21 , test "fromList" <| assertEqual (Array.fromList []) Array.empty
22 ]
22 ]
23− basicsTests =
23+ basicsTests = Suite "Basics"
24 [ test "length" <| assertEqual (Array.length (Array.fromList [1,2,3])) 3
24 [ test "length" <| assertEqual (Array.length (Array.fromList [1,2,3])) 3
25 , test "length - Long" <| assertEqual (Array.length (Array.repeat 10000 0)) 10000
25 , test "length - Long" <| assertEqual (Array.length (Array.repeat 10000 0)) 10000
26 , test "push" <| assertEqual (Array.push 3 (Array.fromList [1,2])) (Array.fromList [1,2,3])
26 , test "push" <| assertEqual (Array.push 3 (Array.fromList [1,2])) (Array.fromList [1,2,3])
27 , test "append" <| assertEqual (Array.toList <| Array.append (Array.repeat 2 42) (Array.repeat 3 81)) ([42,42,81,81,81])
27 , test "append" <| assertEqual (Array.toList <| Array.append (Array.repeat 2 42) (Array.repeat 3 81)) ([42,42,81,81,81])
28 ]
28 ]
29− getAndSetTests =
29+ getAndSetTests = Suite "Get and Set"
30 [ test "get" <| assertEqual (Array.get 1 (Array.fromList [3,2,1])) (Just 2)
30 [ test "get" <| assertEqual (Array.get 1 (Array.fromList [3,2,1])) (Just 2)
31 , test "get 2" <| assertEqual (Array.get 5 (Array.fromList [3,2,1])) Nothing
31 , test "get 2" <| assertEqual (Array.get 5 (Array.fromList [3,2,1])) Nothing
32 , test "get 3" <| assertEqual (Array.get -1 (Array.fromList [3,2,1])) Nothing
32 , test "get 3" <| assertEqual (Array.get -1 (Array.fromList [3,2,1])) Nothing
@@ -35,14 +35,14 @@ tests =
35 , test "getOrFail" <| assertEqual (Array.getOrFail 2 (Array.fromList [3,2,1])) 1
35 , test "getOrFail" <| assertEqual (Array.getOrFail 2 (Array.fromList [3,2,1])) 1
36 , test "set" <| assertEqual (Array.set 1 7 (Array.fromList [1,2,3])) (Array.fromList [1,7,3])
36 , test "set" <| assertEqual (Array.set 1 7 (Array.fromList [1,2,3])) (Array.fromList [1,7,3])
37 ]
37 ]
38− takingArraysApartTests =
38+ takingArraysApartTests = Suite "Taking Arrays Apart"
39 [ test "toList" <| assertEqual (Array.toList (Array.fromList [3,5,8])) [3,5,8]
39 [ test "toList" <| assertEqual (Array.toList (Array.fromList [3,5,8])) [3,5,8]
40 , test "toIndexedList" <| assertEqual (Array.toIndexedList (Array.fromList ["cat","dog"])) [(0,"cat"), (1,"dog")]
40 , test "toIndexedList" <| assertEqual (Array.toIndexedList (Array.fromList ["cat","dog"])) [(0,"cat"), (1,"dog")]
41 , test "slice" <| assertEqual (Array.slice 1 2 (Array.fromList [0,1,2,3,4])) (Array.fromList [1,2])
41 , test "slice" <| assertEqual (Array.slice 1 2 (Array.fromList [0,1,2,3,4])) (Array.fromList [1,2])
42 , test "slice 2" <| assertEqual (Array.slice 1 -2 (Array.fromList [0,1,2,3,4])) (Array.fromList [1,2,3])
42 , test "slice 2" <| assertEqual (Array.slice 1 -2 (Array.fromList [0,1,2,3,4])) (Array.fromList [1,2,3])
43 , test "slice 3" <| assertEqual (Array.slice -3 -2 (Array.fromList [0,1,2,3,4])) (Array.fromList [2,3])
43 , test "slice 3" <| assertEqual (Array.slice -3 -2 (Array.fromList [0,1,2,3,4])) (Array.fromList [2,3])
44 ]
44 ]
45− mappingAndFoldingTests =
45+ mappingAndFoldingTests = Suite "Mapping and Folding"
46 [ test "map" <| assertEqual (Array.map sqrt (Array.fromList [1,4,9])) (Array.fromList [1,2,3])
46 [ test "map" <| assertEqual (Array.map sqrt (Array.fromList [1,4,9])) (Array.fromList [1,2,3])
47 , test "indexedMap" <| assertEqual (Array.indexedMap (*) (Array.fromList [5,5,5])) (Array.fromList [0,5,10])
47 , test "indexedMap" <| assertEqual (Array.indexedMap (*) (Array.fromList [5,5,5])) (Array.fromList [0,5,10])
48 , test "foldl" <| assertEqual (Array.foldl (::) [] (Array.fromList [1,2,3])) [3,2,1]
48 , test "foldl" <| assertEqual (Array.foldl (::) [] (Array.fromList [1,2,3])) [3,2,1]
@@ -51,4 +51,4 @@ tests =
51 , test "filter" <| assertEqual (Array.filter (\x -> x `mod` 2 == 0) (Array.fromList [1..6])) (Array.fromList [2,4,6])
51 , test "filter" <| assertEqual (Array.filter (\x -> x `mod` 2 == 0) (Array.fromList [1..6])) (Array.fromList [2,4,6])
52 ]
52 ]
53 in
53 in
54− List.concat [creationTests, basicsTests, getAndSetTests, takingArraysApartTests, mappingAndFoldingTests]
54+ Suite "Array Tests" [creationTests, basicsTests, getAndSetTests, takingArraysApartTests, mappingAndFoldingTests]
tests/elm/Test/Dict.elm+2−2
@@ -9,7 +9,7 @@ import ElmTest.Test (..)
9animals : Dict.Dict String String
9animals : Dict.Dict String String
10animals = Dict.fromList [ ("Tom", "cat"), ("Jerry", "mouse") ]
10animals = Dict.fromList [ ("Tom", "cat"), ("Jerry", "mouse") ]
11
11
12−tests : [Test]
12+tests : Test
13tests =
13tests =
14 let getTests =
14 let getTests =
15 [ test "get 1" <| assertEqual (Just "cat") (Dict.get "Tom" animals)
15 [ test "get 1" <| assertEqual (Just "cat") (Dict.get "Tom" animals)
@@ -23,4 +23,4 @@ tests =
23 , test "partition" <| assertEqual (Dict.singleton "Tom" "cat", Dict.singleton "Jerry" "mouse") (Dict.partition (\k v -> k == "Tom") animals)
23 , test "partition" <| assertEqual (Dict.singleton "Tom" "cat", Dict.singleton "Jerry" "mouse") (Dict.partition (\k v -> k == "Tom") animals)
24 ]
24 ]
25 in
25 in
26− List.concat [ getTests, filterTests ]
26+ Suite "Dict Tests" <| List.concat [ getTests, filterTests ]
tests/elm/Test/List.elm+6−6
@@ -5,29 +5,29 @@ import List
5import ElmTest.Assertion (..)
5import ElmTest.Assertion (..)
6import ElmTest.Test (..)
6import ElmTest.Test (..)
7
7
8−tests : [Test]
8+tests : Test
9tests =
9tests =
10 let partitionTests =
10 let partitionTests =
11 let p1 = id
11 let p1 = id
12 p2 x = x < 3
12 p2 x = x < 3
13 isEven n = n `mod` 2 == 0
13 isEven n = n `mod` 2 == 0
14− in [ test "simple partition" <| assertEqual ([True],[False]) (List.partition p1 [False, True]),
14+ in Suite "partition Tests" [ 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]),
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]),
16+ test "partition doc check 1" <| assertEqual ([0,0,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]),
17 test "partition doc check 2" <| assertEqual ([0,2,4], [1,3,5]) (partition isEven [0..5]),
18 let n = 100000
18 let n = 100000
19 ts = repeat n True
19 ts = repeat n True
20 fs = repeat n False
20 fs = repeat n False
21 in test "partition stress test" <| assertEqual (ts, fs) (partition p1 (fs++ts))
21 in test "partition stress test" <| assertEqual (ts, fs) (partition p1 (fs++ts))
22 ]
22 ]
23− unzipTests = [
23+ unzipTests = Suite "unzip Tests" [
24 test "unzip doc check" <| assertEqual ([0,17,1337],[True,False,True]) (unzip [(0, True), (17, False), (1337, True)]),
24 test "unzip doc check" <| assertEqual ([0,17,1337],[True,False,True]) (unzip [(0, True), (17, False), (1337, True)]),
25 let n = 100000
25 let n = 100000
26 ts = repeat n True
26 ts = repeat n True
27 fs = repeat n False
27 fs = repeat n False
28 in test "unzip stress test" <| assertEqual (ts, fs) (unzip (zip ts fs))
28 in test "unzip stress test" <| assertEqual (ts, fs) (unzip (zip ts fs))
29 ]
29 ]
30− intersperseTests = [
30+ intersperseTests = Suite "intersperse Tests" [
31 test "intersperse doc check" <| assertEqual ["turtles","on","turtles","on","turtles"] (intersperse "on" ["turtles","turtles","turtles"]),
31 test "intersperse doc check" <| assertEqual ["turtles","on","turtles","on","turtles"] (intersperse "on" ["turtles","turtles","turtles"]),
32 let n = 100000
32 let n = 100000
33 ts = repeat n True
33 ts = repeat n True
@@ -35,4 +35,4 @@ tests =
35 in test "intersperse stress test" <| assertEqual (tail . List.concat <| zipWith (\x y -> [x,y]) fs ts)
35 in test "intersperse stress test" <| assertEqual (tail . List.concat <| zipWith (\x y -> [x,y]) fs ts)
36 (intersperse False ts)
36 (intersperse False ts)
37 ]
37 ]
38− in List.concat [partitionTests, unzipTests, intersperseTests]
38+ in Suite "List Tests" [partitionTests, unzipTests, intersperseTests]
tests/elm/Test/Set.elm+4−4
@@ -19,9 +19,9 @@ setPart2 = Set.fromList [51..100]
19pred : Int -> Bool
19pred : Int -> Bool
20pred x = x <= 50
20pred x = x <= 50
21
21
22−tests : [Test]
22+tests : Test
23tests =
23tests =
24 let
24 let
25− filterTests = [test "Simple filter" <| assertEqual setPart1 <| Set.filter pred set]
25+ filterTests = Suite "filter Tests" [test "Simple filter" <| assertEqual setPart1 <| Set.filter pred set]
26− partitionTests = [test "Simple partition" <| assertEqual (setPart1, setPart2) <| Set.partition pred set]
26+ partitionTests = Suite "partition Tests" [test "Simple partition" <| assertEqual (setPart1, setPart2) <| Set.partition pred set]
27− in List.concat [partitionTests, filterTests]
27+ in Suite "Set Tests" [partitionTests, filterTests]
tests/elm/Test/String.elm+18−10
@@ -6,21 +6,29 @@ import String (..)
6import ElmTest.Assertion (..)
6import ElmTest.Assertion (..)
7import ElmTest.Test (..)
7import ElmTest.Test (..)
8
8
9−tests : [Test]
9+tests : Test
10tests =
10tests =
11+ let isEmptyTests = Suite "isEmpty Tests" [
11− let isEmptyTests = [test "empty is empty" <| assert <| isEmpty "",
12+ test "empty is empty" <| assert <| isEmpty "",
12− test "not empty" <| assert <| not . isEmpty <| "the world"]
13+ test "not empty" <| assert <| not . isEmpty <| "the world"
14+ ]
13 lengthTest = test "length of innumerable" <| assertEqual 11 (length "innumerable")
15 lengthTest = test "length of innumerable" <| assertEqual 11 (length "innumerable")
14 reverseTest = test "reverse test" <| assertEqual "desserts" (reverse "stressed")
16 reverseTest = test "reverse test" <| assertEqual "desserts" (reverse "stressed")
15 repeatTest = test "repeat test" <| assertEqual "hahaha" (repeat 3 "ha")
17 repeatTest = test "repeat test" <| assertEqual "hahaha" (repeat 3 "ha")
18+ unconsTests = Suite "uncons Tests" [
16− unconsTests = [test "nonempty uncons" <| assertEqual (Just ('a',"bc")) (uncons "abc"),
19+ test "nonempty uncons" <| assertEqual (Just ('a',"bc")) (uncons "abc"),
17− test "empty uncons" <| assertEqual Nothing (uncons "")]
20+ test "empty uncons" <| assertEqual Nothing (uncons "")
21+ ]
18 appendTest = test "append test" <| assertEqual "butterfly" (append "butter" "fly")
22 appendTest = test "append test" <| assertEqual "butterfly" (append "butter" "fly")
19 concatTest = test "concat test" <| assertEqual "nevertheless" (concat ["never","the","less"])
23 concatTest = test "concat test" <| assertEqual "nevertheless" (concat ["never","the","less"])
24+ splitTests = Suite "split Tests" [
20− splitTests = [test "split commas" <| assertEqual ["cat","dog","cow"] (split "," "cat,dog,cow"),
25+ test "split commas" <| assertEqual ["cat","dog","cow"] (split "," "cat,dog,cow"),
21− test "split slashes"<| assertEqual ["home","evan","Desktop", ""] (split "/" "home/evan/Desktop/")]
26+ test "split slashes"<| assertEqual ["home","evan","Desktop", ""] (split "/" "home/evan/Desktop/")
27+ ]
28+ joinTests = Suite "join Tests" [
22− joinTests = [test "join spaces" <| assertEqual "cat dog cow" (join " " ["cat","dog","cow"]),
29+ test "join spaces" <| assertEqual "cat dog cow" (join " " ["cat","dog","cow"]),
23− test "join slashes" <| assertEqual "home/evan/Desktop" (join "/" ["home","evan","Desktop"])]
30+ test "join slashes" <| assertEqual "home/evan/Desktop" (join "/" ["home","evan","Desktop"])
31+ ]
24
32
25 endsWithTest = test "endsWith Check" (assert <| endsWith "h" "th")
33 endsWithTest = test "endsWith Check" (assert <| endsWith "h" "th")
26− in List.concat [isEmptyTests, [lengthTest, reverseTest, repeatTest], unconsTests, [appendTest, concatTest], splitTests, joinTests, [endsWithTest]]
34+ in Suite "String Tests" [isEmptyTests, lengthTest, reverseTest, repeatTest, unconsTests, appendTest, concatTest, splitTests, joinTests, endsWithTest]
tests/elm/Test/Trampoline.elm+3−3
@@ -21,9 +21,9 @@ goodSum n =
21 _ -> Continue (\_ -> sumT (x-1) (acc+x))
21 _ -> Continue (\_ -> sumT (x-1) (acc+x))
22 in trampoline <| sumT n 0
22 in trampoline <| sumT n 0
23
23
24−tests : [Test]
24+tests : Test
25tests =
25tests =
26 let mkLoopCheck n = test ("Equivalent Loop Check #"++ show n) (assertEqual (badSum n) (goodSum n))
26 let mkLoopCheck n = test ("Equivalent Loop Check #"++ show n) (assertEqual (badSum n) (goodSum n))
27− loopChecks = map mkLoopCheck [0..25]
27+ loopChecks = Suite "Equivalent to untrampolined Tests" <| map mkLoopCheck [0..25]
28 noStackOverflow = test "Trampoline Deep Recursion Test" (assertEqual 500000500000 (goodSum 1000000))
28 noStackOverflow = test "Trampoline Deep Recursion Test" (assertEqual 500000500000 (goodSum 1000000))
29− in noStackOverflow :: loopChecks
29+ in Suite "Trampoline Tests" [noStackOverflow, loopChecks]