From 1875ddf4b167ee703a2fef195dee12cee50069be Mon Sep 17 00:00:00 2001 From: Sam Bostock Date: Sun, 9 Apr 2017 19:58:58 -0400 Subject: [PATCH] Add Fizz Buzz implementation --- README.md | 2 +- lib/fizz_badd.ex | 13 ------------- lib/fizz_badd/fizz_buzz.ex | 28 ++++++++++++++++++++++++++++ test/fizz_badd/fizz_buzz_test.exs | 7 +++++++ test/fizz_badd_test.exs | 4 ---- 5 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 lib/fizz_badd/fizz_buzz.ex create mode 100644 test/fizz_badd/fizz_buzz_test.exs diff --git a/README.md b/README.md index 8513650..571680d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # FizzBadd -**TODO: Add description** +A shitty Fizz Buzz implementation generator. ## Installation diff --git a/lib/fizz_badd.ex b/lib/fizz_badd.ex index 59479e3..3de7b1b 100644 --- a/lib/fizz_badd.ex +++ b/lib/fizz_badd.ex @@ -2,17 +2,4 @@ defmodule FizzBadd do @moduledoc """ Documentation for FizzBadd. """ - - @doc """ - Hello world. - - ## Examples - - iex> FizzBadd.hello - :world - - """ - def hello do - :world - end end diff --git a/lib/fizz_badd/fizz_buzz.ex b/lib/fizz_badd/fizz_buzz.ex new file mode 100644 index 0000000..6d40dba --- /dev/null +++ b/lib/fizz_badd/fizz_buzz.ex @@ -0,0 +1,28 @@ +defmodule FizzBadd.FizzBuzz do + @moduledoc """ + Fizz Buzz implementation for internal use. + """ + + @doc """ + Produce the n-th value in the Fizz Buzz sequence. + + ## Examples + + iex> FizzBadd.FizzBuzz.fizz_buzz(1) + "1" + + iex> FizzBadd.FizzBuzz.fizz_buzz(3) + "Fizz" + + iex> FizzBadd.FizzBuzz.fizz_buzz(5) + "Buzz" + + iex> FizzBadd.FizzBuzz.fizz_buzz(15) + "Fizz Buzz" + + """ + def fizz_buzz(n) when rem(n, 15) == 0, do: "Fizz Buzz" + def fizz_buzz(n) when rem(n, 5) == 0, do: "Buzz" + def fizz_buzz(n) when rem(n, 3) == 0, do: "Fizz" + def fizz_buzz(n), do: Integer.to_string(n) +end diff --git a/test/fizz_badd/fizz_buzz_test.exs b/test/fizz_badd/fizz_buzz_test.exs new file mode 100644 index 0000000..6875d30 --- /dev/null +++ b/test/fizz_badd/fizz_buzz_test.exs @@ -0,0 +1,7 @@ +defmodule FizzBaddTest.FizzBuzzTest do + use ExUnit.Case + + alias FizzBadd.FizzBuzz, as: FizzBuzz + + doctest FizzBuzz +end diff --git a/test/fizz_badd_test.exs b/test/fizz_badd_test.exs index 5288801..cbf72a4 100644 --- a/test/fizz_badd_test.exs +++ b/test/fizz_badd_test.exs @@ -1,8 +1,4 @@ defmodule FizzBaddTest do use ExUnit.Case doctest FizzBadd - - test "the truth" do - assert 1 + 1 == 2 - end end