Created
May 11, 2013 04:43
-
-
Save eiel/5558932 to your computer and use it in GitHub Desktop.
#oso2013 fizzbuzz をテストファーストでやっていたので。 その場で Ruby でかいといた。
This file contains hidden or 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
class FizzBuzz | |
def fizzbuzz(n) | |
if n % 3 == 0 and n % 5 == 0 | |
'fizzbuzz' | |
elsif n % 3 == 0 | |
'fizz' | |
elsif n % 5 == 0 | |
'buzz' | |
else | |
n.to_s | |
end | |
end | |
end |
This file contains hidden or 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 'fizzbuzz' | |
describe FizzBuzz do | |
describe '#fizzbuzz(n)' do | |
subject { FizzBuzz.new.fizzbuzz(n) } | |
context 'n が 1 の時' do | |
let(:n) { 1 } | |
it { should eq('1') } | |
end | |
context 'n が 2 の時' do | |
let(:n) { 2 } | |
it { should eq('2') } | |
end | |
context 'n が 3 の時' do | |
let(:n) { 3 } | |
it { should eq('fizz') } | |
end | |
context 'n が 5 の時' do | |
let(:n) { 5 } | |
it { should eq('buzz') } | |
end | |
context 'n が 9 の時' do | |
let(:n) { 9 } | |
it { should eq('fizz') } | |
end | |
context 'n が 15 の時' do | |
let(:n) { 15 } | |
it { should eq('fizzbuzz') } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment