Skip to content

C22 - Lorraine Shi and Charday Neal#19

Open
chardayneal wants to merge 16 commits into
Ada-C22:mainfrom
chardayneal:main
Open

C22 - Lorraine Shi and Charday Neal#19
chardayneal wants to merge 16 commits into
Ada-C22:mainfrom
chardayneal:main

Conversation

@chardayneal

Copy link
Copy Markdown

No description provided.

Comment thread swap_meet/clothing.py
self.fabric = fabric
self.age = age

def __str__(self):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Notice that each __str__ method for Clothing, Decor, and Electronic all start with "An object of type [CLASSNAME] with id [ID].". Inside of Item we can have a __str__ method that print could return the part mentioned above and then pair that with the __str__ inside the child classes (Clothing, Decor, and Electronic). It could something like this:

class Item: 
...
	def  __str__(self):
		return  f"An object of type {self.get_category()}" \
		f" with id {self.id}."

class Clothing(Item):
...
	def  __str__(self):
		return  f"{super().__str__()} It is made " \
		f"from {self.fabric} fabric."

Comment thread swap_meet/clothing.py Outdated
def __init__(self, id=None, fabric="Unknown",condition=0,age=0):
super().__init__(id,condition)
self.fabric = fabric
self.age = age

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If all the children classes will have an attribute called age could we move this attribute into the parent class Item?

Comment thread swap_meet/item.py
class Item:
pass No newline at end of file
def __init__(self, id=None,condition=0,age=0):
self.id = uuid4().int if id is None else id

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread swap_meet/item.py Outdated
self.age = age

def get_category(self):
return type(self).__name__

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This could be written as self.__class__.__name__

Comment thread swap_meet/item.py Outdated
Comment on lines +16 to +21
if self.condition <= 2.0:
return "This is poor condition."
elif self.condition <= 4.0:
return "It is gently used."
elif self.condition > 4.0:
return "Fantastic condition!" No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A perfect time to use match casing as well!

Comment thread swap_meet/vendor.py
class Vendor:
pass No newline at end of file
def __init__(self, inventory=None):
self.inventory = [] if inventory is None else inventory

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⭐️

Comment thread swap_meet/vendor.py Outdated
return None

def swap_items(self, other_vendor, my_item, their_item):
if my_item not in self.inventory or their_item not in other_vendor.inventory:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We could also use get_by_id to check if an item is in a given inventory and then check to see if that function returns None or the item.

Comment thread swap_meet/vendor.py Outdated
return False

self.inventory.remove(my_item)
self.inventory.append(their_item)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Don't we have a method that adds items to an inventory? 👀 Might look simple here, but what happens if the structure of inventory changes?

Comment thread swap_meet/vendor.py
Comment on lines +31 to +38
def swap_first_item(self, other_vendor):
if not self.inventory or not other_vendor.inventory:
return False

my_first_item = self.inventory[0]
other_first_item = other_vendor.inventory[0]
self.swap_items(other_vendor, my_first_item, other_first_item)
return True

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great function!

Comment thread swap_meet/vendor.py
return True

def get_by_category(self, category):
return [item for item in self.inventory if item.get_category() == category]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Omg list comprehension, love her!

Comment thread swap_meet/vendor.py
best_condition_item = item

return best_condition_item
# return max(category_items, key=lambda item : item.condition)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perfect use of a lambda function!

Comment thread swap_meet/vendor.py
Comment on lines +59 to +65
def swap_best_by_category(self, other_vendor, my_priority, their_priority):
my_swap_item = self.get_best_by_category(their_priority)
their_swap_item = other_vendor.get_best_by_category(my_priority)

if not my_swap_item or not their_swap_item:
return False
return self.swap_items(other_vendor, my_swap_item, their_swap_item)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💅🏿

Comment thread swap_meet/vendor.py
Comment on lines +71 to +72
my_swap_item = self.get_newest()
their_swap_item = other_vendor.get_newest()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎉

Comment on lines +134 to +135
assert len(fatimah.inventory) == 3
assert len(jolie.inventory) == 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

How could we alter these to make sure they check for the correct data structure as well.

Comment on lines +228 to +229
assert tai.inventory == [item_a, item_b, item_c]
assert jesse.inventory == [item_d, item_e, item_f]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

perfect!

assert len(tai.inventory) == 3
assert len(jesse.inventory) == 3
assert tai.inventory == [item_c, item_b, item_f]
assert jesse.inventory == [item_e, item_d, item_a]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great work here!

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