Skip to content

Instantly share code, notes, and snippets.

@huytd huytd/FizzBuzz.rb
Created Jul 24, 2016

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.