Skip to content

Commit

Permalink
Add test for flatten1
Browse files Browse the repository at this point in the history
  • Loading branch information
seriyps committed Dec 7, 2023
1 parent ad72ede commit e190e7c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: rebar3 proper -c

- name: Coverage
run: rebar3 cover --verbose --min_coverage 80
run: rebar3 cover --verbose --min_coverage 85

- name: Run Xref
run: rebar3 xref
Expand Down
3 changes: 3 additions & 0 deletions src/iterator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ yield_flatmap({Fun, [Item | Tail], InnerIter}) ->
{Item, {Fun, Tail, InnerIter}}.

%% @doc Converts iterator that yields lists to flat list (non-recursive)
%%
%% Do not confuse with `append/1'. This function takes SINGLE iterator that yields
%% lists and returns list elements one-by-one.
-spec flatten1(iterator([Type])) -> iterator(Type).
flatten1(InnerIterator) ->
flatmap(fun(V) -> V end, InnerIterator).
Expand Down
16 changes: 16 additions & 0 deletions test/prop_vs_lists.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
prop_map/0,
prop_mapfoldl/0,
prop_flatmap/0,
prop_flatten1/0,
prop_filter/0,
prop_filtermap/0,
prop_dropwhile/0,
Expand Down Expand Up @@ -113,6 +114,21 @@ prop_flatmap() ->
end
).

prop_flatten1() ->
Gen = proper_types:list(proper_types:list()),
?FORALL(
ListOfLists,
Gen,
begin
Iterator = iterator:from_list(ListOfLists),
?assertEqual(
lists:append(ListOfLists),
iterator:to_list(iterator:flatten1(Iterator))
),
true
end
).

prop_filter() ->
Gen = proper_types:list(proper_types:integer()),
?FORALL(
Expand Down

0 comments on commit e190e7c

Please sign in to comment.