-
Notifications
You must be signed in to change notification settings - Fork 26
C22 - Lorraine Shi and Charday Neal #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
16c929d
34432fa
01857c2
ba527b7
e6f34ea
98c392c
638d19f
7d2f504
48fd6f7
c41f61e
715f3d4
152348a
1e4ded7
189c802
ca01589
0de2f2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,10 @@ | ||
| class Clothing: | ||
| pass | ||
| from swap_meet.item import Item | ||
|
|
||
| class Clothing(Item): | ||
| def __init__(self, id=None, fabric="Unknown",condition=0,age=0): | ||
| super().__init__(id,condition, age) | ||
| self.fabric = fabric | ||
|
|
||
|
|
||
| def __str__(self): | ||
| return f"{super().__str__()} It is made from {self.fabric} fabric." | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,12 @@ | ||
| class Decor: | ||
| pass | ||
| from swap_meet.item import Item | ||
|
|
||
| class Decor(Item): | ||
|
|
||
| def __init__(self, id=None, width=0, length=0, condition=0, age=0): | ||
| super().__init__(id,condition, age) | ||
| self.width = width | ||
| self.length = length | ||
|
|
||
|
|
||
| def __str__(self): | ||
| return f"{super().__str__()} It takes up a {self.width} by {self.length} sized space." |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,11 @@ | ||
| class Electronics: | ||
| pass | ||
| from swap_meet.item import Item | ||
| class Electronics(Item): | ||
| def __init__(self, id=None, type="Unknown",condition=0,age=0): | ||
| super().__init__(id,condition,age) | ||
| self.type = type | ||
|
|
||
|
|
||
|
|
||
| def __str__(self): | ||
| return f"{super().__str__()} This is a {self.type} device." | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,25 @@ | ||
| from uuid import uuid4 | ||
|
|
||
| class Item: | ||
| pass | ||
| def __init__(self, id=None,condition=0,age=0): | ||
| self.id = uuid4().int if id is None else id | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||
| self.condition = condition | ||
| self.age = age | ||
|
|
||
| def get_category(self): | ||
| return self.__class__.__name__ | ||
|
|
||
| def __str__(self): | ||
| return f"An object of type {self.get_category()} with id {self.id}." | ||
|
|
||
| def condition_description(self): | ||
| condition = self.condition | ||
| match condition: | ||
| case condition if 0.0 <= condition < 2.0: | ||
| return 'This is poor condition' | ||
| case condition if 2.0 <= condition < 4.0: | ||
| return 'It is gently used.' | ||
| case condition if 4.0 < condition: | ||
| return 'Fantastic condition' | ||
| case _: | ||
| return "Hmm...something's not right." | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,73 @@ | ||
| class Vendor: | ||
| pass | ||
| def __init__(self, inventory=None): | ||
| self.inventory = [] if inventory is None else inventory | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⭐️ |
||
|
|
||
| def add(self, item): | ||
| self.inventory.append(item) | ||
| return item | ||
|
|
||
| def remove(self, item): | ||
| if item not in self.inventory: | ||
| return False | ||
| self.inventory.remove(item) | ||
| return item | ||
|
|
||
| def get_by_id(self, id): | ||
| for item in self.inventory: | ||
| if item.id == id: | ||
| return item | ||
| return None | ||
|
|
||
| def swap_items(self, other_vendor, my_item, their_item): | ||
| if self.get_by_id(my_item.id) and other_vendor.get_by_id(their_item.id): | ||
| self.remove(my_item) | ||
| self.add(their_item) | ||
| other_vendor.remove(their_item) | ||
| other_vendor.add(my_item) | ||
| return True | ||
|
|
||
| return False | ||
|
|
||
| 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 | ||
|
Comment on lines
+31
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great function! |
||
|
|
||
| def get_by_category(self, category): | ||
| return [item for item in self.inventory if item.get_category() == category] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Omg list comprehension, love her! |
||
|
|
||
| def get_best_by_category(self, category): | ||
| category_items = self.get_by_category(category) | ||
| if not category_items: | ||
| return None | ||
|
|
||
| best_condition_item = category_items[0] | ||
| best_condition = category_items[0].condition | ||
|
|
||
| for item in category_items: | ||
| if item.condition > best_condition: | ||
| best_condition = item.condition | ||
| best_condition_item = item | ||
|
|
||
| return best_condition_item | ||
| # return max(category_items, key=lambda item : item.condition) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect use of a lambda function! |
||
|
|
||
| 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) | ||
|
Comment on lines
+59
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💅🏿 |
||
|
|
||
| def get_newest(self): | ||
| return min(self.inventory, key=lambda item:item.age) | ||
|
|
||
| def swap_by_newest(self, other_vendor): | ||
| my_swap_item = self.get_newest() | ||
| their_swap_item = other_vendor.get_newest() | ||
|
Comment on lines
+71
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 |
||
| return self.swap_items(other_vendor, my_swap_item, their_swap_item) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| from swap_meet.vendor import Vendor | ||
| from swap_meet.item import Item | ||
|
|
||
| @pytest.mark.skip | ||
| # @pytest.mark.skip | ||
| def test_item_overrides_to_string(): | ||
| test_id = 12345 | ||
| item = Item(id=test_id) | ||
|
|
@@ -12,7 +12,7 @@ def test_item_overrides_to_string(): | |
| expected_result = f"An object of type Item with id {test_id}." | ||
| assert item_as_string == expected_result | ||
|
|
||
| @pytest.mark.skip | ||
| # @pytest.mark.skip | ||
| def test_swap_items_returns_true(): | ||
| item_a = Item() | ||
| item_b = Item() | ||
|
|
@@ -40,7 +40,7 @@ def test_swap_items_returns_true(): | |
| assert item_b in jolie.inventory | ||
| assert result | ||
|
|
||
| @pytest.mark.skip | ||
| # @pytest.mark.skip | ||
| def test_swap_items_when_my_item_is_missing_returns_false(): | ||
| item_a = Item() | ||
| item_b = Item() | ||
|
|
@@ -67,7 +67,7 @@ def test_swap_items_when_my_item_is_missing_returns_false(): | |
| assert item_e in jolie.inventory | ||
| assert not result | ||
|
|
||
| @pytest.mark.skip | ||
| # @pytest.mark.skip | ||
| def test_swap_items_when_their_item_is_missing_returns_false(): | ||
| item_a = Item() | ||
| item_b = Item() | ||
|
|
@@ -94,7 +94,7 @@ def test_swap_items_when_their_item_is_missing_returns_false(): | |
| assert item_e in jolie.inventory | ||
| assert not result | ||
|
|
||
| @pytest.mark.skip | ||
| # @pytest.mark.skip | ||
| def test_swap_items_from_my_empty_returns_false(): | ||
| fatimah = Vendor( | ||
| inventory=[] | ||
|
|
@@ -114,7 +114,7 @@ def test_swap_items_from_my_empty_returns_false(): | |
| assert len(jolie.inventory) == 2 | ||
| assert not result | ||
|
|
||
| @pytest.mark.skip | ||
| # @pytest.mark.skip | ||
| def test_swap_items_from_their_empty_returns_false(): | ||
| item_a = Item() | ||
| item_b = Item() | ||
|
|
@@ -131,7 +131,10 @@ def test_swap_items_from_their_empty_returns_false(): | |
|
|
||
| result = fatimah.swap_items(jolie, item_b, nobodys_item) | ||
|
|
||
| raise Exception("Complete this test according to comments below.") | ||
| # ********************************************************************* | ||
| # ****** Complete Assert Portion of this test ********** | ||
| # ********************************************************************* | ||
| assert len(fatimah.inventory) == 3 | ||
| assert len(jolie.inventory) == 0 | ||
|
Comment on lines
+134
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| assert fatimah.inventory == [item_a, item_b, item_c] | ||
| assert jolie.inventory == [] | ||
|
|
||
| assert not result | ||
There was a problem hiding this comment.
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 forClothing,Decor, andElectronicall start with "An object of type [CLASSNAME] with id [ID].". Inside ofItemwe 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, andElectronic). It could something like this: