Skip to content

Instantly share code, notes, and snippets.

@kaiguogit
Forked from davidvandusen/renter.rb
Last active July 20, 2016 18:29
Show Gist options
  • Save kaiguogit/94de5d148e0a255aaf075d6a7df00783 to your computer and use it in GitHub Desktop.
Save kaiguogit/94de5d148e0a255aaf075d6a7df00783 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(actual, expected)
if actual != expected
print "Test result is #{actual}, expecting #{expected} "
else
print "Test passed "
end
end
[true,false].each do |furnished|
(0..1).each do |rent|
[true,false].each do |baller|
test(rent?(furnished, (2000+rent*200), baller),baller && (furnished || (2000+rent*200) < 2100))
puts "input is furnished #{furnished}, rent #{2000+rent*200}, baller #{baller}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment