Created
January 19, 2017 01:51
-
-
Save novikserg/f21a67671069ceef5b7b209404dfac1d to your computer and use it in GitHub Desktop.
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
class BuckFizz | |
def print | |
all.each do |buck_fizz| | |
puts buck_fizz | |
end | |
end | |
private | |
def all | |
1.upto(100).map do |number| | |
case | |
when number % 15 == 0 then "BucksFizz" | |
when number % 3 == 0 then "Bucks" | |
when number % 5 == 0 then "Fizz" | |
else number | |
end | |
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
describe BuckFizz do | |
describe "#print" do | |
it "prints FizzBucks correctly" do | |
expect{ BuckFizz.new.print }.to output(start_with( | |
%w(1 2 Bucks 4 Fizz Bucks 7 8 Bucks Fizz 11 Bucks 13 14 BucksFizz 16).join("\n") | |
)).to_stdout | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment