Last active
November 28, 2023 20:22
-
-
Save PragTob/8bd3d8aad74c702ce514b8df76ae6b33 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
module FizzBuzz | |
module_function | |
def fizz_buzz(number) | |
if (number % 3 == 0) && (number % 5 == 0) | |
"FizzBuzz" | |
elsif number % 3 == 0 | |
"Fizz" | |
elsif number % 5 == 0 | |
"Buzz" | |
else | |
number | |
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
RSpec.describe FizzBuzz do | |
describe ".fizz_buzz" do | |
expected = { | |
1 => 1, | |
2 => 2, | |
3 => "Fizz", | |
4 => 4, | |
5 => "Buzz", | |
6 => "Fizz", | |
11 => 11, | |
15 => "FizzBuzz", | |
20 => "Buzz", | |
60 => "FizzBuzz", | |
98 => 98, | |
99 => "Fizz", | |
100 => "Buzz" | |
} | |
expected.each do |input, output| | |
it "for #{input} expect #{output}" do | |
expect(FizzBuzz.fizz_buzz(input)).to eq output | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment