-
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
Rock - Priscille #50
base: master
Are you sure you want to change the base?
Rock - Priscille #50
Changes from all commits
6127970
9e9c5ea
f538c53
ca88e94
af83c73
8fb9fab
73c8d7d
2d14431
3dfd13f
1e6a3f2
577442e
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,9 @@ | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self, category="Clothing", condition=0, age=0): | ||
super().__init__(category, condition, age) | ||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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. 👍 We can do the same thing here as we did above! |
||
|
||
def __init__(self, category="Decor", condition=0, age=0): | ||
super().__init__(category, condition, age) | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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. 👍 We can do the same thing here as we did above! |
||
|
||
def __init__(self, category="Electronics", condition=0, age=0): | ||
super().__init__(category, condition, age) | ||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,39 @@ | ||||||||||||||||||||||||||||||||||||
class Item: | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
def __init__(self, category = "", condition = 0, age = 0): | ||||||||||||||||||||||||||||||||||||
if category is None: | ||||||||||||||||||||||||||||||||||||
self.category = "" | ||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||
self.category = category | ||||||||||||||||||||||||||||||||||||
if condition is None: | ||||||||||||||||||||||||||||||||||||
self.condition = 0 | ||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||
self.condition = condition | ||||||||||||||||||||||||||||||||||||
if age is None: | ||||||||||||||||||||||||||||||||||||
self.age = 0 | ||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||
self.age = age | ||||||||||||||||||||||||||||||||||||
Comment on lines
+3
to
+15
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 works good! But our default parameters, like
Suggested change
now category will be assigned |
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
def __str__(self): | ||||||||||||||||||||||||||||||||||||
return "Hello World!" | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
def condition_description(self): | ||||||||||||||||||||||||||||||||||||
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 self.condition == 0: | ||||||||||||||||||||||||||||||||||||
return "Poor" | ||||||||||||||||||||||||||||||||||||
elif self.condition == 1: | ||||||||||||||||||||||||||||||||||||
return "Fair" | ||||||||||||||||||||||||||||||||||||
elif self.condition == 2: | ||||||||||||||||||||||||||||||||||||
return "Good" | ||||||||||||||||||||||||||||||||||||
elif self.condition == 3: | ||||||||||||||||||||||||||||||||||||
return "Very good" | ||||||||||||||||||||||||||||||||||||
elif self.condition == 4: | ||||||||||||||||||||||||||||||||||||
return "Like new" | ||||||||||||||||||||||||||||||||||||
elif self.condition == 5: | ||||||||||||||||||||||||||||||||||||
return "Brand new" | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,97 @@ | ||||||||||
from swap_meet.item import Item | ||||||||||
|
||||||||||
class 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. 👍 |
||||||||||
|
||||||||||
def __init__(self, inventory = None): | ||||||||||
if inventory is None: | ||||||||||
self.inventory = [] | ||||||||||
else: | ||||||||||
self.inventory = inventory | ||||||||||
Comment on lines
+5
to
+9
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 time the if statement is necessary! we shouldn't use lists and dictionaries as default parameters because then all instances of Vendor would use the same list or dictionary in our memory space. But with the if-else statement, we an make sure that each instance gets its own unique and independent list! perfect! |
||||||||||
|
||||||||||
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. 👍 |
||||||||||
self.inventory.append(item) | ||||||||||
return item | ||||||||||
|
||||||||||
def remove(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. 👍 |
||||||||||
if item in self.inventory: | ||||||||||
self.inventory.remove(item) | ||||||||||
return item | ||||||||||
return False | ||||||||||
|
||||||||||
def get_by_category(self, category_name): | ||||||||||
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. 👍 |
||||||||||
items = [] | ||||||||||
for item in self.inventory: | ||||||||||
if category_name == item.category: | ||||||||||
items.append(item) | ||||||||||
return items | ||||||||||
|
||||||||||
def swap_items(self, vendor_friend, 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. 👍 |
||||||||||
if my_item not in self.inventory or their_item not in vendor_friend.inventory: | ||||||||||
return False | ||||||||||
else: | ||||||||||
self.remove(my_item) | ||||||||||
vendor_friend.remove(their_item) | ||||||||||
vendor_friend.add(my_item) | ||||||||||
self.add(their_item) | ||||||||||
return True | ||||||||||
|
||||||||||
def swap_first_item(self, vendor_friend): | ||||||||||
if len(self.inventory) == 0 or len(vendor_friend.inventory) == 0: | ||||||||||
return False | ||||||||||
else: | ||||||||||
item_a = self.inventory[0] | ||||||||||
item_d = vendor_friend.inventory[0] | ||||||||||
result = self.swap_items(vendor_friend, item_a, item_d) | ||||||||||
Comment on lines
+42
to
+44
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. we could get rid of these two variables if we wanted!
Suggested change
|
||||||||||
return result | ||||||||||
|
||||||||||
def get_best_by_category(self, category_name): | ||||||||||
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. 👍 |
||||||||||
highest_condition = 0 | ||||||||||
best_item = None | ||||||||||
|
||||||||||
for item in self.get_by_category(category_name): | ||||||||||
if item.condition > highest_condition: | ||||||||||
highest_condition = item.condition | ||||||||||
best_item = 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. 👍 |
||||||||||
my_best_item = self.get_best_by_category(their_priority) | ||||||||||
their_best_item = other.get_best_by_category(my_priority) | ||||||||||
result = self.swap_items(other, my_best_item, their_best_item) | ||||||||||
return result | ||||||||||
|
||||||||||
# Optional Enhancements: item by age | ||||||||||
|
||||||||||
def get_newest_item(self): | ||||||||||
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. 👍 |
||||||||||
lowest_value = self.inventory[0].age | ||||||||||
newest_item = None | ||||||||||
for item in self.inventory: | ||||||||||
if item.age < lowest_value: | ||||||||||
lowest_value = item.age | ||||||||||
newest_item = item | ||||||||||
return newest_item | ||||||||||
|
||||||||||
def swap_by_newest(self, business_partner, my_newest_item, their_newest_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. 👍 |
||||||||||
|
||||||||||
if len(self.inventory) == 0 or len(business_partner.inventory) == 0: | ||||||||||
return False | ||||||||||
else: | ||||||||||
my_newest_item = self.get_newest_item() | ||||||||||
their_newest_item = business_partner.get_newest_item() | ||||||||||
result = self.swap_items(business_partner, my_newest_item, their_newest_item) | ||||||||||
return result | ||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import pytest | ||
from swap_meet.vendor import Vendor | ||
from swap_meet.item import Item | ||
from swap_meet.electronics import Electronics | ||
|
||
def test_get_newest_item(): | ||
item_a = Item(age = 3) | ||
item_b = Item(age = 1) | ||
item_c = Item(age = 2) | ||
fatimah = Vendor( | ||
inventory=[item_a, item_b, item_c] | ||
) | ||
newest_item = fatimah.get_newest_item() | ||
|
||
assert newest_item.age == pytest.approx(1.0) | ||
|
||
|
||
def test_get_newest_item_with_duplicates(): | ||
item_a = Item(age = 3) | ||
item_b = Item(age = 1) | ||
item_c = Item(age = 1) | ||
fatimah = Vendor( | ||
inventory=[item_a, item_b, item_c] | ||
) | ||
newest_item = fatimah.get_newest_item() | ||
|
||
assert newest_item.age == pytest.approx(1.0) | ||
|
||
def test_swap_by_newest(): | ||
item_a = Item(age = 3) | ||
item_b = Item(age = 1) | ||
item_c = Item(age = 2) | ||
fatimah = Vendor( | ||
inventory=[item_a, item_b, item_c] | ||
) | ||
|
||
item_d = Item(age = 4) | ||
item_e = Item(age = 5) | ||
item_f = Item(age = 2) | ||
jolie = Vendor( | ||
inventory=[item_d, item_e, item_f] | ||
) | ||
|
||
result = fatimah.swap_by_newest( | ||
business_partner = jolie, | ||
my_newest_item = item_b, | ||
their_newest_item = item_f) | ||
|
||
assert result is True | ||
assert len(fatimah.inventory) is 3 | ||
assert len(jolie.inventory) is 3 | ||
assert item_b not in fatimah.inventory | ||
assert item_f in fatimah.inventory | ||
assert item_f not in jolie.inventory | ||
assert item_b in jolie.inventory | ||
|
||
def test_swap_by_newest_from_my_empty_returns_false(): | ||
fatimah = Vendor( | ||
inventory=[] | ||
) | ||
|
||
item_d = Item(age = 4) | ||
item_e = Item(age = 5) | ||
item_f = Item(age = 2) | ||
jolie = Vendor( | ||
inventory=[item_d, item_e, item_f] | ||
) | ||
|
||
nobodys_item = Item(age = 3) | ||
|
||
result = fatimah.swap_by_newest(jolie, nobodys_item, item_f) | ||
|
||
assert len(fatimah.inventory) is 0 | ||
assert len(jolie.inventory) is 3 | ||
assert result is False | ||
|
||
def test_swap_by_newest_from_their_empty_returns_false(): | ||
item_a = Item(age = 3) | ||
item_b = Item(age = 1) | ||
item_c = Item(age = 2) | ||
fatimah = Vendor( | ||
inventory=[item_a, item_b, item_c] | ||
) | ||
|
||
jolie = Vendor( | ||
inventory=[] | ||
) | ||
|
||
nobodys_item = Item(age = 3) | ||
|
||
result = fatimah.swap_by_newest(jolie, item_b, nobodys_item) | ||
|
||
assert len(fatimah.inventory) is 3 | ||
assert len(jolie.inventory) is 0 | ||
assert result is False |
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.
👍 this works perfectly! But it still lets the user change the category, and we don't want that. class Clothing will always have the category "clothing." So let's try this: