Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caffeine Challenge Done #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion caffeine_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ def test_humans_need_coffee
assert matt.needs_coffee?
end

def test_humans_can_get_coffee
katie = Human.new "Katie"
refute katie.has_coffee?
katie.buy Coffee.new("Latte")
assert katie.has_coffee?
end

def test_humans_can_drink_coffee
mallory = Human.new "Mallory"
tsmf = Coffee.new "Triple Shot Mocha Frappuccino"
assert tsmf.full?

mallory.buy tsmf
mallory.drink!
assert_within_epsilon mallory.alertness, 0.33, 0.1
assert_in_epsilon mallory.alertness, 0.33, 0.1
refute tsmf.full?
refute tsmf.empty?
end
Expand Down
18 changes: 16 additions & 2 deletions coffee.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
class Coffee
# Add code here
end
def initialize name
@sips = 3
end

def full?
@sips == 3
end

def empty?
@sips.zero?
end

def take_sip
@sips -= 1
end
end
29 changes: 28 additions & 1 deletion human.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
class Human
# Add code here
def initialize name
@alertness = 0
end

def has_coffee?
if @my_coffee.nil?
false
else
true
end
end

def needs_coffee?
!has_coffee?
end

def alertness
@alertness
end

def buy coffee
@my_coffee = coffee
end

def drink!
@alertness += 0.33
@my_coffee.take_sip
end
end