Sphinx_Olga_Karaivanska_and_Tatiana_Snook#11
Sphinx_Olga_Karaivanska_and_Tatiana_Snook#11lioliadoc wants to merge 22 commits intoAda-C22:mainfrom
Conversation
| class Item: | ||
| pass No newline at end of file | ||
| def __init__(self, id=None, condition=0): | ||
| self.id = id if id is not None else uuid.uuid4().int | ||
| self.condition = condition | ||
|
|
||
| def get_category(self): | ||
| return self.__class__.__name__ | ||
|
|
||
| def __str__(self): | ||
| return f"An object of type {self.get_category()} with id {self.id}." |
There was a problem hiding this comment.
Really great work on the inheritance and methods for the different classes!
| def __str__(self): | ||
| return f"An object of type {self.get_category()} with id {self.id}." | ||
|
|
||
| conditions = {0: "New", 1: "Mint", 2: "Good", 3: "Fair", 4: "Heavily used", 5: "Damaged"} |
There was a problem hiding this comment.
I would opt to move this inside of the condition_description method since it is the only function that will use it. 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!"| class Vendor: | ||
| pass No newline at end of file | ||
| def __init__(self, inventory=None): | ||
| self.inventory = [] if inventory is None else inventory |
| 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: |
There was a problem hiding this comment.
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.
| self.remove(my_item) | ||
| other_vendor.add(my_item) | ||
| other_vendor.remove(their_item) | ||
| self.add(their_item) |
| first_item = self.remove(self.inventory[0]) | ||
| other_vendor.add(first_item) | ||
|
|
||
| other_first_item = other_vendor.remove(other_vendor.inventory[0]) | ||
| self.add(other_first_item) |
There was a problem hiding this comment.
Couldn't we also use the the swap_items method here to do this?
| for item in self.inventory: | ||
| if item.get_category() == category: | ||
| category_list.append(item) |
There was a problem hiding this comment.
How would this look as list comprehension?
| best_item = None | ||
| highest_condition = 0 | ||
|
|
||
| for item in self.inventory: |
There was a problem hiding this comment.
Here we could loop over a list of items in a specific category curated by get_by_category. That way we don't have to check to see if an item has a matching category.
| def swap_best_by_category(self, other_vendor, my_priority, their_priority): | ||
| my_best_item = self.get_best_by_category(their_priority) | ||
| their_best_item = other_vendor.get_best_by_category(my_priority) | ||
|
|
||
| if my_best_item and their_best_item: | ||
| self.swap_items(other_vendor, my_best_item, their_best_item) | ||
| return True | ||
|
|
||
| return False No newline at end of file |
| assert len(vendor.inventory) == 3 | ||
| assert item not in vendor.inventory | ||
| assert result == False |
There was a problem hiding this comment.
Nice, this accurately tests for everything!
| assert len(jolie.inventory) == 0 | ||
| assert len(fatimah.inventory) == 3 |
There was a problem hiding this comment.
How could we alter these to ensure that test for the correct data structures as well? Right now they would pass with any data structure of length 0 and 3.
| assert item_a in tai.inventory | ||
| assert item_b in tai.inventory | ||
| assert item_f in tai.inventory | ||
| assert item_d in jesse.inventory | ||
| assert item_e in jesse.inventory | ||
| assert item_c in jesse.inventory |
There was a problem hiding this comment.
We could use a loop here to help DRY up our code
No description provided.