elm/exercises/strain/tests/Tests.elm

81 lines
2.3 KiB
Elm
Raw Normal View History

2017-05-27 17:56:31 +00:00
module Tests exposing (..)
2015-10-13 18:56:46 +00:00
import Test exposing (..)
import Expect
import Strain exposing (keep, discard)
2015-10-13 18:56:46 +00:00
import String
even : Int -> Bool
even number =
number % 2 == 0
odd : Int -> Bool
odd number =
number % 2 == 1
isFirstLetter : String -> String -> Bool
isFirstLetter letter word =
(String.left 1 word) == letter
2016-12-17 22:15:34 +00:00
lessThanTen : comparable -> Bool
lessThanTen num =
num < 10
2015-10-13 18:56:46 +00:00
tests : Test
tests =
describe "Strain"
[ test "empty keep" <|
\() ->
Expect.equal []
(keep lessThanTen [])
, test "keep everything" <|
\() ->
Expect.equal [ 1, 2, 3 ]
(keep lessThanTen [ 1, 2, 3 ])
, test "keep first and last" <|
\() ->
Expect.equal [ 1, 3 ]
(keep odd [ 1, 2, 3 ])
, test "keep nothing" <|
\() ->
Expect.equal []
(keep even [ 1, 3, 5, 7 ])
, test "keep neither first nor last" <|
\() ->
Expect.equal [ 2 ]
(keep even [ 1, 2, 3 ])
, test "keep strings" <|
\() ->
Expect.equal [ "zebra", "zombies", "zealot" ]
(keep (isFirstLetter "z") [ "apple", "zebra", "banana", "zombies", "cherimoya", "zealot" ])
, test "empty discard" <|
\() ->
Expect.equal []
(discard lessThanTen [])
, test "discard everything" <|
\() ->
Expect.equal []
(discard lessThanTen [ 1, 2, 3 ])
, test "discard first and last" <|
\() ->
Expect.equal [ 2 ]
(discard odd [ 1, 2, 3 ])
, test "discard nothing" <|
\() ->
Expect.equal [ 1, 3, 5, 7 ]
(discard even [ 1, 3, 5, 7 ])
, test "discard neither first nor last" <|
\() ->
Expect.equal [ 1, 3 ]
(discard even [ 1, 2, 3 ])
, test "discard strings" <|
\() ->
Expect.equal [ "apple", "banana", "cherimoya" ]
(discard (isFirstLetter "z") [ "apple", "zebra", "banana", "zombies", "cherimoya", "zealot" ])
]