From 13c673569377fc063e17207fe68d971842e5f5cd Mon Sep 17 00:00:00 2001 From: Nick Caley Date: Thu, 1 Mar 2018 15:24:35 -0500 Subject: [PATCH 1/2] Completed FizzBuzz with tests --- lib/fizzbuzz.rb | 12 +++++++++--- spec/fizzbuzz_spec.rb | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/fizzbuzz.rb b/lib/fizzbuzz.rb index 86f9def..0addfe6 100644 --- a/lib/fizzbuzz.rb +++ b/lib/fizzbuzz.rb @@ -1,9 +1,15 @@ class SuperFizzBuzz def run(input) - - #Implement your code here - + if input % 3 == 0 && input % 5 == 0 + "FizzBuzz" + elsif input % 3 == 0 + "Fizz" + elsif input % 5 == 0 + "Buzz" + else + input + end end end diff --git a/spec/fizzbuzz_spec.rb b/spec/fizzbuzz_spec.rb index cfda46b..a78aa0a 100644 --- a/spec/fizzbuzz_spec.rb +++ b/spec/fizzbuzz_spec.rb @@ -9,14 +9,14 @@ end it "returns 'Buzz' when my input is divisible by 5" do - #implement your test here + expect(script.run(5)).to eq "Buzz" end it "returns 'FizzBuzz' when input is divisible by 3 & 5" do - #implement your test here + expect(script.run(15)).to eq "FizzBuzz" end it "returns the input number when input isn't divisible by 3, 5, or both" do - #implement your test here + expect(script.run(7)).to eq 7 end end From b01d643b34801e85d617d57a960a2d0088879e6f Mon Sep 17 00:00:00 2001 From: Nick Caley Date: Thu, 1 Mar 2018 15:57:04 -0500 Subject: [PATCH 2/2] Completed deaf grandma with tests --- lib/deaf_grandma.rb | 23 ++++++++++++++++++----- lib/fizzbuzz.rb | 1 + spec/deaf_grandma_spec.rb | 6 ++++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/deaf_grandma.rb b/lib/deaf_grandma.rb index 83ad52a..ec06fa4 100644 --- a/lib/deaf_grandma.rb +++ b/lib/deaf_grandma.rb @@ -17,11 +17,24 @@ def run! end end - def speak(input) - - #Implement your code here <<<<<<<<< - + if input == input.upcase + + if input == "BYE" + @bye_counter += 1 + else + @bye_counter = 0 + end + + if @bye_counter == 3 + "SEE YOU LATER SONNY!" + else + "NOT SINCE 1964!" + end + + else + "SPEAK UP SONNY!" + end end private @@ -38,4 +51,4 @@ def get_user_input end #Uncomment this next line to run your script but BE SURE to comment it, before you try and run your tests. -#DeafGrandma.new.run! +# DeafGrandma.new.run! diff --git a/lib/fizzbuzz.rb b/lib/fizzbuzz.rb index 0addfe6..3497508 100644 --- a/lib/fizzbuzz.rb +++ b/lib/fizzbuzz.rb @@ -17,3 +17,4 @@ def run(input) #You don't necessarily need to execute this script to complete this challenge, but how would you "run" this method (pun intended) so that it printed a value to the terminal? # #HINT: it's an instance method. +# SuperFizzBuzz.new.run(15) diff --git a/spec/deaf_grandma_spec.rb b/spec/deaf_grandma_spec.rb index cf09766..7dd34c0 100644 --- a/spec/deaf_grandma_spec.rb +++ b/spec/deaf_grandma_spec.rb @@ -9,10 +9,12 @@ end it "says 'NOT SINCE 1964!' when we yell" do - #implement your test here + expect(script.speak("HI GRANDMA")).to eq "NOT SINCE 1964!" end it "EXTRA CREDIT: How would you test yelling BYE?" do - #implement your test here + expect(script.speak("BYE")).to eq "NOT SINCE 1964!" + expect(script.speak("BYE")).to eq "NOT SINCE 1964!" + expect(script.speak("BYE")).to eq "SEE YOU LATER SONNY!" end end