on master help sign in
Merge pull request #599 from maxsnew/test-suites

Test suites

commit351e2458f423ef71cd6dce1a62f1394702b06a95 authorEvan Czaplicki <info@elm-lang.org> dateMon 28 Apr 2014, 18:03 (13 years ago) parent394f70292d0b62
9 files changed+49−35
Elm-Test+1−1 automaton+1−1 tests/elm/Test.elm+8−2 tests/elm/Test/Array.elm+7−7 tests/elm/Test/Dict.elm+2−2 tests/elm/Test/List.elm+5−5 tests/elm/Test/Set.elm+4−4 tests/elm/Test/String.elm+18−10 tests/elm/Test/Trampoline.elm+3−3
Elm-Test+1−1

Submodule changed.

automaton+1−1

Submodule changed.

tests/elm/Test.elm+8−2
@@ -16,8 +16,14 @@ import Test.Set as Set
1616import Test.String as String
1717import Test.Trampoline as Trampoline
1818
19−tests : [Test]
20−tests = String.tests ++ Trampoline.tests ++ Array.tests ++ Dict.tests ++ Set.tests ++ List.tests
19+tests : Test
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+ ]
2127
2228console : IO ()
2329console = runDisplay tests
tests/elm/Test/Array.elm+7−7
@@ -6,9 +6,9 @@ import Array
66import ElmTest.Assertion (..)
77import ElmTest.Test (..)
88
9−tests : [Test]
9+tests : Test
1010tests =
11− let creationTests =
11+ let creationTests = suite "Creation"
1212 [ test "empty" <| assertEqual Array.empty (Array.fromList [])
1313 , test "initialize" <| assertEqual (Array.initialize 4 id) (Array.fromList [0,1,2,3])
1414 , test "initialize 2" <| assertEqual (Array.initialize 4 (\n -> n*n)) (Array.fromList [0,1,4,9])
@@ -20,13 +20,13 @@ tests =
2020 , test "repeat 3" <| assertEqual (Array.repeat 3 "cat") (Array.fromList ["cat","cat","cat"])
2121 , test "fromList" <| assertEqual (Array.fromList []) Array.empty
2222 ]
23− basicsTests =
23+ basicsTests = suite "Basics"
2424 [ test "length" <| assertEqual (Array.length (Array.fromList [1,2,3])) 3
2525 , test "length - Long" <| assertEqual (Array.length (Array.repeat 10000 0)) 10000
2626 , test "push" <| assertEqual (Array.push 3 (Array.fromList [1,2])) (Array.fromList [1,2,3])
2727 , test "append" <| assertEqual (Array.toList <| Array.append (Array.repeat 2 42) (Array.repeat 3 81)) ([42,42,81,81,81])
2828 ]
29− getAndSetTests =
29+ getAndSetTests = suite "Get and Set"
3030 [ test "get" <| assertEqual (Array.get 1 (Array.fromList [3,2,1])) (Just 2)
3131 , test "get 2" <| assertEqual (Array.get 5 (Array.fromList [3,2,1])) Nothing
3232 , test "get 3" <| assertEqual (Array.get -1 (Array.fromList [3,2,1])) Nothing
@@ -35,14 +35,14 @@ tests =
3535 , test "getOrFail" <| assertEqual (Array.getOrFail 2 (Array.fromList [3,2,1])) 1
3636 , test "set" <| assertEqual (Array.set 1 7 (Array.fromList [1,2,3])) (Array.fromList [1,7,3])
3737 ]
38− takingArraysApartTests =
38+ takingArraysApartTests = suite "Taking Arrays Apart"
3939 [ test "toList" <| assertEqual (Array.toList (Array.fromList [3,5,8])) [3,5,8]
4040 , test "toIndexedList" <| assertEqual (Array.toIndexedList (Array.fromList ["cat","dog"])) [(0,"cat"), (1,"dog")]
4141 , test "slice" <| assertEqual (Array.slice 1 2 (Array.fromList [0,1,2,3,4])) (Array.fromList [1,2])
4242 , test "slice 2" <| assertEqual (Array.slice 1 -2 (Array.fromList [0,1,2,3,4])) (Array.fromList [1,2,3])
4343 , test "slice 3" <| assertEqual (Array.slice -3 -2 (Array.fromList [0,1,2,3,4])) (Array.fromList [2,3])
4444 ]
45− mappingAndFoldingTests =
45+ mappingAndFoldingTests = suite "Mapping and Folding"
4646 [ test "map" <| assertEqual (Array.map sqrt (Array.fromList [1,4,9])) (Array.fromList [1,2,3])
4747 , test "indexedMap" <| assertEqual (Array.indexedMap (*) (Array.fromList [5,5,5])) (Array.fromList [0,5,10])
4848 , test "foldl" <| assertEqual (Array.foldl (::) [] (Array.fromList [1,2,3])) [3,2,1]
@@ -51,4 +51,4 @@ tests =
5151 , test "filter" <| assertEqual (Array.filter (\x -> x `mod` 2 == 0) (Array.fromList [1..6])) (Array.fromList [2,4,6])
5252 ]
5353 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 (..)
99animals : Dict.Dict String String
1010animals = Dict.fromList [ ("Tom", "cat"), ("Jerry", "mouse") ]
1111
12−tests : [Test]
12+tests : Test
1313tests =
1414 let getTests =
1515 [ test "get 1" <| assertEqual (Just "cat") (Dict.get "Tom" animals)
@@ -23,4 +23,4 @@ tests =
2323 , test "partition" <| assertEqual (Dict.singleton "Tom" "cat", Dict.singleton "Jerry" "mouse") (Dict.partition (\k v -> k == "Tom") animals)
2424 ]
2525 in
26− List.concat [ getTests, filterTests ]
26+ suite "Dict Tests" <| List.concat [ getTests, filterTests ]
tests/elm/Test/List.elm+5−5
@@ -5,13 +5,13 @@ import List
55import ElmTest.Assertion (..)
66import ElmTest.Test (..)
77
8−tests : [Test]
8+tests : Test
99tests =
1010 let partitionTests =
1111 let p1 = id
1212 p2 x = x < 3
1313 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]),
1515 test "order check" <| assertEqual ([2,1], [5,6]) (List.partition p2 [2,5,6,1]),
1616 test "partition doc check 1" <| assertEqual ([0,1,2], [3,4,5]) (partition p2 [0..5]),
1717 test "partition doc check 2" <| assertEqual ([0,2,4], [1,3,5]) (partition isEven [0..5]),
@@ -20,14 +20,14 @@ tests =
2020 fs = repeat n False
2121 in test "partition stress test" <| assertEqual (ts, fs) (partition p1 (fs++ts))
2222 ]
23− unzipTests = [
23+ unzipTests = suite "unzip Tests" [
2424 test "unzip doc check" <| assertEqual ([0,17,1337],[True,False,True]) (unzip [(0, True), (17, False), (1337, True)]),
2525 let n = 100000
2626 ts = repeat n True
2727 fs = repeat n False
2828 in test "unzip stress test" <| assertEqual (ts, fs) (unzip (zip ts fs))
2929 ]
30− intersperseTests = [
30+ intersperseTests = suite "intersperse Tests" [
3131 test "intersperse doc check" <| assertEqual ["turtles","on","turtles","on","turtles"] (intersperse "on" ["turtles","turtles","turtles"]),
3232 let n = 100000
3333 ts = repeat n True
@@ -35,4 +35,4 @@ tests =
3535 in test "intersperse stress test" <| assertEqual (tail . List.concat <| zipWith (\x y -> [x,y]) fs ts)
3636 (intersperse False ts)
3737 ]
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]
1919pred : Int -> Bool
2020pred x = x <= 50
2121
22−tests : [Test]
22+tests : Test
2323tests =
2424 let
25− filterTests = [test "Simple filter" <| assertEqual setPart1 <| Set.filter pred set]
26− partitionTests = [test "Simple partition" <| assertEqual (setPart1, setPart2) <| Set.partition pred set]
27− in List.concat [partitionTests, filterTests]
25+ filterTests = suite "filter Tests" [test "Simple filter" <| assertEqual setPart1 <| Set.filter pred set]
26+ partitionTests = suite "partition Tests" [test "Simple partition" <| assertEqual (setPart1, setPart2) <| Set.partition pred set]
27+ in suite "Set Tests" [partitionTests, filterTests]
tests/elm/Test/String.elm+18−10
@@ -6,21 +6,29 @@ import String (..)
66import ElmTest.Assertion (..)
77import ElmTest.Test (..)
88
9−tests : [Test]
9+tests : Test
1010tests =
11− let isEmptyTests = [test "empty is empty" <| assert <| isEmpty "",
12− test "not empty" <| assert <| not . isEmpty <| "the world"]
11+ let isEmptyTests = suite "isEmpty Tests" [
12+ test "empty is empty" <| assert <| isEmpty "",
13+ test "not empty" <| assert <| not . isEmpty <| "the world"
14+ ]
1315 lengthTest = test "length of innumerable" <| assertEqual 11 (length "innumerable")
1416 reverseTest = test "reverse test" <| assertEqual "desserts" (reverse "stressed")
1517 repeatTest = test "repeat test" <| assertEqual "hahaha" (repeat 3 "ha")
16− unconsTests = [test "nonempty uncons" <| assertEqual (Just ('a',"bc")) (uncons "abc"),
17− test "empty uncons" <| assertEqual Nothing (uncons "")]
18+ unconsTests = suite "uncons Tests" [
19+ test "nonempty uncons" <| assertEqual (Just ('a',"bc")) (uncons "abc"),
20+ test "empty uncons" <| assertEqual Nothing (uncons "")
21+ ]
1822 appendTest = test "append test" <| assertEqual "butterfly" (append "butter" "fly")
1923 concatTest = test "concat test" <| assertEqual "nevertheless" (concat ["never","the","less"])
20− splitTests = [test "split commas" <| assertEqual ["cat","dog","cow"] (split "," "cat,dog,cow"),
21− test "split slashes"<| assertEqual ["home","evan","Desktop", ""] (split "/" "home/evan/Desktop/")]
22− joinTests = [test "join spaces" <| assertEqual "cat dog cow" (join " " ["cat","dog","cow"]),
23− test "join slashes" <| assertEqual "home/evan/Desktop" (join "/" ["home","evan","Desktop"])]
24+ splitTests = suite "split Tests" [
25+ test "split commas" <| assertEqual ["cat","dog","cow"] (split "," "cat,dog,cow"),
26+ test "split slashes"<| assertEqual ["home","evan","Desktop", ""] (split "/" "home/evan/Desktop/")
27+ ]
28+ joinTests = suite "join Tests" [
29+ test "join spaces" <| assertEqual "cat dog cow" (join " " ["cat","dog","cow"]),
30+ test "join slashes" <| assertEqual "home/evan/Desktop" (join "/" ["home","evan","Desktop"])
31+ ]
2432
2533 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 =
2121 _ -> Continue (\_ -> sumT (x-1) (acc+x))
2222 in trampoline <| sumT n 0
2323
24−tests : [Test]
24+tests : Test
2525tests =
2626 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]
2828 noStackOverflow = test "Trampoline Deep Recursion Test" (assertEqual 500000500000 (goodSum 1000000))
29− in noStackOverflow :: loopChecks
29+ in suite "Trampoline Tests" [noStackOverflow, loopChecks]