From d12aa976f334581b8d37e03627038b1d768c55ae Mon Sep 17 00:00:00 2001 From: Eric Noble Date: Mon, 19 Mar 2018 08:24:55 -0400 Subject: [PATCH 1/2] Working Super Fizz Buzz and Deaf Grandma drills and rspec tests. --- Gemfile | 2 +- Gemfile.lock | 6 ++++++ lib/deaf_grandma.rb | 27 ++++++++++++++++++++++----- lib/fizzbuzz.rb | 22 +++++++++++++++++++--- spec/deaf_grandma_spec.rb | 6 ++++-- spec/fizzbuzz_spec.rb | 6 +++--- 6 files changed, 55 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index 2dac66f..a063ecb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ source 'https://rubygems.org' -ruby '2.0.0' +ruby '2.2.9' gem 'rspec', '~> 3.0.0.beta2' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index dfd2ba5..4477308 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -20,3 +20,9 @@ PLATFORMS DEPENDENCIES rspec (~> 3.0.0.beta2) + +RUBY VERSION + ruby 2.2.9p480 + +BUNDLED WITH + 1.16.1 diff --git a/lib/deaf_grandma.rb b/lib/deaf_grandma.rb index 83ad52a..7301e7e 100644 --- a/lib/deaf_grandma.rb +++ b/lib/deaf_grandma.rb @@ -14,14 +14,31 @@ def run! loop do user_input = get_user_input p speak(user_input) + if @bye_counter > 2 + exit + end end end - def speak(input) - - #Implement your code here <<<<<<<<< - + if input == input.upcase + #YELL + if input == "BYE" + @bye_counter = @bye_counter + 1 + else + @bye_counter = 0 + end + + if @bye_counter == 3 + "SEE YOU LATER SONNY!" + else + "NOT SINCE 1964!" + end + else + #speak + @bye_counter = 0 + "SPEAK UP SONNY!" + end end private @@ -38,4 +55,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! \ No newline at end of file diff --git a/lib/fizzbuzz.rb b/lib/fizzbuzz.rb index 86f9def..4b81b1c 100644 --- a/lib/fizzbuzz.rb +++ b/lib/fizzbuzz.rb @@ -1,13 +1,29 @@ class SuperFizzBuzz def run(input) + output = "" - #Implement your code here + divBy3 = input % 3 == 0 + divBy5 = input % 5 == 0 - end + if divBy3 + output << "Fizz" + end + + if divBy5 + output << "Buzz" + end + if divBy3 || divBy5 + return output + else + return input + end + end end #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? -# + +# puts SuperFizzBuzz.new.run + #HINT: it's an instance method. diff --git a/spec/deaf_grandma_spec.rb b/spec/deaf_grandma_spec.rb index cf09766..d20d2df 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("DO YOU LIKE KITTENS?")).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 diff --git a/spec/fizzbuzz_spec.rb b/spec/fizzbuzz_spec.rb index cfda46b..7ac07d1 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(4)).to eq 4 end end From a07ce82248cc880c9329387a346f90a694050e23 Mon Sep 17 00:00:00 2001 From: Eric Noble Date: Mon, 19 Mar 2018 13:06:57 -0400 Subject: [PATCH 2/2] Fixed some issues brought up by @jaybobo in the PR. --- lib/deaf_grandma.rb | 2 +- lib/fizzbuzz.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/deaf_grandma.rb b/lib/deaf_grandma.rb index 7301e7e..639fae3 100644 --- a/lib/deaf_grandma.rb +++ b/lib/deaf_grandma.rb @@ -24,7 +24,7 @@ def speak(input) if input == input.upcase #YELL if input == "BYE" - @bye_counter = @bye_counter + 1 + @bye_counter += 1 else @bye_counter = 0 end diff --git a/lib/fizzbuzz.rb b/lib/fizzbuzz.rb index 4b81b1c..612eadb 100644 --- a/lib/fizzbuzz.rb +++ b/lib/fizzbuzz.rb @@ -6,18 +6,18 @@ def run(input) divBy3 = input % 3 == 0 divBy5 = input % 5 == 0 - if divBy3 + if div_by_3 output << "Fizz" end - if divBy5 + if div_by_5 output << "Buzz" end - if divBy3 || divBy5 - return output + if div_by_3 || div_by_5 + output else - return input + input end end end