Skip to content

Commit f7391b4

Browse files
committed
Add tests for Stream.concat/1,2 and Enum.concat/1,2
1 parent d78014e commit f7391b4

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lib/elixir/test/elixir/enum_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,23 @@ defmodule EnumTest.List do
5656

5757
test :concat_1 do
5858
assert Enum.concat([[1, [2], 3], [4], [5, 6]]) == [1, [2], 3, 4, 5, 6]
59+
assert Enum.concat(1..3, []) == [1,2,3]
60+
61+
assert Enum.concat([[], []]) == []
62+
assert Enum.concat([[]]) == []
63+
assert Enum.concat([]) == []
64+
65+
assert Enum.concat([1..5, fn acc, _ -> acc end, [1]]) == [1,2,3,4,5,1]
5966
end
6067

6168
test :concat_2 do
69+
assert Enum.concat([], [1]) == [1]
6270
assert Enum.concat([1, [2], 3], [4, 5]) == [1, [2], 3, 4, 5]
71+
assert Enum.concat(1..3, []) == [1,2,3]
72+
73+
assert Enum.concat([], []) == []
74+
75+
assert Enum.concat(fn acc, _ -> acc end, [1]) == [1]
6376
end
6477

6578
test :fetch! do

lib/elixir/test/elixir/stream_test.exs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,37 @@ defmodule StreamTest do
2525
assert Enum.to_list(stream) == [3,5,7]
2626
end
2727

28+
test :concat_1 do
29+
stream = Stream.concat([1..3, [], [4, 5, 6], [], 7..9])
30+
assert is_function(stream)
31+
32+
assert Enum.to_list(stream) == [1,2,3,4,5,6,7,8,9]
33+
assert Enum.take(stream, 5) == [1,2,3,4,5]
34+
35+
stream = Stream.concat([1..3, [4, 5, 6], Stream.cycle(7..100)])
36+
assert is_function(stream)
37+
38+
assert Enum.take(stream, 13) == [1,2,3,4,5,6,7,8,9,10,11,12,13]
39+
end
40+
41+
test :concat_2 do
42+
stream = Stream.concat(1..3, 4..6)
43+
assert is_function(stream)
44+
assert Stream.cycle(stream) |> Enum.take(16) == [1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4]
45+
46+
stream = Stream.concat(1..3, [])
47+
assert is_function(stream)
48+
assert Stream.cycle(stream) |> Enum.take(5) == [1,2,3,1,2]
49+
50+
stream = Stream.concat(1..6, Stream.cycle(7..9))
51+
assert is_function(stream)
52+
assert Stream.drop(stream, 3) |> Enum.take(13) == [4,5,6,7,8,9,7,8,9,7,8,9,7]
53+
54+
stream = Stream.concat(Stream.cycle(1..3), Stream.cycle(4..6))
55+
assert is_function(stream)
56+
assert Enum.take(stream, 13) == [1,2,3,1,2,3,1,2,3,1,2,3,1]
57+
end
58+
2859
test :cycle do
2960
stream = Stream.cycle([1,2,3])
3061
assert is_function(stream)

0 commit comments

Comments
 (0)