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

Eric DeShetler #10

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Eric DeShetler #10

wants to merge 9 commits into from

Conversation

ejdesh
Copy link

@ejdesh ejdesh commented Sep 16, 2024

No description provided.


def initialize(item_info)
@name = item_info[:name]
@price = item_info[:price]
Copy link
Contributor

Choose a reason for hiding this comment

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

The interaction pattern asks to clean the string (remove the $) and convert to a float

def vendors_that_sell(item)
list = []
@vendors.find_all do |vendor|
list << vendor if vendor.check_stock(item).to_i > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice logic happening in here

# find items that are sold by more than one vendor
temp_items = []
# loop through each vendor
@vendors.each do |vendor|
Copy link
Contributor

Choose a reason for hiding this comment

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

There is an easier way to do this! Might be worth asking chatgpt for some refactor tips.

items << item[0].name
end
end
items.uniq.sort
Copy link
Contributor

Choose a reason for hiding this comment

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

Sort!! Nice.

Comment on lines +11 to +20
it 'is and Item' do
expect(@item1).to be_an_instance_of(Item)
end

describe '#initialize' do
it 'has a name' do
expect(@item1.name).to eq('Peach')
end
it 'has a price' do
expect(@item1.price).to eq('$0.75')
Copy link
Contributor

Choose a reason for hiding this comment

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

Functionality that. happens in the initialize can be consolidated to the same test, if you want to save some time and some lines.

@market.add_vendor(@vendor1)
@market.add_vendor(@vendor2)
@market.add_vendor(@vendor3)
expect(@market.overstock_items).to eq([])
Copy link
Contributor

Choose a reason for hiding this comment

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

The spec asks for #overstocked_items and #sorted_item_list. Try to make you method names match exactly!! On a real team, a developer working on an adjacent feature might have to change their method names if they dont match what is exactly specified.

@market.add_vendor(@vendor1)
@market.add_vendor(@vendor2)
@market.add_vendor(@vendor3)
expect(@market.vendor_names.length).to eq(3)
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of checking the length, you should check that vendor_names is an array of the actual names.

@market.add_vendor(@vendor1)
@market.add_vendor(@vendor2)
@market.add_vendor(@vendor3)
expect(@market.vendors_that_sell(@item1)).to eq([@vendor1, @vendor3])
Copy link
Contributor

Choose a reason for hiding this comment

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

You could consider adding a test that handles the .stock functionality in isolation. This works though, this is a nice test!

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