You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having a lot of trouble getting this one to pass. I even tried using the solution code as-is and it still doesn't work. Here's the error:
Emmas-MacBook-Air:learn_to_program emmabeynon$ rspec spec/ch13/orange_tree_spec.rb
OrangeTree
reports height and number of oranges (FAILED - 1)
Failures:
1) OrangeTree reports height and number of oranges
Failure/Error: expect(ot.one_year_passes).to eq 'This year your tree grew to 10.0m tall, and produced 125 oranges.'
expected: "This year your tree grew to 10.0m tall, and produced 125 oranges."
got: "Oh, no! The tree is too old, and has died. :("
(compared using ==)
# /Users/emmabeynon/Dropbox (Personal)/Makers_Academy/Projects/learn_to_program/spec/ch13/orange_tree_spec.rb:16:in `block (2 levels) in <top (required)>'
Finished in 0.01465 seconds (files took 0.19631 seconds to load)
1 example, 1 failure
Failed examples:
rspec /Users/emmabeynon/Dropbox (Personal)/Makers_Academy/Projects/learn_to_program/spec/ch13/orange_tree_spec.rb:12 # OrangeTree reports height and number of oranges
The text was updated successfully, but these errors were encountered:
# note we have added a rounding operation on the height to ensure
# the output is sensible in terms of decimal places
class OrangeTree
def initialize
@height = 0
@orange_count = 0
@alive = true
end
def height
if @alive
@height.round(1)
else
'A dead tree is not very tall. :('
end
end
def count_the_oranges
if @alive
@orange_count
else
'A dead tree has no oranges. :('
end
end
def one_year_passes
if @alive
@height = @height + 0.4
@orange_count = 0 # old oranges fall off
if @height > 10 && rand(2) > 0
# tree dies
@alive = false
'Oh, no! The tree is too old, and has died. :('
elsif @height > 2
# new oranges grow
@orange_count = (@height * 15 - 25).to_i
"This year your tree grew to #{@height.round(1)}m tall," +
" and produced #{@orange_count} oranges."
else
"This year your tree grew to #{@height.round(1)}m tall," +
" but is still too young to bear fruit."
end
else
'A year later, the tree is still dead. :('
end
end
def pick_an_orange
if @alive
if @orange_count > 0
@orange_count = @orange_count - 1
'You pick a juicy, delicious orange!'
else
'You search every branch, but find no oranges.'
end
else
'A dead tree has nothing to pick. :('
end
end
end
Hi guys,
I'm having a lot of trouble getting this one to pass. I even tried using the solution code as-is and it still doesn't work. Here's the error:
The text was updated successfully, but these errors were encountered: