0
-include_lib("eunit/include/eunit.hrl").
0
--import(hslists, [init/1, intersperse/2, intercalate/2, transpose/1]).
0
+-import(hslists, [init/1, mid/1, random/1, intersperse/2, join/2, intercalate/2,
0
+ transpose/1, product/1, average/1, loop/2, shuffle/1, uniq/1,
0
+ enumerate/1, drop/2]).
0
@@ -10,17 +12,64 @@ init_test_() ->
0
?_assert(init([[1], [a], ["string"]]) == [[1], [a]])
0
+ ?_assert(mid([1, 2]) == []),
0
+ ?_assert(mid([1, 2, 3]) == [2]),
0
+ ?_assert(mid(["hello", "world", a, b, c]) == ["world", a, b])
0
?_assert(intersperse(x, [1]) == [1]),
0
- ?_assert(intersperse(x, [1, 2, 3]) == [1, x, 2, x, 3])
0
+ ?_assert(intersperse(x, [1, 2, 3]) == [1, x, 2, x, 3]),
0
+ ?_assert(intersperse(x, []) == [])
0
-%% TODO: Tests for intercalate.
0
?_assert(transpose([[1]]) == [[1]]),
0
?_assert(transpose([[1,2,3],[4,5,6]]) == [[1,4],[2,5],[3,6]]),
0
?_assert(transpose([[a,b,c],[1,2,3],[4,5,6]]) == [[a,1,4],[b,2,5],[c,3,6]])
0
+ ?_assert(product([0]) == 0),
0
+ ?_assert(product([1, 2, 3]) == 6),
0
+ ?_assert(product([111, 222, 333, 0, 444]) == 0)
0
+ ?_assert(average([0]) == 0),
0
+ ?_assert(average([0,1,2,3,4]) == 2)
0
+ ?_assert(loop(fun(N) -> 96 + N end, 10) == "abcdefghij"),
0
+ ?_assert(loop(fun(X, Idx) -> {X, Idx} end,
0
+ ["hello", "world"]) == [{"hello", 1}, {"world", 2}])
0
+ ?_assert(uniq([x]) == [x]),
0
+ ?_assert(uniq([x, 1, 2, "hello world"]) == [x, 1, 2, "hello world"]),
0
+ ?_assert(uniq([x, 1, 2, "hello world", 2, 1]) ==
0
+ [x, 1, 2, "hello world"])
0
+ ?_assert(enumerate([a, b, c]) == [{a, 1}, {b, 2}, {c, 3}])
0
+ ?_assert(drop([1, 2, 3, 4, 5], 2) == [3, 4, 5]),
0
+ ?_assert(drop([a, b, c], 3) == []),
0
+ ?_assert(drop([a, b, c, d, e], -2) == [a, b, c]),
0
+ ?_assert(drop([a, b, c, d, e], -5) == [])
Comments
No one has commented yet.