aboutsummaryrefslogtreecommitdiff
path: root/gen/test/gleam@pair_test.erl
blob: d073e19778cf0c855dc6876618566d7d57bccd57 (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
-module(gleam@pair_test).
-compile(no_auto_import).

-export([first_test/0, second_test/0, swap_test/0, map_first_test/0, map_second_test/0]).

first_test() ->
    gleam@should:equal(gleam@pair:first({1, 2}), 1),
    gleam@should:equal(gleam@pair:first({<<"abc"/utf8>>, []}), <<"abc"/utf8>>).

second_test() ->
    gleam@should:equal(gleam@pair:second({1, 2}), 2),
    gleam@should:equal(gleam@pair:second({<<"abc"/utf8>>, []}), []).

swap_test() ->
    gleam@should:equal(gleam@pair:swap({1, <<"2"/utf8>>}), {<<"2"/utf8>>, 1}).

map_first_test() ->
    Inc = fun(A) -> A + 1 end,
    gleam@should:equal(gleam@pair:map_first({1, 2}, Inc), {2, 2}),
    gleam@should:equal(gleam@pair:map_first({8, 2}, Inc), {9, 2}),
    gleam@should:equal(gleam@pair:map_first({0, -2}, Inc), {1, -2}),
    gleam@should:equal(gleam@pair:map_first({-10, 20}, Inc), {-9, 20}).

map_second_test() ->
    Dec = fun(A) -> A - 1 end,
    gleam@should:equal(gleam@pair:map_second({1, 2}, Dec), {1, 1}),
    gleam@should:equal(gleam@pair:map_second({8, 2}, Dec), {8, 1}),
    gleam@should:equal(gleam@pair:map_second({0, -2}, Dec), {0, -3}),
    gleam@should:equal(gleam@pair:map_second({-10, 20}, Dec), {-10, 19}).