diff options
author | Louis Pilfold <louis@lpil.uk> | 2019-03-02 19:08:46 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-03-02 19:10:45 +0000 |
commit | ea5e146cf5ffd26a1c77a6b7e3160d98fc503c3c (patch) | |
tree | 98c7273268ed5eecaccb2d9d88d983181496c293 /gen/bool.erl | |
parent | ceb115b4dbc878b885521743f6018563b2dea3c8 (diff) | |
download | gleam_stdlib-ea5e146cf5ffd26a1c77a6b7e3160d98fc503c3c.tar.gz gleam_stdlib-ea5e146cf5ffd26a1c77a6b7e3160d98fc503c3c.zip |
Compile stdlib
Diffstat (limited to 'gen/bool.erl')
-rw-r--r-- | gen/bool.erl | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/gen/bool.erl b/gen/bool.erl new file mode 100644 index 0000000..52a9379 --- /dev/null +++ b/gen/bool.erl @@ -0,0 +1,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. |