DEV Community

Discussion on: Daily Challenge #75 - Set Alarm

Collapse
 
aminnairi profile image
Amin

Elm

setAlarm : Bool -> Bool -> Bool
setAlarm employed onVacation =
    case (employed, onVacation) of
        (True, False) ->
            True

        _ ->
            False

Explainations

module SetAlarm exposing (setAlarm)

This will expose our only function setAlarm to the outside world (used in our tests, see below).

setAlarm : Bool -> Bool -> Bool
setAlarm employed onVacation =

This will define a function named setAlarm. It takes three parameters. Which are all three booleans.

    case (employed, onVacation) of

We wrap our two parameters into a tuple. That way we can easily work with pattern matching.

Tests

module SetAlarmTest exposing (suite)

import Expect exposing (equal)
import SetAlarm exposing (setAlarm)
import Test exposing (Test, describe, test)


suite : Test
suite =
    describe "Set alarm"
        [ test "It should return true when employed and not on vacation" <| \_ -> equal True <| setAlarm True False
        , test "It should return true when unemployed and not on vacation" <| \_ -> equal False <| setAlarm False False
        , test "It should return true when employed and on vacation" <| \_ -> equal False <| setAlarm True True
        , test "It should return true when unemployed and on vacation" <| \_ -> equal False <| setAlarm False True
        ]