Skip to content

Instantly share code, notes, and snippets.

@allthetime
Forked from kvirani/README.md
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allthetime/17549c036d5fb4b7360e to your computer and use it in GitHub Desktop.
Save allthetime/17549c036d5fb4b7360e to your computer and use it in GitHub Desktop.

The Yuppie Vancouverite

The Yuppie Vancouverite needs to rent an apartment downtown!

Here we have a rent? method that helps them decide if they are going to an apartment based on some information about it. It's passed 3 key pieces of information that are used to determine this:

  1. Is the apartment furnished? Since this is a yes/no thing, it's a boolean (true/false)
  2. Is the apartment baller? Since this is a yes/no thing, it's a boolean (true/false)
  3. The monthly rent for the apartment. This is expected to be an integer (Fixnum)

Firstly, They only want to rent it if it's baller (whatever that means!). Furthermore, they only want it if it's furnished but are willing to make an exception if it's rent is cheaper than 2100 per month (Ugh...Downtown Vancouver prices!)

Steps:

  1. Write test code by outputting the return values for possible permutations of this method (at the bottom of this file)
  2. Based on the actual behavior (vs desired behavior), can you determine what the (buggy) logic is ACTUALLY checking?
  3. Having identified what is actually occurring vs what should occur, fix the bug such that the logic works as desired.
  4. Compare and discuss your solution (fix) with your peers. This includes your test cases. Did you cover all the possibilities? Did you have the same solution? Whose is better and why?
  5. How can you reduce the body/contents of this method down to one line? Effectively making it much simpler and cleaner. Do it!
def rent?(furnished, rent, baller)
baller && (furnished || rent < 2100) ? puts "I want the house" : false
end
#TESTS
#CONDITIONS: must be baller and either furnished or rent cheaper than 2100
#isn't baller, should return false
puts rent?(false,2000,false)
#is baller, but has no furniture and is expensive (should false)
puts rent?(false,30000,true)
#is baller, has furniture (should true)
puts rent?(true,3000,true)
#is baller, has no furniture, but is cheap (should true)
puts rent?(false,100,true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment