Skip to content

Commit

Permalink
Merge pull request #93 from NobbZ/master
Browse files Browse the repository at this point in the history
Applied x-common/sum-of-multiples.json
  • Loading branch information
NobbZ committed Mar 25, 2016
2 parents 22f9ff6 + c3c2aed commit acd74e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
6 changes: 1 addition & 5 deletions exercises/sum-of-multiples/example.erl
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
-module(sum_of_multiples).

-export([sumOfMultiplesDefault/1, sumOfMultiples/2]).
-export([sumOfMultiples/2]).

-import(lists, [foldl/3, seq/2, any/2]).

-spec sumOfMultiplesDefault(pos_integer()) -> non_neg_integer().
sumOfMultiplesDefault(A) ->
sumOfMultiples([3,5], A).

-spec sumOfMultiples([pos_integer()], pos_integer()) -> non_neg_integer().
sumOfMultiples(Multiples, A) ->
foldl(fun(X, Sum) -> case multiple(Multiples, X) of
Expand Down
38 changes: 25 additions & 13 deletions exercises/sum-of-multiples/sum_of_multiples_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,35 @@

-include_lib("eunit/include/eunit.hrl").

sum_to_1_test() ->
?assertEqual(0, sumOfMultiplesDefault(1)).
sum_with_3_5_to_1_test() ->
?assertEqual(0, sumOfMultiples([3, 5], 1)).

sum_to_3_test() ->
?assertEqual(3, sumOfMultiplesDefault(4)).
sum_with_3_5_to_3_test() ->
?assertEqual(3, sumOfMultiples([3, 5], 4)).

sum_to_10_test() ->
?assertEqual(23, sumOfMultiplesDefault(10)).

sum_to_100_test() ->
?assertEqual(2318, sumOfMultiplesDefault(100)).
sum_with_3_5_to_10_test() ->
?assertEqual(23, sumOfMultiples([3, 5], 10)).

sum_to_1000_test() ->
?assertEqual(233168, sumOfMultiplesDefault(1000)).
sum_with_3_5_to_100_test() ->
?assertEqual(2318, sumOfMultiples([3, 5], 100)).

sum_of_configurable_to_20_test() ->
sum_with_3_5_to_1000_test() ->
?assertEqual(233168, sumOfMultiples([3, 5], 1000)).

sum_with_7_13_17_to_20_test() ->
?assertEqual(51, sumOfMultiples([7,13,17], 20)).

sum_of_configurable_to_10000_test() ->
sum_with_4_6_to_15_test() ->
?assertEqual(30, sumOfMultiples([4,6], 15)).

sum_with_5_6_8_to_150_test() ->
?assertEqual(4419, sumOfMultiples([5, 6, 8], 150)).

sum_with_43_47_to_10000_test() ->
?assertEqual(2203160, sumOfMultiples([43,47], 10000)).

sum_with_1_to_100_test() ->
?assertEqual(4950, sumOfMultiples([1], 100)).

sum_with_empty_to_10000_test() ->
?assertEqual(0, sumOfMultiples([], 10000)).

0 comments on commit acd74e0

Please sign in to comment.