Skip to content

Instantly share code, notes, and snippets.

@alexmoore
Last active Dec 21, 2015
Embed
What would you like to do?
-module(fizzbuzz).
-export([print_fizz_buzz/0,fizzbuzz/1]).
print_fizz_buzz() ->
Each = fun(I) ->
print_fizz_buzz(fizzbuzz(I)) end,
lists:foreach(Each, lists:seq(1,100)).
print_fizz_buzz(I) when is_integer(I) -> io:fwrite("~p~n", [I]);
print_fizz_buzz(I) -> io:fwrite("~s~n", [I]).
fizzbuzz(I) when I rem 3 == 0 andalso I rem 5 == 0 -> "FizzBuzz";
fizzbuzz(I) when I rem 3 == 0 -> "Fizz";
fizzbuzz(I) when I rem 5 == 0 -> "Buzz";
fizzbuzz(I) -> I.
-module(fizzbuzz_tests).
-include_lib("eunit/include/eunit.hrl").
one_test() ->
1 = fizzbuzz:fizzbuzz(1).
two_test() ->
2 = fizzbuzz:fizzbuzz(2).
three_test() ->
"Fizz" = fizzbuzz:fizzbuzz(3).
four_test() ->
4 = fizzbuzz:fizzbuzz(4).
five_test() ->
"Buzz" = fizzbuzz:fizzbuzz(5).
six_test() ->
"Fizz" = fizzbuzz:fizzbuzz(6).
seven_test() ->
7 = fizzbuzz:fizzbuzz(7).
eight_test() ->
8 = fizzbuzz:fizzbuzz(8).
nine_test() ->
"Fizz" = fizzbuzz:fizzbuzz(9).
ten_test() ->
"Buzz" = fizzbuzz:fizzbuzz(10).
fifteen_test() ->
"FizzBuzz" = fizzbuzz:fizzbuzz(15).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment