Skip to content

Instantly share code, notes, and snippets.

@bryanhunter
Created June 6, 2011 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanhunter/1011103 to your computer and use it in GitHub Desktop.
Save bryanhunter/1011103 to your computer and use it in GitHub Desktop.
Erlang FizzBuzz with an eunit test
-module(fizzbuzz).
-export([playto/1]).
-include_lib("eunit/include/eunit.hrl").
playto(Upper) ->
[case
{X rem 3, X rem 5} of
{0, 0} -> fizzBuzz;
{0, _} -> fizz;
{_, 0} -> buzz;
{_, _} -> X
end
|| X <- lists:seq(1,Upper)].
% Note: The following is a magic test-generating function because it has an '_'
% appended to the end of the function name, and a '_' prepended to the assert macro
fizzbuzz_can_playto_7_test_() ->
[
?_assert([1,2,fizz,4,buzz,fizz,7] == playto(7))
].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment