Skip to content

Ada C22 Phoenix Class - Madina Dzhetegenova#20

Open
Madina-j wants to merge 18 commits into
Ada-C22:mainfrom
PickledData:main
Open

Ada C22 Phoenix Class - Madina Dzhetegenova#20
Madina-j wants to merge 18 commits into
Ada-C22:mainfrom
PickledData:main

Conversation

@Madina-j

@Madina-j Madina-j commented Oct 4, 2024

Copy link
Copy Markdown

No description provided.

@anselrognlie anselrognlie left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good! Please review my comments, and let me know if you have any questions via Slack, our next 1:1, or office hours. Nice job!

Comment on lines +52 to +53
assert item not in vendor.inventory
assert result == False

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 While it would be surprising if the remove call had added item into the inventory (remove doesn't have any logic that should result in this being possible), I like that you're thinking about checking the status of the inventory. Since the remove failed, there shold be no change. So we might wantt o ensure that the values that started in the inventory were all still there after the remove call.

# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************
assert result == False

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 Here again, this is the expected result, but we might also include checks to make that the vendor's inventory wasn't modified after the failed swap.

items = vendor.get_by_category("Electronics")

raise Exception("Complete this test according to comments below.")
assert len(items) == 0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 We shouldn't get any matches in this case.

Notice that this checks that items is an empty collection, but not necessarily a list. The function is specified to return an empty list when no items are found, so we might prefer to write this as

    assert items == []

Or we could add a type()/isinstance() assertion that items is, in fact, a list.

)

raise Exception("Complete this test according to comments below.")
assert result is True

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 I agree with checking literally for True rather than doing a truthy check, since the spec literally says the result should be True. In application code that uses this function, we might relax our checks to be more truthy/falsy, but a test should enforce the behavior as strictly as possible.

Typically, if we do need to compare with True or False we usually use == (and is for None). Technically, == wouldn't guarantee that result was literally True (in Python 0 == False and 1 == True), so I could be persuaded to prefer is since we're expecting to literally return either True or False.

Comment on lines +117 to +120
assert item_c not in tai.inventory
assert item_f in tai.inventory
assert item_f not in jesse.inventory
assert item_c in jesse.inventory

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👀 We should also make sure that the non-swapped items are still in their original lists. Yes, we checked that the overall length hasn't changed, but we should make sure that the membership is as we expect.

Comment thread swap_meet/vendor.py
Comment on lines +47 to +50
items_in_category = []
for item in self.inventory:
if item.get_category() == category:
items_in_category.append(item)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 We need to loop to find all the items with the specified category.

This would be a great opportunity to try using list comprehension syntax.

Comment thread swap_meet/vendor.py
return items_in_category

def get_best_by_category(self, category=None):
items_in_category = self.get_by_category(category)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 Nice use of the function we just made, and then locating the best value in the result (if any).

Comment thread swap_meet/vendor.py
Comment on lines +59 to +61
for item in items_in_category:
if item.condition > item_best_condition.condition:
item_best_condition = item

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 Nice logic to loop through and find the item with the best condition.

Comment thread swap_meet/vendor.py
Comment on lines +66 to +67
my_best_item = self.get_best_by_category(their_priority)
their_best_item = other_vendor.get_best_by_category(my_priority)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 Great job reusing our Vendor functions.

Comment thread swap_meet/vendor.py
Comment on lines +72 to +76
self.remove(my_best_item)
other_vendor.add(my_best_item)

other_vendor.remove(their_best_item)
self.add(their_best_item)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👀 Once we've identified the two items to swap, could we reuse swap logic that we previously wrote?

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