-
Notifications
You must be signed in to change notification settings - Fork 110
Puja Mukherjee-Lions #82
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
base: master
Are you sure you want to change the base?
Changes from all commits
4675213
f1b025b
778e4ef
2f37f64
c3df7cb
b806870
c893a33
3f6b3a4
098efbc
b778456
032ed1e
abf3b82
c442e4d
cf1b0ba
ed788ea
54570a8
d0f2949
6bc03df
9a8678c
198a606
ace8d39
50c0a93
5b15ba6
59e8c24
c0c76d1
1209751
eb4888f
4232ec1
5ec9729
2200d76
e5ac082
904122a
96c1587
be80bbb
54f3c9c
7936689
8530a72
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,14 @@ | ||
class Clothing: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self, category = "",condition = 0): | ||
super().__init__(category = "Clothing", condition = condition) | ||
|
||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." | ||
|
||
|
||
|
||
|
||
|
||
Comment on lines
+8
to
+14
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. Please delete empty lines at the end of your file. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
class Decor: | ||
pass | ||
from swap_meet.item import Item | ||
class Decor(Item): | ||
def __init__(self, category = "",condition = 0): | ||
super().__init__(category = "Decor", condition = condition) | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
class Electronics: | ||
pass | ||
from swap_meet.item import Item | ||
class Electronics(Item): | ||
def __init__(self, category = "", condition = 0): | ||
super().__init__(category = "Electronics", condition = 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,22 @@ | ||
class Item: | ||
pass | ||
def __init__(self, age = 0, category = "", condition = 0): | ||
self.category = category | ||
self.condition = condition | ||
self.age = age | ||
|
||
# Wave 3 | ||
def __str__(self): | ||
return "Hello World!" | ||
|
||
# Wave 5 | ||
def condition_description(self): | ||
condition_descriptions = ["I dont like zero", "I dont like one either", | ||
"Maybe I like two", "Hmmmm.....probably three is nice", "I like four", | ||
"Five is a nice number"] | ||
return condition_descriptions[self.condition] | ||
Comment on lines
+12
to
+16
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 if the condition is an integer, but what would happen if it were a float? (Some of the test data shows the condition as |
||
|
||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,98 @@ | ||
class Vendor: | ||
pass | ||
MAX_AGE = 1000 | ||
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. What would happen if we had a dinosaur fossil that was more than a thousand years old? To accommodate this case, we can set our max age to infinity using |
||
# Wave 1 | ||
def __init__(self, inventory = None): | ||
if inventory is None: | ||
inventory = [] | ||
self.inventory = inventory | ||
def add(self,item): | ||
self.inventory.append(item) | ||
return item | ||
def remove(self,item): | ||
for inventory_item in self.inventory: | ||
if inventory_item == item: | ||
self.inventory.remove(item) | ||
return item | ||
return False | ||
|
||
# Wave 2 | ||
def get_by_category(self, category): | ||
item_list = [] | ||
for item in self.inventory: | ||
if item.category == category: | ||
item_list.append(item) | ||
return item_list | ||
Comment on lines
+19
to
+24
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. Really nicely done! As an alternative, can you consider how this could be done using a list comprehension? Which method do you prefer? |
||
|
||
# Wave 3 | ||
def swap_items(self, friend_vendor, my_item, their_item): | ||
if my_item not in self.inventory or their_item not in friend_vendor.inventory: | ||
return False | ||
|
||
self.remove(my_item) | ||
friend_vendor.add(my_item) | ||
friend_vendor.remove(their_item) | ||
self.add(their_item) | ||
return True | ||
Comment on lines
+27
to
+35
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. Nice re-use of your instance methods! |
||
|
||
|
||
# Wave 4 | ||
def swap_first_item(self, friend_vendor): | ||
if len(self.inventory) == 0 or len(friend_vendor.inventory) == 0: | ||
return False | ||
|
||
return self.swap_items(friend_vendor, self.inventory[0], | ||
friend_vendor.inventory[0]) | ||
|
||
|
||
# Wave 6 | ||
|
||
def get_best_by_category(self, category): | ||
matching_category_items = self.get_by_category(category) | ||
highest_condition = 0 | ||
highest_item = None | ||
for item in matching_category_items: | ||
if item.condition > highest_condition: | ||
highest_condition = item.condition | ||
highest_item = item | ||
return highest_item | ||
Comment on lines
+49
to
+57
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 great! Can you consider how you would do this using |
||
|
||
|
||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
my_best_item = self.get_best_by_category(their_priority) | ||
their_best_item = other.get_best_by_category(my_priority) | ||
if my_best_item == None or their_best_item == None: | ||
return False | ||
return self.swap_items(other, my_best_item, their_best_item) | ||
Comment on lines
+61
to
+66
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. Really nice use of helpers! Small note, please use |
||
|
||
|
||
# Optional Enhancement | ||
def find_newest_item (self): | ||
min_item_age = self.MAX_AGE | ||
min_item = None | ||
for item in self.inventory: | ||
if item.age < min_item_age: | ||
min_item_age = item.age | ||
min_item = item | ||
return min_item | ||
|
||
def swap_by_newest(self, friend_vendor): | ||
vendor_newest_item = self.find_newest_item() | ||
friend_newest_item = friend_vendor.find_newest_item() | ||
return self.swap_items(friend_vendor, vendor_newest_item, friend_newest_item) | ||
Comment on lines
+79
to
+82
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 extra functionality! |
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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,12 @@ 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_c not in items | ||
assert item_b not in items | ||
Comment on lines
+37
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. This works, but we can make it simpler by removing lines 38-40. If the length of |
||
|
||
# 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.
Nice use of super! Here, it would be a good idea to not have
category
be a parameter in theClothing
constructor. We know that we always wantcategory
to be"Clothing"
, so we shouldn't give the caller the illusion that they can change it.Also a small style note: when using default/named parameters, do not put spaces before or after the equals sign. It should instead look like this:
condition=0
.