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