aboutsummaryrefslogtreecommitdiff
path: root/gen/bool.erl
blob: a02edc8a176e5580e4c862f3555bef26365acc95 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
-module(bool).
-compile(no_auto_import).
-include_lib("eunit/include/eunit.hrl").

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

negate(Bool) ->
    case Bool of
        true ->
            false;

        false ->
            true
    end.

-ifdef(TEST).
negate_test() ->
    expect:false(negate(true)),
    expect:true(negate(false)).
-endif.

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

        false ->
            B
    end.

-ifdef(TEST).
max_test() ->
    expect:equal(max(true, true), true),
    expect:equal(max(true, false), true),
    expect:equal(max(false, false), false),
    expect:equal(max(false, true), true).
-endif.

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

        true ->
            B
    end.

-ifdef(TEST).
min_test() ->
    expect:equal(min(true, true), true),
    expect:equal(min(true, false), false),
    expect:equal(min(false, false), false),
    expect:equal(min(false, true), false).
-endif.

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

        true ->
            1
    end.

-ifdef(TEST).
to_int_test() ->
    expect:equal(to_int(true), 1),
    expect:equal(to_int(false), 0).
-endif.