aboutsummaryrefslogtreecommitdiff
path: root/gen/bool.erl
blob: 8b9c1c40a87fb00d1fd1a592effbd0dd0bc6d2ea (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
54
-module(bool).
-compile(no_auto_import).
-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.