Skip to content

C22/ Luibov&Natalie/ swap-meet#6

Open
natsen1004 wants to merge 4 commits into
Ada-C22:mainfrom
natsen1004:main
Open

C22/ Luibov&Natalie/ swap-meet#6
natsen1004 wants to merge 4 commits into
Ada-C22:mainfrom
natsen1004:main

Conversation

@natsen1004

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!

result = vendor.remove(item)

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

👍 This is the expected result, but we might also include checks to make sure that the vendor's inventory wasn't modified.

Comment on lines +134 to +139
assert result == False
assert len(fatimah.inventory) == 3
assert item_a in fatimah.inventory
assert item_b in fatimah.inventory
assert item_c in fatimah.inventory
assert len(jolie.inventory) == 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.

👍 Great job checking both the result and that no changes happened to the inventories.

items = vendor.get_by_category("Electronics")

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

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.

👍 In tests, I like the asserts to be as specific as we can make them. We are told this should return an empty list in this situation, and your check literally checks for an empty list. This ensures the type is correct (a list) and that it has no contents. In contrast, if we had checked that the len of the result was 0, that would just tell us that there was a collection with notihing in it, not that it was a list. And doing a falsy test (like we usually do in application code to check for empty collections) wouldn't even guarantee that we had gotten a collection back at all, only that the result was falsy.

In earlier cases, checked that the inventories weren't modified for a failing case, but since we don't expect get_by_category to ever modify any data, we don't need to consider that here.

Comment on lines +116 to +118
assert result == True
assert len(tai.inventory) == 3
assert len(jesse.inventory) == 3

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 we should also check that items we expected to swap actually did so, and that the items that should have remained where they were also did so.

Comment on lines +155 to +167
assert result is True
assert len(tai.inventory) == 3
assert len(jesse.inventory) == 3

assert item_b in tai.inventory
assert item_a in tai.inventory
assert item_f in tai.inventory
assert item_c not in tai.inventory

assert item_d in jesse.inventory
assert item_e in jesse.inventory
assert item_c in jesse.inventory
assert item_f not 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.

👍 Great job checking the contents as well.

Notice that we don't need to check the not in cases, since we know that each list is 3 items long, and we checked that the 3 expected to be there are in fact there, this means the 4th item (that should have swapped) cannot be there. If it were there, that would mean there were 4 items in the inventories.

Comment thread swap_meet/vendor.py
return items_in_category

def get_best_by_category(self, category):
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
def find_best_item_by_category(self, category):
return self.get_best_by_category(category)

def swap_best_by_category(self, other_vendor, my_priority, their_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 +82 to +83
self.swap_items(other_vendor, my_best_item, their_best_item)
return 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.

We could return the result of this function call, which will be False if the swap fails, and True if it succeeds.

Comment thread swap_meet/vendor.py
Comment on lines +79 to +80
if my_best_item is None or their_best_item is None:
return 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.

Is this check necessary? If either of the find_best_item_by_category calls fails, we'll get bakc None. None shouldn't be in either of the inventories, meaning an attempt to swap would also fail, returning False.

It still might be more clear to have this check, but if we have confidence in the behavior of our other functions, we may be able to remove unnecessary logic.

Comment thread swap_meet/vendor.py
return True


def reorder_inventory(self, new_order):

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.

How would you expect a function like this to be used? It looks like it allows a new ordering to be specified and a new inventory will be constructed. Did you have a particular use case in mind?

It would be great if there were tests added for this function to show what some of the behaviors could be. And for some additional validation, what would happen if not every index were included (e.g., some indices were duplicated)?

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