Current section

Files

Jump to
gleam_stdlib gen test gleam@list_test.erl
Raw

gen/test/gleam@list_test.erl

-module(gleam@list_test).
-compile(no_auto_import).
-export([length_test/0, reverse_test/0, is_empty_test/0, contains_test/0, head_test/0, tail_test/0, filter_test/0, filter_map_test/0, map_test/0, map_fold_test/0, try_map_test/0, drop_test/0, take_test/0, new_test/0, append_test/0, flatten_test/0, flat_map_test/0, fold_test/0, fold_right_test/0, index_fold_test/0, fold_until_test/0, try_fold_test/0, find_map_test/0, find_test/0, all_test/0, any_test/0, zip_test/0, strict_zip_test/0, unzip_test/0, intersperse_test/0, at_test/0, unique_test/0, sort_test/0, index_map_test/0, range_test/0, repeat_test/0, split_test/0, split_while_test/0, key_find_test/0, pop_test/0, pop_map_test/0, key_pop_test/0, key_set_test/0, partition_test/0, permutations_test/0, window_test/0, window_by_2_test/0, drop_while_test/0, take_while_test/0, chunk_test/0, sized_chunk_test/0, reduce_test/0, scan_test/0, last_test/0, combinations_test/0, combination_pairs_test/0, interleave_test/0, transpose_test/0]).
-spec length_test() -> nil.
length_test() ->
_pipe = gleam@list:length([]),
gleam@should:equal(_pipe, 0),
_pipe@1 = gleam@list:length([1]),
gleam@should:equal(_pipe@1, 1),
_pipe@2 = gleam@list:length([1, 1]),
gleam@should:equal(_pipe@2, 2),
_pipe@3 = gleam@list:length([1, 1, 1]),
gleam@should:equal(_pipe@3, 3).
-spec reverse_test() -> nil.
reverse_test() ->
_pipe = gleam@list:reverse([]),
gleam@should:equal(_pipe, []),
_pipe@1 = gleam@list:reverse([1]),
gleam@should:equal(_pipe@1, [1]),
_pipe@2 = gleam@list:reverse([1, 2]),
gleam@should:equal(_pipe@2, [2, 1]),
_pipe@3 = gleam@list:reverse([1, 2, 3, 4, 5]),
gleam@should:equal(_pipe@3, [5, 4, 3, 2, 1]).
-spec is_empty_test() -> nil.
is_empty_test() ->
_pipe = gleam@list:is_empty([]),
gleam@should:be_true(_pipe),
_pipe@1 = gleam@list:is_empty([1]),
gleam@should:be_false(_pipe@1).
-spec contains_test() -> nil.
contains_test() ->
_pipe = gleam@list:contains([0, 4, 5, 1], 1),
gleam@should:be_true(_pipe),
_pipe@1 = gleam@list:contains([0, 4, 5, 7], 1),
gleam@should:be_false(_pipe@1),
_pipe@2 = gleam@list:contains([], 1),
gleam@should:be_false(_pipe@2).
-spec head_test() -> nil.
head_test() ->
_pipe = gleam@list:head([0, 4, 5, 7]),
gleam@should:equal(_pipe, {ok, 0}),
_pipe@1 = gleam@list:head([]),
gleam@should:equal(_pipe@1, {error, nil}).
-spec tail_test() -> nil.
tail_test() ->
_pipe = gleam@list:tail([0, 4, 5, 7]),
gleam@should:equal(_pipe, {ok, [4, 5, 7]}),
_pipe@1 = gleam@list:tail([0]),
gleam@should:equal(_pipe@1, {ok, []}),
_pipe@2 = gleam@list:tail([]),
gleam@should:equal(_pipe@2, {error, nil}).
-spec filter_test() -> nil.
filter_test() ->
_pipe = [],
_pipe@1 = gleam@list:filter(_pipe, fun(_) -> true end),
gleam@should:equal(_pipe@1, []),
_pipe@2 = [0, 4, 5, 7, 3],
_pipe@3 = gleam@list:filter(_pipe@2, fun(_) -> true end),
gleam@should:equal(_pipe@3, [0, 4, 5, 7, 3]),
_pipe@4 = [0, 4, 5, 7, 3],
_pipe@5 = gleam@list:filter(_pipe@4, fun(X) -> X > 4 end),
gleam@should:equal(_pipe@5, [5, 7]),
_pipe@6 = [0, 4, 5, 7, 3],
_pipe@7 = gleam@list:filter(_pipe@6, fun(X@1) -> X@1 < 4 end),
gleam@should:equal(_pipe@7, [0, 3]).
-spec filter_map_test() -> nil.
filter_map_test() ->
_pipe = [2, 4, 6, 1],
_pipe@1 = gleam@list:filter_map(_pipe, fun(X) -> {ok, X + 1} end),
gleam@should:equal(_pipe@1, [3, 5, 7, 2]),
_pipe@2 = [2, 4, 6, 1],
_pipe@3 = gleam@list:filter_map(_pipe@2, fun(A) -> {error, A} end),
gleam@should:equal(_pipe@3, []).
-spec map_test() -> nil.
map_test() ->
_pipe = [],
_pipe@1 = gleam@list:map(_pipe, fun(X) -> X * 2 end),
gleam@should:equal(_pipe@1, []),
_pipe@2 = [0, 4, 5, 7, 3],
_pipe@3 = gleam@list:map(_pipe@2, fun(X@1) -> X@1 * 2 end),
gleam@should:equal(_pipe@3, [0, 8, 10, 14, 6]).
-spec map_fold_test() -> nil.
map_fold_test() ->
_pipe = [1, 2, 3, 4],
_pipe@1 = gleam@list:map_fold(_pipe, 0, fun(Acc, I) -> {Acc + I, I * 2} end),
gleam@should:equal(_pipe@1, {10, [2, 4, 6, 8]}).
-spec try_map_test() -> nil.
try_map_test() ->
Fun = fun(X) -> case ((X =:= 6) orelse (X =:= 5)) orelse (X =:= 4) of
true ->
{ok, X * 2};
false ->
{error, X}
end end,
_pipe = [5, 6, 5, 6],
_pipe@1 = gleam@list:try_map(_pipe, Fun),
gleam@should:equal(_pipe@1, {ok, [10, 12, 10, 12]}),
_pipe@2 = [4, 6, 5, 7, 3],
_pipe@3 = gleam@list:try_map(_pipe@2, Fun),
gleam@should:equal(_pipe@3, {error, 7}).
-spec drop_test() -> nil.
drop_test() ->
_pipe = [],
_pipe@1 = gleam@list:drop(_pipe, 5),
gleam@should:equal(_pipe@1, []),
_pipe@2 = [1, 2, 3, 4, 5, 6, 7, 8],
_pipe@3 = gleam@list:drop(_pipe@2, 5),
gleam@should:equal(_pipe@3, [6, 7, 8]).
-spec take_test() -> nil.
take_test() ->
_pipe = [],
_pipe@1 = gleam@list:take(_pipe, 5),
gleam@should:equal(_pipe@1, []),
_pipe@2 = [1, 2, 3, 4, 5, 6, 7, 8],
_pipe@3 = gleam@list:take(_pipe@2, 5),
gleam@should:equal(_pipe@3, [1, 2, 3, 4, 5]).
-spec new_test() -> nil.
new_test() ->
_pipe = gleam@list:new(),
gleam@should:equal(_pipe, []).
-spec append_test() -> nil.
append_test() ->
_pipe = gleam@list:append([1], [2, 3]),
gleam@should:equal(_pipe, [1, 2, 3]),
_pipe@1 = gleam@list:append([1, 2], []),
gleam@should:equal(_pipe@1, [1, 2]),
_pipe@2 = gleam@list:append([], [1, 2]),
gleam@should:equal(_pipe@2, [1, 2]),
_pipe@3 = gleam@list:append([1, 2], [3, 4]),
gleam@should:equal(_pipe@3, [1, 2, 3, 4]),
_pipe@4 = gleam@list:append([1, 2, 3], []),
gleam@should:equal(_pipe@4, [1, 2, 3]),
_pipe@5 = gleam@list:append([1, 2, 3], [4]),
gleam@should:equal(_pipe@5, [1, 2, 3, 4]),
_pipe@6 = gleam@list:append([1, 2, 3, 4], [5]),
gleam@should:equal(_pipe@6, [1, 2, 3, 4, 5]),
_pipe@7 = gleam@list:append([], []),
gleam@should:equal(_pipe@7, []).
-spec flatten_test() -> nil.
flatten_test() ->
_pipe = gleam@list:flatten([]),
gleam@should:equal(_pipe, []),
_pipe@1 = gleam@list:flatten([[]]),
gleam@should:equal(_pipe@1, []),
_pipe@2 = gleam@list:flatten([[], [], []]),
gleam@should:equal(_pipe@2, []),
_pipe@3 = gleam@list:flatten([[1, 2], [], [3, 4]]),
gleam@should:equal(_pipe@3, [1, 2, 3, 4]).
-spec flat_map_test() -> nil.
flat_map_test() ->
_pipe = gleam@list:flat_map([1, 10, 20], fun(X) -> [X, X + 1] end),
gleam@should:equal(_pipe, [1, 2, 10, 11, 20, 21]).
-spec fold_test() -> nil.
fold_test() ->
_pipe = [1, 2, 3],
_pipe@1 = gleam@list:fold(_pipe, [], fun(Acc, X) -> [X | Acc] end),
gleam@should:equal(_pipe@1, [3, 2, 1]).
-spec fold_right_test() -> nil.
fold_right_test() ->
_pipe = [1, 2, 3],
_pipe@1 = gleam@list:fold_right(_pipe, [], fun(Acc, X) -> [X | Acc] end),
gleam@should:equal(_pipe@1, [1, 2, 3]).
-spec index_fold_test() -> nil.
index_fold_test() ->
_pipe = [<<"a"/utf8>>, <<"b"/utf8>>, <<"c"/utf8>>],
_pipe@1 = gleam@list:index_fold(
_pipe,
[],
fun(Acc, I, Ix) -> [{Ix, I} | Acc] end
),
gleam@should:equal(
_pipe@1,
[{2, <<"c"/utf8>>}, {1, <<"b"/utf8>>}, {0, <<"a"/utf8>>}]
).
-spec fold_until_test() -> nil.
fold_until_test() ->
_pipe = [1, 2, 3, 4],
_pipe@1 = gleam@list:fold_until(_pipe, 0, fun(Acc, N) -> case N < 4 of
true ->
{continue, Acc + N};
false ->
{stop, Acc}
end end),
gleam@should:equal(_pipe@1, 6).
-spec try_fold_test() -> nil.
try_fold_test() ->
_pipe = [1, 2, 3],
_pipe@1 = gleam@list:try_fold(_pipe, 0, fun(I, Acc) -> case I < 4 of
true ->
{ok, Acc + I};
false ->
{error, nil}
end end),
gleam@should:equal(_pipe@1, {ok, 6}),
_pipe@2 = [1, 2, 3],
_pipe@3 = gleam@list:try_fold(_pipe@2, 0, fun(I@1, Acc@1) -> case I@1 < 3 of
true ->
{ok, Acc@1 + I@1};
false ->
{error, nil}
end end),
gleam@should:equal(_pipe@3, {error, nil}).
-spec find_map_test() -> nil.
find_map_test() ->
F = fun(X) -> case X of
2 ->
{ok, 4};
_@1 ->
{error, nil}
end end,
_pipe = [1, 2, 3],
_pipe@1 = gleam@list:find_map(_pipe, F),
gleam@should:equal(_pipe@1, {ok, 4}),
_pipe@2 = [1, 3, 2],
_pipe@3 = gleam@list:find_map(_pipe@2, F),
gleam@should:equal(_pipe@3, {ok, 4}),
_pipe@4 = [1, 3],
_pipe@5 = gleam@list:find_map(_pipe@4, F),
gleam@should:equal(_pipe@5, {error, nil}).
-spec find_test() -> nil.
find_test() ->
Is_two = fun(X) -> X =:= 2 end,
_pipe = [1, 2, 3],
_pipe@1 = gleam@list:find(_pipe, Is_two),
gleam@should:equal(_pipe@1, {ok, 2}),
_pipe@2 = [1, 3, 2],
_pipe@3 = gleam@list:find(_pipe@2, Is_two),
gleam@should:equal(_pipe@3, {ok, 2}),
_pipe@4 = [1, 3],
_pipe@5 = gleam@list:find(_pipe@4, Is_two),
gleam@should:equal(_pipe@5, {error, nil}).
-spec all_test() -> nil.
all_test() ->
_pipe = gleam@list:all([1, 2, 3, 4, 5], fun(X) -> X > 0 end),
gleam@should:equal(_pipe, true),
_pipe@1 = gleam@list:all([1, 2, 3, 4, 5], fun(X@1) -> X@1 < 0 end),
gleam@should:equal(_pipe@1, false),
_pipe@2 = gleam@list:all([], fun(_) -> false end),
gleam@should:equal(_pipe@2, true).
-spec any_test() -> nil.
any_test() ->
_pipe = gleam@list:any([1, 2, 3, 4, 5], fun(X) -> X =:= 2 end),
gleam@should:equal(_pipe, true),
_pipe@1 = gleam@list:any([1, 2, 3, 4, 5], fun(X@1) -> X@1 < 0 end),
gleam@should:equal(_pipe@1, false),
_pipe@2 = gleam@list:any([], fun(_) -> false end),
gleam@should:equal(_pipe@2, false).
-spec zip_test() -> nil.
zip_test() ->
_pipe = gleam@list:zip([], [1, 2, 3]),
gleam@should:equal(_pipe, []),
_pipe@1 = gleam@list:zip([1, 2], []),
gleam@should:equal(_pipe@1, []),
_pipe@2 = gleam@list:zip([1, 2, 3], [4, 5, 6]),
gleam@should:equal(_pipe@2, [{1, 4}, {2, 5}, {3, 6}]),
_pipe@3 = gleam@list:zip([5, 6], [1, 2, 3]),
gleam@should:equal(_pipe@3, [{5, 1}, {6, 2}]),
_pipe@4 = gleam@list:zip([5, 6, 7], [1, 2]),
gleam@should:equal(_pipe@4, [{5, 1}, {6, 2}]).
-spec strict_zip_test() -> nil.
strict_zip_test() ->
_pipe = gleam@list:strict_zip([], [1, 2, 3]),
gleam@should:equal(_pipe, {error, length_mismatch}),
_pipe@1 = gleam@list:strict_zip([1, 2], []),
gleam@should:equal(_pipe@1, {error, length_mismatch}),
_pipe@2 = gleam@list:strict_zip([1, 2, 3], [4, 5, 6]),
gleam@should:equal(_pipe@2, {ok, [{1, 4}, {2, 5}, {3, 6}]}),
_pipe@3 = gleam@list:strict_zip([5, 6], [1, 2, 3]),
gleam@should:equal(_pipe@3, {error, length_mismatch}),
_pipe@4 = gleam@list:strict_zip([5, 6, 7], [1, 2]),
gleam@should:equal(_pipe@4, {error, length_mismatch}).
-spec unzip_test() -> nil.
unzip_test() ->
_pipe = gleam@list:unzip([{1, 2}, {3, 4}]),
gleam@should:equal(_pipe, {[1, 3], [2, 4]}),
_pipe@1 = gleam@list:unzip([]),
gleam@should:equal(_pipe@1, {[], []}).
-spec intersperse_test() -> nil.
intersperse_test() ->
_pipe = gleam@list:intersperse([1, 2, 3], 4),
gleam@should:equal(_pipe, [1, 4, 2, 4, 3]),
_pipe@1 = gleam@list:intersperse([], 2),
gleam@should:equal(_pipe@1, []).
-spec at_test() -> nil.
at_test() ->
_pipe = gleam@list:at([1, 2, 3], 2),
gleam@should:equal(_pipe, {ok, 3}),
_pipe@1 = gleam@list:at([1, 2, 3], 5),
gleam@should:equal(_pipe@1, {error, nil}),
_pipe@2 = gleam@list:at([], 0),
gleam@should:equal(_pipe@2, {error, nil}),
_pipe@3 = gleam@list:at([1, 2, 3, 4, 5, 6], -1),
gleam@should:equal(_pipe@3, {error, nil}).
-spec unique_test() -> nil.
unique_test() ->
_pipe = gleam@list:unique([1, 1, 2, 3, 4, 4, 4, 5, 6]),
gleam@should:equal(_pipe, [1, 2, 3, 4, 5, 6]),
_pipe@1 = gleam@list:unique([7, 1, 45, 6, 2, 47, 2, 7, 5]),
gleam@should:equal(_pipe@1, [7, 1, 45, 6, 2, 47, 5]),
_pipe@2 = gleam@list:unique([3, 4, 5]),
gleam@should:equal(_pipe@2, [3, 4, 5]),
_pipe@3 = gleam@list:unique([]),
gleam@should:equal(_pipe@3, []).
-spec sort_test() -> nil.
sort_test() ->
_pipe = [4, 3, 6, 5, 4],
_pipe@1 = gleam@list:sort(_pipe, fun gleam@int:compare/2),
gleam@should:equal(_pipe@1, [3, 4, 4, 5, 6]),
_pipe@2 = [4, 3, 6, 5, 4, 1],
_pipe@3 = gleam@list:sort(_pipe@2, fun gleam@int:compare/2),
gleam@should:equal(_pipe@3, [1, 3, 4, 4, 5, 6]),
_pipe@4 = [4.1, 3.1, 6.1, 5.1, 4.1],
_pipe@5 = gleam@list:sort(_pipe@4, fun gleam@float:compare/2),
gleam@should:equal(_pipe@5, [3.1, 4.1, 4.1, 5.1, 6.1]),
_pipe@6 = [],
_pipe@7 = gleam@list:sort(_pipe@6, fun gleam@int:compare/2),
gleam@should:equal(_pipe@7, []).
-spec index_map_test() -> nil.
index_map_test() ->
_pipe = gleam@list:index_map([3, 4, 5], fun(I, X) -> {I, X} end),
gleam@should:equal(_pipe, [{0, 3}, {1, 4}, {2, 5}]),
F = fun(I@1, X@1) -> {X@1, I@1} end,
_pipe@1 = gleam@list:index_map([<<"a"/utf8>>, <<"b"/utf8>>], F),
gleam@should:equal(_pipe@1, [{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}]),
F@1 = fun(I@2, X@2) -> {X@2, I@2} end,
_pipe@2 = gleam@list:index_map(
[<<"a"/utf8>>, <<"b"/utf8>>, <<"c"/utf8>>],
F@1
),
gleam@should:equal(
_pipe@2,
[{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}, {<<"c"/utf8>>, 2}]
).
-spec range_test() -> nil.
range_test() ->
_pipe = gleam@list:range(0, 0),
gleam@should:equal(_pipe, []),
_pipe@1 = gleam@list:range(1, 1),
gleam@should:equal(_pipe@1, []),
_pipe@2 = gleam@list:range(-1, -1),
gleam@should:equal(_pipe@2, []),
_pipe@3 = gleam@list:range(0, 1),
gleam@should:equal(_pipe@3, [0]),
_pipe@4 = gleam@list:range(0, 5),
gleam@should:equal(_pipe@4, [0, 1, 2, 3, 4]),
_pipe@5 = gleam@list:range(1, -5),
gleam@should:equal(_pipe@5, [1, 0, -1, -2, -3, -4]).
-spec repeat_test() -> nil.
repeat_test() ->
_pipe = gleam@list:repeat(1, -10),
gleam@should:equal(_pipe, []),
_pipe@1 = gleam@list:repeat(1, 0),
gleam@should:equal(_pipe@1, []),
_pipe@2 = gleam@list:repeat(2, 3),
gleam@should:equal(_pipe@2, [2, 2, 2]),
_pipe@3 = gleam@list:repeat(<<"x"/utf8>>, 5),
gleam@should:equal(
_pipe@3,
[<<"x"/utf8>>, <<"x"/utf8>>, <<"x"/utf8>>, <<"x"/utf8>>, <<"x"/utf8>>]
).
-spec split_test() -> nil.
split_test() ->
_pipe = [],
_pipe@1 = gleam@list:split(_pipe, 0),
gleam@should:equal(_pipe@1, {[], []}),
_pipe@2 = [0, 1, 2, 3, 4],
_pipe@3 = gleam@list:split(_pipe@2, 0),
gleam@should:equal(_pipe@3, {[], [0, 1, 2, 3, 4]}),
_pipe@4 = [0, 1, 2, 3, 4],
_pipe@5 = gleam@list:split(_pipe@4, -2),
gleam@should:equal(_pipe@5, {[], [0, 1, 2, 3, 4]}),
_pipe@6 = [0, 1, 2, 3, 4],
_pipe@7 = gleam@list:split(_pipe@6, 1),
gleam@should:equal(_pipe@7, {[0], [1, 2, 3, 4]}),
_pipe@8 = [0, 1, 2, 3, 4],
_pipe@9 = gleam@list:split(_pipe@8, 3),
gleam@should:equal(_pipe@9, {[0, 1, 2], [3, 4]}),
_pipe@10 = [0, 1, 2, 3, 4],
_pipe@11 = gleam@list:split(_pipe@10, 9),
gleam@should:equal(_pipe@11, {[0, 1, 2, 3, 4], []}).
-spec split_while_test() -> nil.
split_while_test() ->
_pipe = [],
_pipe@1 = gleam@list:split_while(_pipe, fun(X) -> X =< 5 end),
gleam@should:equal(_pipe@1, {[], []}),
_pipe@2 = [1, 2, 3, 4, 5],
_pipe@3 = gleam@list:split_while(_pipe@2, fun(X@1) -> X@1 =< 5 end),
gleam@should:equal(_pipe@3, {[1, 2, 3, 4, 5], []}),
_pipe@4 = [1, 2, 3, 4, 5],
_pipe@5 = gleam@list:split_while(_pipe@4, fun(X@2) -> X@2 =:= 2 end),
gleam@should:equal(_pipe@5, {[], [1, 2, 3, 4, 5]}),
_pipe@6 = [1, 2, 3, 4, 5],
_pipe@7 = gleam@list:split_while(_pipe@6, fun(X@3) -> X@3 =< 3 end),
gleam@should:equal(_pipe@7, {[1, 2, 3], [4, 5]}),
_pipe@8 = [1, 2, 3, 4, 5],
_pipe@9 = gleam@list:split_while(_pipe@8, fun(X@4) -> X@4 =< -3 end),
gleam@should:equal(_pipe@9, {[], [1, 2, 3, 4, 5]}).
-spec key_find_test() -> nil.
key_find_test() ->
Proplist = [{0, <<"1"/utf8>>}, {1, <<"2"/utf8>>}],
_pipe = Proplist,
_pipe@1 = gleam@list:key_find(_pipe, 0),
gleam@should:equal(_pipe@1, {ok, <<"1"/utf8>>}),
_pipe@2 = Proplist,
_pipe@3 = gleam@list:key_find(_pipe@2, 1),
gleam@should:equal(_pipe@3, {ok, <<"2"/utf8>>}),
_pipe@4 = Proplist,
_pipe@5 = gleam@list:key_find(_pipe@4, 2),
gleam@should:equal(_pipe@5, {error, nil}).
-spec pop_test() -> nil.
pop_test() ->
_pipe = gleam@list:pop([1, 2, 3], fun(X) -> X > 2 end),
gleam@should:equal(_pipe, {ok, {3, [1, 2]}}),
_pipe@1 = gleam@list:pop([1, 2, 3], fun(X@1) -> X@1 > 4 end),
gleam@should:equal(_pipe@1, {error, nil}),
_pipe@2 = gleam@list:pop([], fun(_) -> true end),
gleam@should:equal(_pipe@2, {error, nil}).
-spec pop_map_test() -> nil.
pop_map_test() ->
Get = fun(X) -> case X > 0 of
true ->
{ok, X * 2};
false ->
{error, nil}
end end,
_pipe = gleam@list:pop_map([0, 2, 3], Get),
gleam@should:equal(_pipe, {ok, {4, [0, 3]}}),
_pipe@1 = gleam@list:pop_map([0, -1], Get),
gleam@should:equal(_pipe@1, {error, nil}),
_pipe@2 = gleam@list:pop_map([], Get),
gleam@should:equal(_pipe@2, {error, nil}).
-spec key_pop_test() -> nil.
key_pop_test() ->
_pipe = gleam@list:key_pop(
[{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}],
<<"a"/utf8>>
),
gleam@should:equal(_pipe, {ok, {0, [{<<"b"/utf8>>, 1}]}}),
_pipe@1 = gleam@list:key_pop(
[{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}],
<<"b"/utf8>>
),
gleam@should:equal(_pipe@1, {ok, {1, [{<<"a"/utf8>>, 0}]}}),
_pipe@2 = gleam@list:key_pop(
[{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}],
<<"c"/utf8>>
),
gleam@should:equal(_pipe@2, {error, nil}).
-spec key_set_test() -> nil.
key_set_test() ->
_pipe = [{5, 0}, {4, 1}],
_pipe@1 = gleam@list:key_set(_pipe, 4, 100),
gleam@should:equal(_pipe@1, [{5, 0}, {4, 100}]),
_pipe@2 = [{5, 0}, {4, 1}],
_pipe@3 = gleam@list:key_set(_pipe@2, 1, 100),
gleam@should:equal(_pipe@3, [{5, 0}, {4, 1}, {1, 100}]).
-spec partition_test() -> nil.
partition_test() ->
_pipe = [1, 2, 3, 4, 5, 6, 7],
_pipe@1 = gleam@list:partition(_pipe, fun gleam@int:is_odd/1),
gleam@should:equal(_pipe@1, {[1, 3, 5, 7], [2, 4, 6]}).
-spec permutations_test() -> nil.
permutations_test() ->
_pipe = [1, 2],
_pipe@1 = gleam@list:permutations(_pipe),
gleam@should:equal(_pipe@1, [[1, 2], [2, 1]]),
Expected = [[1, 2, 3],
[1, 3, 2],
[2, 1, 3],
[2, 3, 1],
[3, 1, 2],
[3, 2, 1]],
_pipe@2 = [1, 2, 3],
_pipe@3 = gleam@list:permutations(_pipe@2),
gleam@should:equal(_pipe@3, Expected),
_pipe@4 = [<<"a"/utf8>>, <<"b"/utf8>>],
_pipe@5 = gleam@list:permutations(_pipe@4),
gleam@should:equal(
_pipe@5,
[[<<"a"/utf8>>, <<"b"/utf8>>], [<<"b"/utf8>>, <<"a"/utf8>>]]
).
-spec window_test() -> nil.
window_test() ->
_pipe = [1, 2, 3],
_pipe@1 = gleam@list:window(_pipe, 2),
gleam@should:equal(_pipe@1, [[1, 2], [2, 3]]),
_pipe@2 = [1, 2, 3],
_pipe@3 = gleam@list:window(_pipe@2, 3),
gleam@should:equal(_pipe@3, [[1, 2, 3]]),
_pipe@4 = [1, 2, 3],
_pipe@5 = gleam@list:window(_pipe@4, 4),
gleam@should:equal(_pipe@5, []),
_pipe@6 = [1, 2, 3, 4, 5],
_pipe@7 = gleam@list:window(_pipe@6, 3),
gleam@should:equal(_pipe@7, [[1, 2, 3], [2, 3, 4], [3, 4, 5]]).
-spec window_by_2_test() -> nil.
window_by_2_test() ->
_pipe = [1, 2, 3, 4],
_pipe@1 = gleam@list:window_by_2(_pipe),
gleam@should:equal(_pipe@1, [{1, 2}, {2, 3}, {3, 4}]),
_pipe@2 = [1],
_pipe@3 = gleam@list:window_by_2(_pipe@2),
gleam@should:equal(_pipe@3, []).
-spec drop_while_test() -> nil.
drop_while_test() ->
_pipe = [1, 2, 3, 4],
_pipe@1 = gleam@list:drop_while(_pipe, fun(X) -> X < 3 end),
gleam@should:equal(_pipe@1, [3, 4]).
-spec take_while_test() -> nil.
take_while_test() ->
_pipe = [1, 2, 3, 2, 4],
_pipe@1 = gleam@list:take_while(_pipe, fun(X) -> X < 3 end),
gleam@should:equal(_pipe@1, [1, 2]).
-spec chunk_test() -> nil.
chunk_test() ->
_pipe = [1, 2, 3],
_pipe@1 = gleam@list:chunk(_pipe, fun(N) -> N rem 2 end),
gleam@should:equal(_pipe@1, [[1], [2], [3]]),
_pipe@2 = [1, 2, 2, 3, 4, 4, 6, 7, 7],
_pipe@3 = gleam@list:chunk(_pipe@2, fun(N@1) -> N@1 rem 2 end),
gleam@should:equal(_pipe@3, [[1], [2, 2], [3], [4, 4, 6], [7, 7]]).
-spec sized_chunk_test() -> nil.
sized_chunk_test() ->
_pipe = [1, 2, 3, 4, 5, 6],
_pipe@1 = gleam@list:sized_chunk(_pipe, 2),
gleam@should:equal(_pipe@1, [[1, 2], [3, 4], [5, 6]]),
_pipe@2 = [1, 2, 3, 4, 5, 6, 7, 8],
_pipe@3 = gleam@list:sized_chunk(_pipe@2, 3),
gleam@should:equal(_pipe@3, [[1, 2, 3], [4, 5, 6], [7, 8]]).
-spec reduce_test() -> nil.
reduce_test() ->
_pipe = [],
_pipe@1 = gleam@list:reduce(_pipe, fun(X, Y) -> X + Y end),
gleam@should:equal(_pipe@1, {error, nil}),
_pipe@2 = [1, 2, 3, 4, 5],
_pipe@3 = gleam@list:reduce(_pipe@2, fun(X@1, Y@1) -> X@1 + Y@1 end),
gleam@should:equal(_pipe@3, {ok, 15}).
-spec scan_test() -> nil.
scan_test() ->
_pipe = [],
_pipe@1 = gleam@list:scan(_pipe, 0, fun(Acc, I) -> I + Acc end),
gleam@should:equal(_pipe@1, []),
_pipe@2 = [1, 2, 3, 4],
_pipe@3 = gleam@list:scan(
_pipe@2,
0,
fun(Acc@1, I@1) -> (2 * I@1) + Acc@1 end
),
gleam@should:equal(_pipe@3, [2, 6, 12, 20]),
_pipe@4 = [1, 2, 3, 4],
_pipe@5 = gleam@list:scan(
_pipe@4,
[],
fun(Acc@2, I@2) -> case gleam@int:is_even(I@2) of
true ->
[<<"Even"/utf8>> | Acc@2];
false ->
[<<"Odd"/utf8>> | Acc@2]
end end
),
gleam@should:equal(
_pipe@5,
[[<<"Odd"/utf8>>],
[<<"Even"/utf8>>, <<"Odd"/utf8>>],
[<<"Odd"/utf8>>, <<"Even"/utf8>>, <<"Odd"/utf8>>],
[<<"Even"/utf8>>, <<"Odd"/utf8>>, <<"Even"/utf8>>, <<"Odd"/utf8>>]]
).
-spec last_test() -> nil.
last_test() ->
_pipe = gleam@list:last([]),
gleam@should:equal(_pipe, {error, nil}),
_pipe@1 = gleam@list:last([1, 2, 3, 4, 5]),
gleam@should:equal(_pipe@1, {ok, 5}).
-spec combinations_test() -> nil.
combinations_test() ->
_pipe = gleam@list:combinations([1, 2, 3], 0),
gleam@should:equal(_pipe, [[]]),
_pipe@1 = gleam@list:combinations([1, 2, 3], 1),
gleam@should:equal(_pipe@1, [[1], [2], [3]]),
_pipe@2 = gleam@list:combinations([1, 2, 3], 2),
gleam@should:equal(_pipe@2, [[1, 2], [1, 3], [2, 3]]),
_pipe@3 = gleam@list:combinations([1, 2, 3], 3),
gleam@should:equal(_pipe@3, [[1, 2, 3]]),
_pipe@4 = gleam@list:combinations([1, 2, 3], 4),
gleam@should:equal(_pipe@4, []),
_pipe@5 = gleam@list:combinations([1, 2, 3, 4], 3),
gleam@should:equal(_pipe@5, [[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]).
-spec combination_pairs_test() -> nil.
combination_pairs_test() ->
_pipe = gleam@list:combination_pairs([1]),
gleam@should:equal(_pipe, []),
_pipe@1 = gleam@list:combination_pairs([1, 2]),
gleam@should:equal(_pipe@1, [{1, 2}]),
_pipe@2 = gleam@list:combination_pairs([1, 2, 3]),
gleam@should:equal(_pipe@2, [{1, 2}, {1, 3}, {2, 3}]),
_pipe@3 = gleam@list:combination_pairs([1, 2, 3, 4]),
gleam@should:equal(
_pipe@3,
[{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}]
).
-spec interleave_test() -> nil.
interleave_test() ->
_pipe = gleam@list:interleave([[1, 2], [101, 102]]),
gleam@should:equal(_pipe, [1, 101, 2, 102]),
_pipe@1 = gleam@list:interleave([[1, 2], [101, 102], [201, 202]]),
gleam@should:equal(_pipe@1, [1, 101, 201, 2, 102, 202]),
_pipe@2 = gleam@list:interleave([[1, 2, 3], [101, 102]]),
gleam@should:equal(_pipe@2, [1, 101, 2, 102, 3]),
_pipe@3 = gleam@list:interleave([[1, 2], [101, 102, 103]]),
gleam@should:equal(_pipe@3, [1, 101, 2, 102, 103]).
-spec transpose_test() -> nil.
transpose_test() ->
_pipe = gleam@list:transpose([[1, 2, 3], [101, 102, 103]]),
gleam@should:equal(_pipe, [[1, 101], [2, 102], [3, 103]]),
_pipe@1 = gleam@list:transpose(
[[1, 2, 3], [101, 102, 103], [201, 202, 203]]
),
gleam@should:equal(_pipe@1, [[1, 101, 201], [2, 102, 202], [3, 103, 203]]),
_pipe@2 = gleam@list:transpose([[1, 2], [101, 102, 103]]),
gleam@should:equal(_pipe@2, [[1, 101], [2, 102], [103]]),
_pipe@3 = gleam@list:transpose([[1, 2, 3], [101, 102], [201, 202, 203]]),
gleam@should:equal(_pipe@3, [[1, 101, 201], [2, 102, 202], [3, 203]]).