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

TreeTDD exercise dhatten #58

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

davidhatten
Copy link

No description provided.

end

def age!
@age+=1
@alive = false unless @age < 9
Copy link

Choose a reason for hiding this comment

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

@alive = false if @age > 9 is probably a bit clearer. if is generally clearer than unless, except when it isn't.

Copy link
Member

Choose a reason for hiding this comment

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

* if is clearer than unless, unless it isn't. 😁

@age+=1
@alive = false unless @age < 9
@height+=rand(20)
self.add_apples
Copy link

Choose a reason for hiding this comment

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

The self shouldn't be necessary here - self is the default receiver for every command in ruby.

Copy link
Member

Choose a reason for hiding this comment

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

Joe is right. The only time self. is needed is calling a setter method, like self.foo = "bar". Ruby will assume foo = "bar" is local variable assignment instead of calling the foo= method.


def initialize
@height = 0
@age = 0
@apples = 0
Copy link

Choose a reason for hiding this comment

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

This makes it sound like @apples will be an array of apples. I'd say either switch the value or change the name to make clear that it's a count.

Copy link
Author

Choose a reason for hiding this comment

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

Rupert ended up doing the array design, it works out much better overall

diameter_sum = 0

basket.each do |apple|
diameter_sum += apple.diameter
end

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

Choose a reason for hiding this comment

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

This seems to assume that users of the Apple class will always initialize it with a floating point diameter, as you did above.

it 'should be a Class' do
expect(described_class.is_a? 'Class').to be_true
describe AppleTree do
context 'when AppleTree exists' do
Copy link

Choose a reason for hiding this comment

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

I'm not sure adding this context helps to clarify anything.

subject(:tree) { AppleTree.new }
it 'should be a Class' do
expect(described_class.is_a? Class).to be true
end
Copy link

Choose a reason for hiding this comment

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

I know this is provided for you, but I really dislike this kind of test 😄 .


it 'should have no apples' do
expect(tree.any_apples?).to eq false
end
Copy link

@sjreich sjreich Jan 19, 2018

Choose a reason for hiding this comment

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

For these two tests: if it's part of the required setup for these guys that this be a brand-new tree, then the setup should go with the test. The options are either to do the necessary setup inside the it block itself, or else to use a context/describe block.

(and some other tests below too)


it 'should not be able to have an apple picked' do
expect{tree.pick_an_apple!}.to raise_error NoApplesError
end
Copy link

Choose a reason for hiding this comment

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

nice

tree.age!
}
expect(tree.dead?).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.

Not that you need to add it, but think about testing the flip side here too: this only shows that tens years of aging kills the tree - but maybe 9 or 8 years would also kill it.


it 'should have a diameter' do
expect(apple.diameter).to eq 5
end
Copy link

Choose a reason for hiding this comment

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

Nice tests overall.

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.

3 participants