-
Notifications
You must be signed in to change notification settings - Fork 71
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
Scissors Swap Meet - Araceli #71
base: master
Are you sure you want to change the base?
Changes from 1 commit
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
import pytest | ||
from swap_meet.vendor import Vendor | ||
from swap_meet.item import Item | ||
|
||
|
||
item_a = Item(category="clothing") | ||
item_b = Item(category="electronics") | ||
item_c = Item(category="clothing") | ||
vendor = Vendor( | ||
inventory=[item_a, item_b, item_c] | ||
) | ||
|
||
items = vendor.get_by_category("clothing") | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class Clothing: | ||
|
||
def __init__(self, category = "Clothing", condition = 0): | ||
|
||
self.category = category | ||
self.condition = condition | ||
|
||
def __str__(self): | ||
|
||
return "The finest clothing you could wear." | ||
|
||
def condition_description(self): | ||
|
||
if self.condition == 1: | ||
return "Geez, maybe put that back." | ||
elif self.condition == 2: | ||
return "Well, could be worse." | ||
elif self.condition == 3: | ||
return "What are the savings from retail value?" | ||
elif self.condition == 4: | ||
return "Almost in perfect condition" | ||
elif self.condition == 5: | ||
return "I am delighted from the sun and back" | ||
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. Love these :D |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,22 @@ | ||||||
class Decor: | ||||||
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 is the first of many changes that'd need to be made to this class definition to properly inherit from the Item class.
Suggested change
|
||||||
|
||||||
def __init__(self, category = "Decor", condition = 0.0): | ||||||
|
||||||
self.category = category | ||||||
self.condition = condition | ||||||
|
||||||
def __str__(self): | ||||||
return "Something to decorate your space." | ||||||
|
||||||
def condition_description(self): | ||||||
|
||||||
if self.condition == 1: | ||||||
return "Geez, maybe put that back." | ||||||
elif self.condition == 2: | ||||||
return "Well, could be worse." | ||||||
elif self.condition == 3: | ||||||
return "What are the savings from retail value?" | ||||||
elif self.condition == 4: | ||||||
return "Almost in perfect condition" | ||||||
elif self.condition == 5: | ||||||
return "I am delighted from the sun and back" | ||||||
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. If the Clothing, Decor, and Electronics classes were written to inherit from Item, this method could go in the Item class instead and it wouldn't need to be repeated in 3 different classes. I would encourage you to take time to see if you can rewrite these classes to use inheritance. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class Electronics: | ||
|
||
def __init__(self, category = "Electronics", condition = 0.0): | ||
|
||
self.category = category | ||
self.condition = condition | ||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." | ||
|
||
def condition_description(self): | ||
|
||
if self.condition == 1: | ||
return "Geez, maybe put that back." | ||
elif self.condition == 2: | ||
return "Well, could be worse." | ||
elif self.condition == 3: | ||
return "What are the savings from retail value?" | ||
elif self.condition == 4: | ||
return "Almost in perfect condition" | ||
elif self.condition == 5: | ||
return "I am delighted from the sun and back" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
class Item: | ||
|
||
def __init__(self, category = "", condition = 0.0): | ||
|
||
self.category = category | ||
self.condition = condition | ||
|
||
def __str__(self): | ||
return "Hello World!" | ||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,96 @@ | ||||||||
# from item import Item | ||||||||
|
||||||||
class Vendor: | ||||||||
|
||||||||
def __init__(self, inventory = []): | ||||||||
self.inventory = inventory | ||||||||
|
||||||||
def add(self, item): | ||||||||
self.inventory.append(item) | ||||||||
return item | ||||||||
|
||||||||
def remove(self, item): | ||||||||
if item in self.inventory: | ||||||||
self.inventory.remove(item) | ||||||||
return item | ||||||||
|
||||||||
else: | ||||||||
return False | ||||||||
|
||||||||
def get_by_category(self, category): | ||||||||
self.category = category | ||||||||
category_list = [] | ||||||||
|
||||||||
for item in self.inventory: | ||||||||
|
||||||||
if item.category == category: | ||||||||
category_list.append(item) | ||||||||
|
||||||||
return category_list | ||||||||
|
||||||||
def swap_items(self, other, my_item, their_item): | ||||||||
|
||||||||
self.other = other | ||||||||
self.my_item = my_item | ||||||||
self.their_item = their_item | ||||||||
|
||||||||
if my_item == True and their_item == True: | ||||||||
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 will never evaluate to true so the method will never actually appropriately swap the items. |
||||||||
self.inventory.remove(my_item) | ||||||||
self.inventory.append(their_item) | ||||||||
other.inventory.append(my_item) | ||||||||
other.inventory.remove(their_item) | ||||||||
return self.inventory, bool(self.inventory) | ||||||||
|
||||||||
else: | ||||||||
return False | ||||||||
|
||||||||
def swap_first_item(self, other): | ||||||||
|
||||||||
self.other = other | ||||||||
|
||||||||
if len(self.inventory) > 0 and len(other.inventory) > 0: | ||||||||
my_first_item = self.inventory[0] | ||||||||
their_first_item = other.inventory[0] | ||||||||
|
||||||||
self.inventory[0] = their_first_item | ||||||||
other.inventory[0] = my_first_item | ||||||||
return bool(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. I'm curious to know why this is written this way. This will return true as long as the list isn't empty, and there's in if check above to already ensure the list isn't empty, so this should always return True anyway.
Suggested change
|
||||||||
|
||||||||
else: | ||||||||
return False | ||||||||
|
||||||||
def get_best_by_category(self, category): | ||||||||
|
||||||||
best_in_category = [] | ||||||||
|
||||||||
for item in self.inventory: | ||||||||
if item.category == category: | ||||||||
best_in_category.append(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. With the conditional on line 71, there's actually no need for this step. Right now the same check is happening twice.
Suggested change
|
||||||||
|
||||||||
for item in best_in_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.
Suggested change
|
||||||||
if item.category == category: | ||||||||
for condition in best_in_category: | ||||||||
if item.condition == 5.0: | ||||||||
return item | ||||||||
elif item.condition == 4.0: | ||||||||
return item | ||||||||
elif item.condition == 3.0: | ||||||||
return item | ||||||||
elif item.condition == 2.0: | ||||||||
return item | ||||||||
elif item.condition == 1.0: | ||||||||
return itme | ||||||||
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 will always return the first item in the list, no matter what. |
||||||||
else: | ||||||||
return None | ||||||||
|
||||||||
def swap_best_by_category(self, other, my_priority, their_priority): | ||||||||
|
||||||||
if my_priority not in other.inventory or their_priority not in self.inventory: | ||||||||
return False | ||||||||
else: | ||||||||
return True | ||||||||
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. There's no swapping actually happening here. If |
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
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.
Love that you did some of your own experimenting with a separate main.py file!