From 02045f5cf036e765020b753394a64df243150c97 Mon Sep 17 00:00:00 2001 From: David Levine Date: Fri, 10 May 2019 14:19:31 -0400 Subject: [PATCH 1/2] Finished challenge --- Gemfile | 3 +-- lib/deaf_grandma.rb | 17 +++++++++++++++-- lib/fizzbuzz.rb | 10 +++++++++- spec/deaf_grandma_spec.rb | 9 ++++++--- spec/fizzbuzz_spec.rb | 11 ++++++----- 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index 2dac66f..d69eabf 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,3 @@ source 'https://rubygems.org' -ruby '2.0.0' -gem 'rspec', '~> 3.0.0.beta2' \ No newline at end of file +gem 'rspec', '~> 3.0.0.beta2' diff --git a/lib/deaf_grandma.rb b/lib/deaf_grandma.rb index 83ad52a..42e997f 100644 --- a/lib/deaf_grandma.rb +++ b/lib/deaf_grandma.rb @@ -5,7 +5,7 @@ class DeafGrandma def initialize - @bye_counter = 0 + @bye_counter = 0 end def run! @@ -19,8 +19,21 @@ def run! def speak(input) + #Check for yell + if input == "BYE" + if @bye_counter < 2 + @bye_counter += 1 + "NOT SINCE 1964!" + else + @bye_counter = 0 + "SEE YOU LATER SONNY!" + end + elsif input == input.upcase + "NOT SINCE 1964!" + else + "SPEAK UP SONNY!" + end - #Implement your code here <<<<<<<<< end diff --git a/lib/fizzbuzz.rb b/lib/fizzbuzz.rb index 86f9def..dae5086 100644 --- a/lib/fizzbuzz.rb +++ b/lib/fizzbuzz.rb @@ -2,7 +2,15 @@ class SuperFizzBuzz def run(input) - #Implement your code here + if input % 15 == 0 + "FizzBuzz" + elsif input % 3 == 0 + "Fizz" + elsif input % 5 == 0 + "Buzz" + else + input + end end diff --git a/spec/deaf_grandma_spec.rb b/spec/deaf_grandma_spec.rb index cf09766..1b57b7b 100644 --- a/spec/deaf_grandma_spec.rb +++ b/spec/deaf_grandma_spec.rb @@ -7,12 +7,15 @@ it "says 'SPEAK UP SONNY!' when we speak regularly" do expect(script.speak("Hi Grandma")).to eq "SPEAK UP SONNY!" end - + it "says 'NOT SINCE 1964!' when we yell" do - #implement your test here + expect(script.speak("HI GRANDMA WHEN DID YOU LAST EAT NOODLES.")).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..d44b7e8 100644 --- a/spec/fizzbuzz_spec.rb +++ b/spec/fizzbuzz_spec.rb @@ -7,16 +7,17 @@ it "returns 'Fizz' when my input is divisible by 3" do expect(script.run(3)).to eq "Fizz" 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 + input_number = 1 + expect(script.run(input_number)).to eq input_number end end From bc0d3785e339e38fbc9c14e20c85aeefecc69703 Mon Sep 17 00:00:00 2001 From: David Levine Date: Fri, 10 May 2019 14:43:09 -0400 Subject: [PATCH 2/2] Fixed revisions --- lib/deaf_grandma.rb | 25 ++++++++++++++++--------- spec/deaf_grandma_spec.rb | 4 ++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/deaf_grandma.rb b/lib/deaf_grandma.rb index 42e997f..adbb0bd 100644 --- a/lib/deaf_grandma.rb +++ b/lib/deaf_grandma.rb @@ -19,17 +19,14 @@ def run! def speak(input) - #Check for yell - if input == "BYE" - if @bye_counter < 2 - @bye_counter += 1 - "NOT SINCE 1964!" + #Check for yel + + if input == input.upcase + if input == "BYE" + bye_function else - @bye_counter = 0 - "SEE YOU LATER SONNY!" + "NOT SINCE 1964!" end - elsif input == input.upcase - "NOT SINCE 1964!" else "SPEAK UP SONNY!" end @@ -39,6 +36,16 @@ def speak(input) private + def bye_function + if @bye_counter < 2 + @bye_counter += 1 + "" + else + @bye_counter = 0 + "SEE YOU LATER SONNY!" + end + end + def print_welcome puts "\nSpeak to your Grandmother: " end diff --git a/spec/deaf_grandma_spec.rb b/spec/deaf_grandma_spec.rb index 1b57b7b..68873a7 100644 --- a/spec/deaf_grandma_spec.rb +++ b/spec/deaf_grandma_spec.rb @@ -14,8 +14,8 @@ end it "EXTRA CREDIT: How would you test yelling BYE?" do - expect(script.speak("BYE")).to eq "NOT SINCE 1964!" - expect(script.speak("BYE")).to eq "NOT SINCE 1964!" + expect(script.speak("BYE")).to eq "" + expect(script.speak("BYE")).to eq "" expect(script.speak("BYE")).to eq "SEE YOU LATER SONNY!" end end