-
Notifications
You must be signed in to change notification settings - Fork 113
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
Ada c17 whales-Nishat Salsabil #96
base: master
Are you sure you want to change the base?
Changes from all commits
e24c3ff
52b046c
96ce532
2b17bcd
8381b60
9f995c2
7af280d
1234741
c02f9f3
69ccf14
afb90ef
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,9 @@ | ||
class Clothing: | ||
pass | ||
from .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 |
---|---|---|
@@ -1,2 +1,9 @@ | ||
class Decor: | ||
pass | ||
from .item import Item | ||
|
||
class Decor(Item): | ||
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 |
---|---|---|
@@ -1,2 +1,9 @@ | ||
class Electronics: | ||
pass | ||
from .item import Item | ||
|
||
class Electronics(Item): | ||
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 |
---|---|---|
@@ -1,2 +1,31 @@ | ||
class Item: | ||
pass | ||
def __init__(self, category = None, condition = 0, age = 0): | ||
if not category: | ||
category = "" | ||
self.category = category | ||
self.condition = condition | ||
self.age = age | ||
|
||
|
||
def __str__(self): | ||
return "Hello World!" | ||
|
||
|
||
def age_statement(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. Nice addition of an age statement! |
||
return f"This item was made {self.age} months ago." | ||
|
||
|
||
def condition_description(self): | ||
if self.condition == 0: | ||
description = "horrendous quality" | ||
elif self.condition == 1: | ||
description = "terrible quality" | ||
elif self.condition == 2: | ||
description = "bad quality" | ||
elif self.condition == 3: | ||
description = "decent quality" | ||
elif self.condition == 4: | ||
description = "great quality" | ||
elif self.condition == 5: | ||
description = "exquisite quality" | ||
return f"This item's condition is {description}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,102 @@ | ||
class Vendor: | ||
pass | ||
def __init__(self, inventory = None): | ||
if not inventory: | ||
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 | ||
return False | ||
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 use of short-circuiting and returning |
||
|
||
|
||
def get_by_category(self, category): | ||
inventory_by_category = [] | ||
for item in self.inventory: | ||
if item.category == category: | ||
inventory_by_category.append(item) | ||
return inventory_by_category | ||
|
||
|
||
def swap_items(self, other_vendor, my_item, their_item): | ||
if my_item in self.inventory and their_item in other_vendor.inventory: | ||
other_vendor.add(my_item) | ||
self.remove(my_item) | ||
self.add(their_item) | ||
other_vendor.remove(their_item) | ||
return True | ||
return False | ||
|
||
|
||
def swap_first_item(self, other_vendor): | ||
try: | ||
my_item = self.inventory[0] | ||
their_item = other_vendor.inventory[0] | ||
first_items = self.swap_items(other_vendor, my_item, their_item) | ||
return first_items | ||
except IndexError: | ||
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. Wonderful try-except and catching |
||
return False | ||
|
||
|
||
def get_best_by_category(self, category): | ||
max_condition = 0 | ||
max_item = None | ||
for item in self.inventory: | ||
if item.condition > max_condition and item.category == category: | ||
max_condition = item.condition | ||
max_item = item | ||
return max_item | ||
|
||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
my_item = other.get_best_by_category(my_priority) | ||
their_item = self.get_best_by_category(their_priority) | ||
return self.swap_items(other, their_item, my_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. Great use of helper functions to DRY your code! |
||
|
||
|
||
|
||
############### Optional Enhancement for Wave 07 ############### | ||
def get_newest_item(self): | ||
newest_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. Clever! We could also use something like |
||
newest_item = None | ||
for item in self.inventory: | ||
if item.age < newest_age: | ||
newest_age = item.age | ||
newest_item = item | ||
return newest_item | ||
|
||
|
||
def swap_by_newest(self, other, my_item, their_item): | ||
their_item = self.get_newest_item() | ||
my_item = other.get_newest_item() | ||
return self.swap_items(other, their_item, my_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. Again, great use of helper functions to DRY your code! |
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,14 @@ | |
import pytest | ||
from swap_meet.vendor import Vendor | ||
|
||
@pytest.mark.skip | ||
# Test 1 | ||
#@pytest.mark.skip | ||
def test_vendor_has_inventory(): | ||
vendor = Vendor() | ||
assert len(vendor.inventory) == 0 | ||
|
||
@pytest.mark.skip | ||
# Test 2 | ||
#@pytest.mark.skip | ||
def test_vendor_takes_optional_inventory(): | ||
inventory = ["a", "b", "c"] | ||
vendor = Vendor(inventory=inventory) | ||
|
@@ -16,18 +18,19 @@ def test_vendor_takes_optional_inventory(): | |
assert "b" in vendor.inventory | ||
assert "c" in vendor.inventory | ||
|
||
@pytest.mark.skip | ||
# Test 3 | ||
#@pytest.mark.skip | ||
def test_adding_to_inventory(): | ||
vendor = Vendor() | ||
item = "new item" | ||
|
||
result = vendor.add(item) | ||
|
||
assert len(vendor.inventory) == 1 | ||
assert item in vendor.inventory | ||
assert result == item | ||
|
||
@pytest.mark.skip | ||
# Test 4 | ||
#@pytest.mark.skip | ||
def test_removing_from_inventory_returns_item(): | ||
item = "item to remove" | ||
vendor = Vendor( | ||
|
@@ -39,8 +42,10 @@ def test_removing_from_inventory_returns_item(): | |
assert len(vendor.inventory) == 3 | ||
assert item not in vendor.inventory | ||
assert result == item | ||
|
||
|
||
@pytest.mark.skip | ||
# Test 5 | ||
#@pytest.mark.skip | ||
def test_removing_not_found_is_false(): | ||
item = "item to remove" | ||
vendor = Vendor( | ||
|
@@ -49,7 +54,7 @@ def test_removing_not_found_is_false(): | |
|
||
result = vendor.remove(item) | ||
|
||
raise Exception("Complete this test according to comments below.") | ||
#raise Exception("Complete this test according to comments below.") | ||
# ********************************************************************* | ||
# ****** Complete Assert Portion of this test ********** | ||
assert result == False | ||
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; another "pythonic" and and human-readable way to express this is |
||
# ********************************************************************* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,14 @@ | |
from swap_meet.vendor import Vendor | ||
from swap_meet.item import Item | ||
|
||
@pytest.mark.skip | ||
# Test 6 | ||
#@pytest.mark.skip | ||
def test_items_have_blank_default_category(): | ||
item = Item() | ||
assert item.category == "" | ||
|
||
@pytest.mark.skip | ||
# Test 7 | ||
#@pytest.mark.skip | ||
def test_get_items_by_category(): | ||
item_a = Item(category="clothing") | ||
item_b = Item(category="electronics") | ||
|
@@ -23,7 +25,8 @@ def test_get_items_by_category(): | |
assert item_c in items | ||
assert item_b not in items | ||
|
||
@pytest.mark.skip | ||
# Test 8 | ||
#@pytest.mark.skip | ||
def test_get_no_matching_items_by_category(): | ||
item_a = Item(category="clothing") | ||
item_b = Item(category="clothing") | ||
|
@@ -34,7 +37,8 @@ def test_get_no_matching_items_by_category(): | |
|
||
items = vendor.get_by_category("electronics") | ||
|
||
raise Exception("Complete this test according to comments below.") | ||
#raise Exception("Complete this test according to comments below.") | ||
# ********************************************************************* | ||
# ****** Complete Assert Portion of this test ********** | ||
assert items == [] | ||
assert len(items) == 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. 👍🏻 |
||
# ********************************************************************* |
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.
If we don't specify a category, it will be
None
because ofcategory = None
in the constructor!