Skip to content

Instantly share code, notes, and snippets.

@huytd
Created July 24, 2016 20:32
Show Gist options
  • Save huytd/db4624346a16c4510598e28602005f5f to your computer and use it in GitHub Desktop.
Save huytd/db4624346a16c4510598e28602005f5f to your computer and use it in GitHub Desktop.
FizzBuzz TDD implementation
module FizzBuzz
extend self
def run(n)
if n % 3 == 0 && n % 5 == 0
return "FizzBuzz"
elsif n % 3 == 0
return "Fizz"
elsif n % 5 == 0
return "Buzz"
else
return n
end
end
end
require 'minitest/autorun'
require './FizzBuzz'
class FizzBuzzTest < Minitest::Test
def test_fizzbuzz_run_return_fizz
expect = "Fizz"
actual = FizzBuzz.run(6)
assert_equal expect, actual
end
def test_fizzbuzz_run_return_buzz
expect = "Buzz"
actual = FizzBuzz.run(10)
assert_equal expect, actual
end
def test_fizzbuzz_run_return_fizzbuzz
expect = "FizzBuzz"
actual = FizzBuzz.run(15)
assert_equal expect, actual
end
def test_fizzbuzz_run_return_n
expect = 8
actual = FizzBuzz.run(8)
assert_equal expect, actual
end
end
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.test_files = FileList["*_test.rb"]
t.verbose = true
end
task :default => :test
@huytd
Copy link
Author

huytd commented Jul 24, 2016

How to run?

Download this gist as Zip file. Extract to anywhere in your computer.

Run test:

rake

# or

rake test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment