Created
July 24, 2016 20:32
-
-
Save huytd/db4624346a16c4510598e28602005f5f to your computer and use it in GitHub Desktop.
FizzBuzz TDD implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to run?
Download this gist as Zip file. Extract to anywhere in your computer.
Run test: