Skip to content

Conversation

@matthewlee07
Copy link

No description provided.

lib/tree.rb Outdated
end

def add_apples
rand(5..15).times do @apples.push(Apple.new()) end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple ruby style points in here:

  • For blocks that fit on a single line, the preferred syntax is { @apples.push(Apple.new()) }. do-end is preferred for multi-line blocks.
  • It's standard to omit the option () for method calls with no arguments.

end

avg_diameter = # It's up to you to calculate the average diameter for this harvest.
avg_diameter = diameter_sum/basket.size
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is doing integer division. Is that what is intended?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what I meant to do. Am I doing it incorrectly?

Copy link

@sjreich sjreich Oct 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose you a had basket with two apples in it, with diameters of 7 and 8, respectively. What would you expect the average diameter to be? What does this code say the average diameter is?

expect(tree.age).to eq(1);
expect(tree.apples).to eq(0);
expect(tree.alive).to eq(true);
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice test

describe Fruit do
it 'should be a Class' do
expect(described_class.is_a? Class).to eq true
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of test is quite possibly not worth having in a project. If Fruit isn't a class, then all kinds of stuff should be blowing up in your tests.

it 'apple should be a an instance of Apple and subclass of Fruit' do
apple = Apple.new()
expect(apple).to be_a_kind_of(Fruit)
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you find yourself putting 'and' in the description of your test, then you should consider writing two tests instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it to be two tests, one for Apple < Fruit, and one for apple to be_an_instance_of(Apple)

@sjreich
Copy link

sjreich commented Oct 10, 2018

:-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants