Responses for exercises in Exercism.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

30 lines
1.1 KiB

-module(accumulate_tests).
-include_lib("erl_exercism/include/exercism.hrl").
-include_lib("eunit/include/eunit.hrl").
accumulate_empty_list_test() ->
Fn = fun() -> ok end,
Ls = [],
?assertEqual([], accumulate:accumulate(Fn, Ls)).
accumulate_squares_test() ->
Fn = fun(Number) -> Number * Number end,
Ls = [1, 2, 3],
?assertEqual([1, 4, 9], accumulate:accumulate(Fn, Ls)).
accumulate_upcases_test() ->
Fn = fun(Word) -> string:to_upper(Word) end,
Ls = string:tokens("hello world", " "),
?assertEqual(["HELLO", "WORLD"], accumulate:accumulate(Fn, Ls)).
accumulate_reversed_strings_test() ->
Fn = fun(Word) -> lists:reverse(Word) end,
Ls = string:tokens("the quick brown fox etc", " "),
?assertEqual(["eht", "kciuq", "nworb", "xof", "cte"], accumulate:accumulate(Fn, Ls)).
accumulate_recursively_test() ->
Chars = string:tokens("a b c", " "),
Nums = string:tokens("1 2 3", " "),
Fn = fun(Char) -> [Char ++ Num || Num <- Nums] end,
?assertEqual([["a1", "a2", "a3"], ["b1", "b2", "b3"], ["c1", "c2", "c3"]], accumulate:accumulate(Fn, Chars)).