on master help sign in
Make tests prettier and add String tests
7c966d6Max New
tests/elm/Test.elm+2−2
@@ -9,11 +9,11 @@ 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
12import Test.Trampoline as Trampoline
13import Test.Trampoline as Trampoline
13
14
14−{- Failing test to get it going -}
15tests : [Test]
15tests : [Test]
16−tests = Trampoline.tests
16+tests = String.tests ++ Trampoline.tests
17
17
18console : IO ()
18console : IO ()
19console = runDisplay tests
19console = 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 @@
1module Test.Trampoline (tests) where
1module Test.Trampoline (tests) where
2
2
3−import ElmTest.Test (..)
4−
5import Trampoline (..)
3import Trampoline (..)
6
4
5+import ElmTest.Assertion (..)
6+import ElmTest.Test (..)
7+
7badSum : Int -> Int
8badSum : Int -> Int
8badSum n =
9badSum n =
9 let loop x acc =
10 let loop x acc =
@@ -20,5 +21,9 @@ goodSum n =
20 _ -> Continue (\_ -> sumT (x-1) (acc+x))
21 _ -> Continue (\_ -> sumT (x-1) (acc+x))
21 in trampoline <| sumT n 0
22 in trampoline <| sumT n 0
22
23
23−tests = goodSum 1000000 `equals` 500000500000 :: map (\n -> badSum n `equals` goodSum n) [0..50]
24+tests : [Test]
24−
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