Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ PLATFORMS

DEPENDENCIES
rspec (~> 3.0.0.beta2)

RUBY VERSION
ruby 2.0.0p648
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-) all of our stuff is on ruby 2.2, so you'll save yourself some trouble later by switching over now

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Gemfile specified 2.0 so for some reason I switched ruby versions as opposed to updating the Gemfile. In hindsight, that wasn't my most efficient option


BUNDLED WITH
1.16.1
31 changes: 29 additions & 2 deletions lib/deaf_grandma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,29 @@ def run!
loop do
user_input = get_user_input
p speak(user_input)
exit if @bye_counter == 3
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since @bye_counter is compared with 3 in two places, consider a new instance method called exiting?.

end
end


def speak(input)
if input.match(/\p{Lower}/)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\p{Lower}

Wow, I've never seen this before. Standard approaches would be

  input == input.downcase

or

  input.match /\A[a-z]*\z/

(or something like that, I'm not actually testing these things out.)

But if you can point me to do the relevant docs, I'm always happy to pick up another option.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using an option that was gentle on non-alphabet characters but I achieved the same thing by using upcase as well. \p is a regex way of matching Unicode categories but it's not fully supported across languages (https://www.regular-expressions.info/unicode.html#category). It's supported in Ruby since 1.9

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆒

@bye_counter = 0
soft
else
if input == "BYE"
@bye_counter += 1

#Implement your code here <<<<<<<<<

if @bye_counter == 3
see_you_later
else
yell
end
else
@bye_counter = 0
yell
end
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nested three levels deep. It's actually not a terrible use-case for deep nesting, but generally that's something to avoid.

end

private
Expand All @@ -35,6 +50,18 @@ def get_user_input
gets.chomp
end

def soft
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, you want your method names to be verbs - something an instance of the class in question could do.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^Maybe that's not right.

Better: you want your method names to be either verbs (something an instance of the class in question could do) -- or else you want your method names to be nouns - a piece of data an instance of the class can tell you about itself

"SPEAK UP SONNY!"
end

def see_you_later
"SEE YOU LATER SONNY!"
end

def yell
"NOT SINCE 1964!"
end

end

#Uncomment this next line to run your script but BE SURE to comment it, before you try and run your tests.
Expand Down
8 changes: 7 additions & 1 deletion lib/fizzbuzz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ class SuperFizzBuzz

def run(input)

#Implement your code here
output = ""

output << "Fizz" if input % 3 == 0
output << "Buzz" if input % 5 == 0
output = input if output.empty?

output
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty slick.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw Jay use a similar method a few months back for running a FizzBuzz server with Sinatra and I was impressed with his work


end

Expand Down
15 changes: 12 additions & 3 deletions spec/deaf_grandma_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@
end

it "says 'NOT SINCE 1964!' when we yell" do
#implement your test here
expect(script.speak("HELLO!")).to eq "NOT SINCE 1964!"
end

it "EXTRA CREDIT: How would you test yelling BYE?" do
#implement your test here
it "says 'SEE YOU LATER SONNY! when we say 3 consecutive 'BYE's" 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 "SEE YOU LATER SONNY!"
end

it "says 'NOT SINCE 1964! when we say 3 'BYE's nonconsecutively" do
expect(script.speak("BYE")).to eq "NOT SINCE 1964!"
expect(script.speak("BYE")).to eq "NOT SINCE 1964!"
expect(script.speak("I guess I'll stay")).to eq "SPEAK UP SONNY!"
expect(script.speak("BYE")).to eq "NOT SINCE 1964!"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are interesting semi-theoretical questions here about what should be under test in these two examples. If it's really what the third response is, given the setup, then why check the expectation on the first two speak("BYE")'s? If it's all three, then maybe too much is being covered in a single test.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I haven't done much work on testing so I'm still working my way through it. It is aiming to test that saying 'BYE' 3 times non consecutively doesn't change the output. I'll update now

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏁

end
end
6 changes: 3 additions & 3 deletions spec/fizzbuzz_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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