Created
June 6, 2011 21:04
-
-
Save bryanhunter/1011103 to your computer and use it in GitHub Desktop.
Erlang FizzBuzz with an eunit test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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