-
Notifications
You must be signed in to change notification settings - Fork 590
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
Lions C18 LP Wilson Swap Meet #21
base: main
Are you sure you want to change the base?
Changes from all commits
9cb10db
a94fc8f
625834d
a139785
5a05190
81e696b
bb64793
8629a03
4c8b79f
8b84140
619f19e
f923478
5a71422
87db152
8bd0b07
b87351c
2d63659
618a629
7c9667b
99a1715
b9c08ab
d7d3cd8
edfb694
6b21756
e4b5573
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,8 @@ | ||
class Clothing: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self, category = "Clothing", condition = 0.0): | ||
#is there a way to NOT have condition here??I don't think so. | ||
super().__init__(category, condition) | ||
def __str__(self): | ||
return "The finest clothing you could wear." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
class Decor: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
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! |
||
def __init__(self, category = "Decor", condition = 0.0): | ||
super().__init__(category, condition) | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
class Electronics: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Electronics(Item): | ||
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! |
||
def __init__(self, category = "Electronics", condition = 0.0): | ||
super().__init__(category, condition) | ||
def __str__(self): | ||
return "A gadget full of buttons and secrets." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,17 @@ | ||
class Item: | ||
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. Excellent! |
||
pass | ||
def __init__(self, category = "", condition = 0.0): | ||
self.category = category | ||
self.condition = condition | ||
def __str__(self): | ||
return "Hello World!" | ||
def condition_description(self): | ||
if self.condition <= 1: | ||
return "OMG Don't swap for this!" | ||
elif self.condition <= 2: | ||
return "This item is well-loved" | ||
elif self.condition <= 3: | ||
return "This is average qualtiy" | ||
elif self.condition <= 4: | ||
return "This is in pretty good condition" | ||
else: | ||
return "Love this. Great condition." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,89 @@ | ||
class Vendor: | ||
pass | ||
"""The Vendor class has optional arguement inventory, | ||
methods: .add(item), .remove(item), .get_by_category(category), | ||
swap_items(swapping_vendor, my_item, their_item)""" | ||
def __init__(self, inventory = None): | ||
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. Excellent! |
||
#if an inventory list is given, assign it to the attribute | ||
if inventory: | ||
self.inventory = inventory | ||
#if no inventory list is given, initialize an empty list for inventory. | ||
else: | ||
self.inventory = [] | ||
|
||
def add(self, item): | ||
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. Excellent! |
||
"""appends the item to the inventory list and returns the item""" | ||
self.inventory.append(item) | ||
return item | ||
|
||
def remove(self, item): | ||
"""removes an item from the inventory list""" | ||
#if item is in inventory, remove it | ||
if item in self.inventory: | ||
self.inventory.remove(item) | ||
return item | ||
else: | ||
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. The else isn't necessary! Since the if block has a return statement, we know that if we move past the if it must be because we're in what happens in else. The return statement can stand on its own outside of the else. |
||
return False | ||
|
||
def get_by_category(self, 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. Excellent! Great use of list comprehension! |
||
"""given a category, return a list of all items in inventory | ||
that have that as their attribute category.""" | ||
# items_in_category = [] | ||
# #iterate through inventory to append items with the given category | ||
# for item in self.inventory: | ||
# if item.category == category: | ||
# items_in_category.append(item) | ||
|
||
items_in_category = [item for item in self.inventory if item.category == category] | ||
|
||
return items_in_category | ||
|
||
def swap_items(self, swapping_vendor, my_item, their_item): | ||
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. Excellent! |
||
"""given another vendor, my_item to swap, their_item to receive, make that swap.""" | ||
#if each item is in the right place, make the swap: | ||
if my_item in self.inventory and their_item in swapping_vendor.inventory: | ||
#make the swap | ||
self.remove(my_item) | ||
self.add(their_item) | ||
swapping_vendor.add(my_item) | ||
swapping_vendor.remove(their_item) | ||
|
||
return True | ||
else: | ||
return False | ||
|
||
def swap_first_item(self, swapping_vendor): | ||
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. Excellent! |
||
"""given another vendor, swap the first item | ||
in each of your inventories.""" | ||
if self.inventory and swapping_vendor.inventory: | ||
#call swap_items, inputing the first item on each of your inventories: | ||
result = self.swap_items(swapping_vendor, self.inventory[0], swapping_vendor.inventory[0]) | ||
return result | ||
else: | ||
return False | ||
|
||
def get_best_by_category(self, 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. Excellent! |
||
"""this will return the best item a vendor has in a given category""" | ||
#In the case of a tie, it will return the LAST instance of this item. | ||
best_item = None | ||
items_in_category = self.get_by_category(category) | ||
|
||
if items_in_category: | ||
best_item = items_in_category[0] | ||
for cat_item in items_in_category: | ||
if cat_item.condition >= best_item.condition: | ||
best_item = cat_item | ||
return best_item | ||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
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. Excellent! |
||
"""This will swap two items: self will give their item | ||
of highest quality from the category their_priority. | ||
In return, the swapping_vendor will give their best item from | ||
the category my_priority.""" | ||
#figure out what items will be swapped. | ||
my_item_to_swap = self.get_best_by_category(their_priority) | ||
their_item_to_swap = other.get_best_by_category(my_priority) | ||
result = self.swap_items(other, my_item_to_swap, their_item_to_swap) | ||
return result | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,12 @@ | |
import pytest | ||
from swap_meet.vendor import Vendor | ||
|
||
@pytest.mark.skip | ||
#@pytest.mark.skip | ||
def test_vendor_has_inventory(): | ||
vendor = Vendor() | ||
assert len(vendor.inventory) == 0 | ||
|
||
@pytest.mark.skip | ||
#@pytest.mark.skip | ||
def test_vendor_takes_optional_inventory(): | ||
inventory = ["a", "b", "c"] | ||
vendor = Vendor(inventory=inventory) | ||
|
@@ -16,7 +16,7 @@ def test_vendor_takes_optional_inventory(): | |
assert "b" in vendor.inventory | ||
assert "c" in vendor.inventory | ||
|
||
@pytest.mark.skip | ||
#@pytest.mark.skip | ||
def test_adding_to_inventory(): | ||
vendor = Vendor() | ||
item = "new item" | ||
|
@@ -27,7 +27,7 @@ def test_adding_to_inventory(): | |
assert item in vendor.inventory | ||
assert result == item | ||
|
||
@pytest.mark.skip | ||
#@pytest.mark.skip | ||
def test_removing_from_inventory_returns_item(): | ||
item = "item to remove" | ||
vendor = Vendor( | ||
|
@@ -40,16 +40,13 @@ def test_removing_from_inventory_returns_item(): | |
assert item not in vendor.inventory | ||
assert result == item | ||
|
||
@pytest.mark.skip | ||
#@pytest.mark.skip | ||
def test_removing_not_found_is_false(): | ||
item = "item to remove" | ||
vendor = Vendor( | ||
inventory=["a", "b", "c"] | ||
) | ||
|
||
result = vendor.remove(item) | ||
|
||
raise Exception("Complete this test according to comments below.") | ||
# ********************************************************************* | ||
# ****** Complete Assert Portion of this test ********** | ||
# ********************************************************************* | ||
#assert: | ||
result == False | ||
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 assert! It would also be a good idea to check the length of inventory to make sure nothing was accidentally removed. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,12 @@ | |
from swap_meet.vendor import Vendor | ||
from swap_meet.item import Item | ||
|
||
@pytest.mark.skip | ||
#@pytest.mark.skip | ||
def test_items_have_blank_default_category(): | ||
item = Item() | ||
assert item.category == "" | ||
|
||
@pytest.mark.skip | ||
#@pytest.mark.skip | ||
def test_get_items_by_category(): | ||
item_a = Item(category="clothing") | ||
item_b = Item(category="electronics") | ||
|
@@ -23,7 +23,7 @@ def test_get_items_by_category(): | |
assert item_c in items | ||
assert item_b not in items | ||
|
||
@pytest.mark.skip | ||
#@pytest.mark.skip | ||
def test_get_no_matching_items_by_category(): | ||
item_a = Item(category="clothing") | ||
item_b = Item(category="clothing") | ||
|
@@ -34,7 +34,7 @@ def test_get_no_matching_items_by_category(): | |
|
||
items = vendor.get_by_category("electronics") | ||
|
||
raise Exception("Complete this test according to comments below.") | ||
# ********************************************************************* | ||
# ****** Complete Assert Portion of this test ********** | ||
# ********************************************************************* | ||
assert len(items) == 0 | ||
assert item_a not in items | ||
assert item_b not in items | ||
assert item_c not in items | ||
Comment on lines
+38
to
+40
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 asserts! These are actually not needed though. Based on the first assert, we know the list is empty. We don't need to check that each of these individual items are in the list. |
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.
We actually do not want to have category in the
__init__
function. We want the category to always be "Clothing", but if we put category here, the user can set category to whatever they want, which isn't good!