Skip to content

Instantly share code, notes, and snippets.

@McTano
Forked from davidvandusen/renter.rb
Last active May 24, 2016 21:38
Show Gist options
  • Save McTano/039681e2c024aaa8a0651f2da4d47f23 to your computer and use it in GitHub Desktop.
Save McTano/039681e2c024aaa8a0651f2da4d47f23 to your computer and use it in GitHub Desktop.
# must be baller and either furnished or rent cheaper than 2100
def rent?(furnished, rent, baller)
baller && (furnished || rent < 2100)
end
###
# Add your "test" ("driver") code below in order to "test drive" (run) your method above...
# The test code will call the method with different permutations of options and output the result each time.
# This way, you will be able to run the renter.rb file from the CLI and look at the output of your "tests" to validate if the method works.
# Without the test code, it will be hard for you to know if this method is working as it should or not.
###
def test_rent
puts "furnished, $1, baller: expect true"
puts rent?(true, 1, true)
puts "furnished, $1, not baller: expect false"
puts rent?(true, 1, false)
puts "furnished, $2400, baller: expect true"
puts rent?(true, 2400, true)
puts "unfurnished, $2100, baller: expect false"
puts rent?(false, 2100, true)
puts "unfurnished, $2099, baller: expect true"
puts rent?(false, 2099, true)
puts "unfurnished, $1, not baller: expect false"
puts rent?(false, 1, false)
end
test_rent
# method was evaluating true whenever the rent is under 2100, because the condition
# is being evaluated as (EITHER (baller AND furnished) OR cheap) instead of
# (baller AND EITHER (furnished OR cheap))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment