Skip to content

C22: Leidy (Sprinx) and Tram (Phoenix)#18

Open
tramhn001 wants to merge 18 commits intoAda-C22:mainfrom
tramhn001:main
Open

C22: Leidy (Sprinx) and Tram (Phoenix)#18
tramhn001 wants to merge 18 commits intoAda-C22:mainfrom
tramhn001:main

Conversation

@tramhn001
Copy link
Copy Markdown

No description provided.

@tramhn001 tramhn001 changed the title Swap_meet : Leidy and Tram C22: Leidy (Sprinx) and Tram (Phoenix) Oct 4, 2024
Comment thread swap_meet/clothing.py
Comment on lines +8 to +10
def __str__(self):
return f"An object of type {self.__class__.__name__} with id {self.id}. "\
f"It is made from {self.fabric} fabric."
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/decor.py
Comment on lines +5 to +6
self.width = 0 if width is None else width
self.length = 0 if length is None else length
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since integers are not mutable datatypes we don't need to take the same precautions as we do with mutable datatypes like lists. This is because a new 0 would be created in memory. So we could have the following:

def __init__(self, id=None, width=0, length=0, condition=None, age=None):
        super().__init__(id, condition, age)
        self.width = width
        self.length = length

Comment thread swap_meet/item.py
class Item:
pass No newline at end of file
def __init__(self, id=None, condition=None, age= None):
self.id = id if id is not None else uuid.uuid4().int
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
Comment on lines +15 to +27
def condition_description(self):

if self.condition > 0 and self.condition < 1:
return "It's barely holding together."
elif self.condition >= 1 and self.condition < 2:
return "This item has seen better days."
elif self.condition >= 2 and self.condition < 3:
return "It is a bit worn, but still has life left."
elif self.condition >= 3 and self.condition < 4:
return "In good condition."
elif self.condition >= 4 and self.condition < 5:
return "Almost like new!"
return "Mint 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.

This could also be a time to use match case!

    def condition_description(self):
        match self.condition:
            case 0:
                return "Throw Away"
            case 1:
                return "Eh"
            case 2:
                return "Better..."
            case 3:
                return "..."
            case 4: 
                return "Okay?!"
            case 5:
                return "Yes!"

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

def swap_items(self, other_vendor, my_item, their_item):

if not my_item 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
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 +40 to +41
self.inventory[0] = their_first_item
other_vendor.inventory[0] = my_first_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.

A perfect case to use the swap_items method

Comment thread swap_meet/vendor.py
Comment on lines +46 to +49
category_list = []
for item in self.inventory:
if item.get_category() == category:
category_list.append(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.

How would this look as list comprehension?

Comment thread swap_meet/vendor.py
return category_list

def get_best_by_category(self, category):
category_list = self.get_by_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.

Comment thread swap_meet/vendor.py
Comment on lines +59 to +65
best_item = None
best_item_condition = -1

for item in category_list:
if item.condition > best_item_condition:
best_item_condition = item.condition
best_item = 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.

Great work here! Could we also use the dot (.) operator here to check the best_item's condition?

Comment thread swap_meet/vendor.py
Comment on lines +71 to +77
vendor_best_item = self.get_best_by_category(their_priority)
other_vendor_best_item = other_vendor.get_best_by_category(my_priority)

if not vendor_best_item or not other_vendor_best_item:
return False

self.swap_items(other_vendor,vendor_best_item,other_vendor_best_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.

Love this!

Comment thread swap_meet/vendor.py
Comment on lines +87 to +96
for item in self.inventory:
if item.age < my_newest_item_age:
my_newest_item_age = item.age
my_newest_item = item

# Find the newest item in the other vendor's inventory
for item in other_vendor.inventory:
if item.age < their_newest_item_age:
their_newest_item_age = item.age
their_newest_item = 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.

Since we are essentially doing the same thing here, we could make this into a method on that all instances will have access to. That way we DRY up our code some.

Comment on lines 44 to +53
def test_removing_not_found_is_false():
item = "item to remove"
item = "c"
vendor = Vendor(
inventory=["a", "b", "c"]
)

result = vendor.remove(item)
vendor_length = len(vendor.inventory)

assert result == "c"
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 test should look to see if your function returns False if it looks to remove an item that is not in the inventory of a given vendor. How could we change it to implement that logic?


raise Exception("Complete this test according to comments below.")
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.

assert jolie.inventory == [] would ensure that the inventory is an empty list.

Comment on lines +162 to +163
assert item_f in tai.inventory
assert item_c in jesse.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 use a for loop to check to see if all the items are in their respective inventories.

Comment on lines +253 to +254
assert item_a or item_b or item_c not in jesse.inventory
assert item_d or item_e or item_f not in tai.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.

These check to make sure the items aren't in the wrong list, but we would still need to check to see if they are in the right list.

assert len(jesse.inventory) == 0
assert item_a in tai.inventory
assert item_b in tai.inventory
assert item_c in tai.inventory 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.

Awesome work!

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