defmodule FizzBuzz do
def say(number) do
say(number, rem(number, 3), rem(number, 5))
end
defp say(_, 0, 0) do
"FizzBuzz"
end
defp say(_, 0, _) do
"Fizz"
end
defp say(_, _, 0) do
"Buzz"
end
defp say(number, _, _) do
Integer.to_string(number)
end
end
for n <- 1..20, do: IO.puts FizzBuzz.say(n)
ExUnit.start()
defmodule FizzBuzzTest do
use ExUnit.Case
test "1 is 1" do
assert "1" == FizzBuzz.say(1)
end
test "3 is Fizz" do
assert "Fizz" == FizzBuzz.say(3)
end
test "5 is Buzz" do
assert "Buzz" == FizzBuzz.say(5)
end
test "15 is FizzBuzz" do
assert "FizzBuzz" == FizzBuzz.say(15)
end
end