defmodule FizzBuzz do
def say(number) do
cond do
rem(number, 15) == 0 -> "FizzBuzz"
rem(number, 3) == 0 -> "Fizz"
rem(number, 5) == 0 -> "Buzz"
number -> Integer.to_string(number)
end
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