aboutsummaryrefslogtreecommitdiff
path: root/gen/bool.erl
blob: 52a93792357eca99fc59faf6d3097a53de9a9b3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-module(bool).
-include_lib("eunit/include/eunit.hrl").

-export([max/2, min/2, to_int/1]).

max(A, B) ->
    case A of
        true ->
            true;

        false ->
            B
    end.

-ifdef(TEST).
max_test() ->
    _ = fun(Capture1) -> expect:equal(Capture1, true) end(max(true, true)),
    _ = fun(Capture1) -> expect:equal(Capture1, true) end(max(true, false)),
    _ = fun(Capture1) -> expect:equal(Capture1, false) end(max(false, false)),
    fun(Capture1) -> expect:equal(Capture1, true) end(max(false, true)).
-endif.

min(A, B) ->
    case A of
        false ->
            false;

        true ->
            B
    end.

-ifdef(TEST).
min_test() ->
    _ = fun(Capture1) -> expect:equal(Capture1, true) end(min(true, true)),
    _ = fun(Capture1) -> expect:equal(Capture1, false) end(min(true, false)),
    _ = fun(Capture1) -> expect:equal(Capture1, false) end(min(false, false)),
    fun(Capture1) -> expect:equal(Capture1, false) end(min(false, true)).
-endif.

to_int(Bool) ->
    case Bool of
        false ->
            0;

        true ->
            1
    end.

-ifdef(TEST).
to_int_test() ->
    _ = fun(Capture1) -> expect:equal(Capture1, 1) end(to_int(true)),
    fun(Capture1) -> expect:equal(Capture1, 0) end(to_int(false)).
-endif.