-
Notifications
You must be signed in to change notification settings - Fork 110
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
Cheetahs - Lynn Jansheski #93
base: master
Are you sure you want to change the base?
Changes from all commits
4a99471
a8d38e2
154cf97
ebf0073
bece982
918ee22
4f23363
1bb0d6a
166ca54
d82db9c
989abd8
74dc31a
25a7dc6
3816d79
89eee41
d50ffbf
08ebf5e
599180b
3b1ac5d
a5bf167
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,11 @@ | ||
class Clothing: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
'''Creating child class of item for clothing category.''' | ||
def __init__(self, condition=0, age=0): | ||
super().__init__("Clothing", condition, age) | ||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
class Decor: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
'''Creating child class of item for decor category.''' | ||
def __init__(self, condition=0, age=0): | ||
super().__init__("Decor", condition, age) | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
class Electronics: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Electronics(Item): | ||
'''Creating child class of item for electronics category.''' | ||
def __init__(self, condition=0, age=0): | ||
super().__init__("Electronics", condition, age) | ||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
class Item: | ||
pass | ||
'''Creating parent class for all items to include category, condition and age.''' | ||
def __init__(self, category="", condition=0, age=0): | ||
self.category = category | ||
self.condition = condition | ||
self.age = age | ||
|
||
def __str__(self): | ||
return "Hello World!" | ||
|
||
def condition_description(self): | ||
if self.condition == 0: | ||
return "This is pretty much garbage." | ||
elif self.condition <= 1: | ||
return "Not great." | ||
elif self.condition <= 2: | ||
return "This is ok." | ||
elif self.condition <= 3: | ||
return "Not too bad." | ||
elif self.condition <= 4: | ||
return "Looking good." | ||
elif self.condition <= 5: | ||
return "Perfect." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,108 @@ | ||
class Vendor: | ||
pass | ||
from tkinter import N | ||
from xml.dom.expatbuilder import theDOMImplementation | ||
from swap_meet.item import Item | ||
|
||
class Vendor(): | ||
'''Creating vendor with inventory. Includes methods for adding and removing | ||
items from inventory by category and condition. Includes methods for swapping | ||
items by category, condition and age.''' | ||
def __init__(self, inventory=None): | ||
if inventory is None: | ||
self.inventory = [] | ||
else: | ||
self.inventory = inventory # list of item objects | ||
|
||
def add(self, item): | ||
'''Add item to inventory list.''' | ||
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. Beautiful docstrings ✨ |
||
self.inventory.append(item) | ||
return item | ||
|
||
def remove(self, item): | ||
'''Remove item from inventory list.''' | ||
if item in self.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. This approach works, but consider how a |
||
self.inventory.remove(item) | ||
return item | ||
|
||
def get_by_category(self, category): | ||
'''Get item from inventory by category.''' | ||
inventory_by_category = [] | ||
|
||
for item in self.inventory: # items in inventory have categories | ||
if item.category == category: | ||
inventory_by_category.append(item) | ||
|
||
return inventory_by_category | ||
|
||
def swap_items(self, another_vendor, my_item, their_item): | ||
'''Swap item between self and another vendor. Call add and remove | ||
methods.''' | ||
if len(self.inventory) == 0 or len(another_vendor.inventory) == 0: | ||
return False | ||
|
||
if my_item in self.inventory and their_item in another_vendor.inventory: | ||
self.add(their_item) | ||
self.remove(my_item) | ||
another_vendor.add(my_item) | ||
another_vendor.remove(their_item) | ||
return True | ||
|
||
return False | ||
|
||
|
||
def swap_first_item(self, another_vendor): | ||
'''Swap first item in self inventory with first item in another | ||
vendor's inventory.''' | ||
if len(self.inventory) > 0 and len(another_vendor.inventory) > 0: | ||
my_item = self.inventory[0] | ||
their_item = another_vendor.inventory[0] | ||
return self.swap_items(another_vendor, my_item, their_item) | ||
|
||
else: | ||
return False | ||
|
||
|
||
def get_best_by_category(self, category): | ||
'''Get item in best condition by category.''' | ||
|
||
if len(self.get_by_category(category)) == 0: | ||
return None | ||
else: | ||
return max(self.get_by_category(category), 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. Oooo! Great usage of the |
||
|
||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
'''Swap item in best condition by desired category of other vendor | ||
and vice versa. Returns False if desired category not in either | ||
inventory.''' | ||
my_best_by_category = self.get_best_by_category(their_priority) | ||
their_best_by_category = other.get_best_by_category(my_priority) | ||
|
||
if my_best_by_category and their_best_by_category: | ||
self.swap_items(other, my_best_by_category, their_best_by_category) | ||
|
||
return True | ||
|
||
else: | ||
return False | ||
|
||
###############Extra################# | ||
|
||
def get_newest_item(self): | ||
'''Get newest item from inventory.''' | ||
if len(self.inventory) > 0: | ||
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. Since a list with 1 or more values is truthy, the Pythonic way to write this if statement would be:
😊 🐍 |
||
return min(self.inventory, key=lambda item: item.age) | ||
else: | ||
return False | ||
|
||
def swap_by_newest(self, other): | ||
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 job with the optional enhancements! 🎉 |
||
'''Swap newest item from inventory with newest item from another vendor. Returns false | ||
if either inventory is empty.''' | ||
if len(self.inventory) > 0 and len(other.inventory) > 0: | ||
|
||
my_newest = self.get_newest_item() | ||
their_newest = other.get_newest_item() | ||
|
||
return self.swap_items(other, my_newest, their_newest) | ||
|
||
else: | ||
return False |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,13 @@ | |
import pytest | ||
from swap_meet.vendor import Vendor | ||
|
||
@pytest.mark.skip | ||
# @pytest.mark.skip | ||
def test_vendor_has_inventory(): | ||
vendor = Vendor() | ||
print(f"{vendor.inventory=}") | ||
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 +17,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 +28,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,7 +41,7 @@ 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( | ||
|
@@ -49,7 +50,9 @@ def test_removing_not_found_is_false(): | |
|
||
result = vendor.remove(item) | ||
|
||
raise Exception("Complete this test according to comments below.") | ||
assert result == "item to remove" | ||
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. Be sure to read the instructions and test names carefully! the Vendor remove method is supposed to return False if the item is not found. |
||
|
||
# raise Exception("Complete this test according to comments below.") | ||
# ********************************************************************* | ||
# ****** Complete Assert Portion of this test ********** | ||
# ********************************************************************* |
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.
Great job with wave 5 and using inheritance! Nice work hardcoding the category too 🥳