on master help sign in
Make tests prettier and add String tests

Starting with the documentation examples. Found a bug already!

commit7c966d625ba70794bfc97966b673b96a5a075de3 authorMax New <maxsnew@gmail.com> dateTue 1 Apr 2014, 08:58 (13 years ago) parentb412396
3 files changed+37−6
tests/elm/Test.elm+2−2 tests/elm/Test/String.elm+26 tests/elm/Test/Trampoline.elm+9−4
tests/elm/Test.elm+2−2
@@ -9,11 +9,11 @@ import IO.IO (..)
99import IO.Runner (Request, Response)
1010import IO.Runner as Run
1111
12+import Test.String as String
1213import Test.Trampoline as Trampoline
1314
14−{- Failing test to get it going -}
1515tests : [Test]
16−tests = Trampoline.tests
16+tests = String.tests ++ Trampoline.tests
1717
1818console : IO ()
1919console = runDisplay tests
tests/elm/Test/String.elmnew file+26
@@ -0,0 +1,26 @@
1+module Test.String (tests) where
2+
3+import List
4+import String (..)
5+
6+import ElmTest.Assertion (..)
7+import ElmTest.Test (..)
8+
9+tests : [Test]
10+tests =
11+ let isEmptyTests = [test "empty is empty" <| assert <| isEmpty "",
12+ test "not empty" <| assert <| not . isEmpty <| "the world"]
13+ lengthTest = test "length of innumerable" <| assertEqual 11 (length "innumerable")
14+ reverseTest = test "reverse test" <| assertEqual "desserts" (reverse "stressed")
15+ 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+ appendTest = test "append test" <| assertEqual "butterfly" (append "butter" "fly")
19+ 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+
25+ endsWithTest = test "endsWith Check" (assert <| endsWith "h" "th")
26+ in List.concat [isEmptyTests, [lengthTest, reverseTest, repeatTest], unconsTests, [appendTest, concatTest], splitTests, joinTests, [endsWithTest]]
tests/elm/Test/Trampoline.elm+9−4
@@ -1,9 +1,10 @@
11module Test.Trampoline (tests) where
22
3−import ElmTest.Test (..)
4−
53import Trampoline (..)
64
5+import ElmTest.Assertion (..)
6+import ElmTest.Test (..)
7+
78badSum : Int -> Int
89badSum n =
910 let loop x acc =
@@ -20,5 +21,9 @@ goodSum n =
2021 _ -> Continue (\_ -> sumT (x-1) (acc+x))
2122 in trampoline <| sumT n 0
2223
23−tests = goodSum 1000000 `equals` 500000500000 :: map (\n -> badSum n `equals` goodSum n) [0..50]
24−
24+tests : [Test]
25+tests =
26+ let mkLoopCheck n = test ("Equivalent Loop Check #"++ show n) (assertEqual (badSum n) (goodSum n))
27+ loopChecks = map mkLoopCheck [0..25]
28+ noStackOverflow = test "Trampoline Deep Recursion Test" (assertEqual 500000500000 (goodSum 1000000))
29+ in noStackOverflow :: loopChecks