Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions main.py
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")
Comment on lines +2 to +14

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!

23 changes: 23 additions & 0 deletions swap_meet/clothing.py
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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love these :D

22 changes: 22 additions & 0 deletions swap_meet/decor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Decor:

Choose a reason for hiding this comment

The 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
class Decor:
class Decor(Item):


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"

Choose a reason for hiding this comment

The 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.

22 changes: 22 additions & 0 deletions swap_meet/electronics.py
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"
14 changes: 14 additions & 0 deletions swap_meet/item.py
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!"




96 changes: 96 additions & 0 deletions swap_meet/vendor.py
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:

Choose a reason for hiding this comment

The 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)

Choose a reason for hiding this comment

The 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
return bool(self.inventory)
return True


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)

Choose a reason for hiding this comment

The 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 self.inventory:
if item.category == category:
best_in_category.append(item)


for item in best_in_category:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for item in best_in_category:
for item in self.inventory:

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

Choose a reason for hiding this comment

The 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.
I'd encourage you to run the tests with the debugger and seek to understand how this is working and why it isn't doing what you intended.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no swapping actually happening here. If swap_items were rewritten to work properly, we could make use of that method by calling it from here.