forked from AdaGold/swap-meet
-
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
C17 Whales Morgan Adkisson #91
Open
MorganAdkisson
wants to merge
13
commits into
ada-c17:master
Choose a base branch
from
MorganAdkisson:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
110b272
Oooops forgot to commit updates... updated vendor and item classes, p…
MorganAdkisson 9ea6bf5
deleted 1 accidental and 1 unnecessary import from vendor.py
MorganAdkisson af510a3
use __str__ method to make Item return the default str 'Hello World!'…
MorganAdkisson 6ad5a8c
unsaved Vendor file during last push
MorganAdkisson f7d2a11
wrote Vendor method swap_first_item and passed all tests in wave 04
MorganAdkisson 3816427
create new classes (as new instances of Item) Clothing, Decor, Electr…
MorganAdkisson 5032273
wrote condition_description method in Item to be inherited by all ins…
MorganAdkisson b72885b
created class method get_best_category and passed tests 1 - 3 in wave 06
MorganAdkisson e0bde7b
conpleted swap_best_by_category and passed remaining tests in wave 06…
MorganAdkisson f1f1eb2
refactored condition_description in Item class to fix bug and achieve…
MorganAdkisson f478e25
optional enhancements: created get_newest_by_category helper function…
MorganAdkisson 3bdc13f
general refactoring for final submission
MorganAdkisson e3ad58e
fixed bug in Vendor class that was keeping integration tests from run…
MorganAdkisson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
class Clothing: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
"""A child class of Item, representing aspects of an Item specific to Clothing""" | ||
def __init__(self, category="Clothing", condition=0.0, age=None): | ||
self.category = category | ||
self.condition = condition | ||
self.age = age | ||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
class Decor: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
"""A child class of Item, representing aspects of an Item specific to Decor""" | ||
def __init__(self, category="Decor", condition=0.0, age=None): | ||
self.category = category | ||
self.condition = condition | ||
self.age = age | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
class Electronics: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Electronics(Item): | ||
"""A child class of Item, representing aspects of an Item specific to Electronics""" | ||
def __init__(self, category="Electronics", condition=0.0, age=None): | ||
self.category = category | ||
self.condition = condition | ||
self.age = age | ||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,22 @@ | ||
class Item: | ||
pass | ||
|
||
def __init__(self, category="", condition=0.0, age=None): | ||
self.category = category | ||
self.condition = condition | ||
self.age = age | ||
|
||
def __str__(self): | ||
return "Hello World!" | ||
|
||
def condition_description(self): | ||
condition = int(self.condition) | ||
descriptions = { | ||
0: 'You should probably pass on this one...', | ||
1: 'Poor', | ||
2: 'Meh', | ||
3: 'Good', | ||
4: 'Great', | ||
5: 'Brand spankin new' | ||
} | ||
Comment on lines
+13
to
+20
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. Using a dictionary for this is really clean. 😃 |
||
return descriptions[condition] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,88 @@ | ||
from swap_meet.item import Item | ||
|
||
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 not in self.inventory: | ||
return False | ||
self.inventory.remove(item) | ||
return item | ||
|
||
def get_by_category(self, category_str): | ||
category_items = [] | ||
for item in self.inventory: | ||
if item.category == category_str: | ||
category_items.append(item) | ||
return category_items | ||
|
||
def swap_items(self, swap_vendor, my_item, their_item): | ||
if my_item in self.inventory and their_item in swap_vendor.inventory: | ||
self.remove(my_item) | ||
swap_vendor.add(my_item) | ||
self.add(their_item) | ||
swap_vendor.remove(their_item) | ||
return True | ||
return False | ||
|
||
def swap_first_item(self, other): | ||
if len(self.inventory) >= 1 and len(other.inventory) >= 1: | ||
self_first_item = self.inventory[0] | ||
other_first_item = other.inventory[0] | ||
self.inventory[0] = other_first_item | ||
other.inventory[0] = self_first_item | ||
return True | ||
return False | ||
|
||
def get_best_by_category(self, category_str): | ||
category_items = self.get_by_category(category_str) | ||
if len(category_items) > 1: | ||
best_item = category_items[0] | ||
else: | ||
return None | ||
|
||
for item in category_items: | ||
if item.condition > best_item.condition: | ||
best_item = item | ||
return best_item | ||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
my_best_swap = self.get_best_by_category(their_priority) | ||
their_best_swap = other.get_best_by_category(my_priority) | ||
|
||
if my_best_swap and their_best_swap: | ||
self.swap_items(other, my_best_swap, their_best_swap) | ||
return True | ||
return False | ||
|
||
def get_newest_by_category(self, category_str): | ||
"""optional enhancement: helper function to get newest item by category to pass to swap_by_newest""" | ||
category_items = self.get_by_category(category_str) | ||
if len(category_items) > 1: | ||
newest_item = category_items[0] | ||
else: | ||
return None | ||
|
||
for item in category_items: | ||
if item.age < newest_item.age: | ||
newest_item = item | ||
|
||
return newest_item | ||
|
||
def swap_newest_by_category(self, other, my_priority, their_priority): | ||
"""optional enhancement: swaps newest item of certain categories with another Vendor""" | ||
my_newest_swap = self.get_newest_by_category(their_priority) | ||
their_newest_swap = other.get_newest_by_category(my_priority) | ||
|
||
if my_newest_swap and their_newest_swap: | ||
self.swap_items(other, my_newest_swap, their_newest_swap) | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import pytest | ||
from swap_meet.vendor import Vendor | ||
from swap_meet.clothing import Clothing | ||
from swap_meet.decor import Decor | ||
from swap_meet.electronics import Electronics | ||
|
||
def test_clothing_has_age_default_None(): | ||
clothing = Clothing() | ||
assert clothing.age == None | ||
|
||
def test_decor_has_age_default_None(): | ||
decor = Decor() | ||
assert decor.age == None | ||
|
||
def test_electronics_has_age_default_None(): | ||
electronics = Electronics() | ||
assert electronics.age == None | ||
|
||
def test_newest_by_category(): | ||
item_a = Clothing(age=2) | ||
item_b = Decor(age=1) | ||
item_c = Clothing(age=5) | ||
ryan = Vendor(inventory=[item_a, item_b, item_c]) | ||
|
||
newest_item = ryan.get_newest_by_category("Clothing") | ||
|
||
assert newest_item.age == 2 | ||
assert newest_item.category == "Clothing" | ||
|
||
def test_newest_by_category_no_matches_is_none(): | ||
item_a = Electronics(age=3) | ||
item_b = Decor(age=7) | ||
item_c = Decor(age=5) | ||
tara = Vendor(inventory=[item_a, item_b, item_c]) | ||
|
||
newest_item = tara.get_newest_by_category("Clothing") | ||
|
||
assert newest_item == None | ||
|
||
def test_newest_by_category_with_duplicates(): | ||
item_a = Clothing(age=2) | ||
item_b = Clothing(age=2) | ||
item_c = Clothing(age=4) | ||
robin = Vendor(inventory=[item_a, item_b, item_c]) | ||
|
||
newest_item = robin.get_newest_by_category("Clothing") | ||
|
||
assert newest_item.age == 2 | ||
assert newest_item.category == "Clothing" | ||
|
||
def test_swap_newest_by_category(): | ||
item_a = Decor(age=9) | ||
item_b = Clothing(age=2) | ||
item_c = Decor(age=3) | ||
thomas = Vendor(inventory=[item_a, item_b, item_c]) | ||
|
||
item_d = Electronics(age=3) | ||
item_e = Decor(age=3) | ||
item_f = Electronics(age=1) | ||
stevie = Vendor(inventory=[item_d, item_e, item_f]) | ||
|
||
result = thomas.swap_newest_by_category( | ||
other=stevie, | ||
my_priority="Electronics", | ||
their_priority="Decor" | ||
) | ||
|
||
assert result is True | ||
assert len(thomas.inventory) == 3 | ||
assert len(stevie.inventory) == 3 | ||
assert item_c in stevie.inventory | ||
assert item_f in thomas.inventory | ||
|
||
def test_swap_newest_by_category_no_inventory_is_false(): | ||
item_a = Clothing(age=9) | ||
item_b = Clothing(age=2) | ||
item_c = Clothing(age=3) | ||
charlotte = Vendor(inventory=[item_a, item_b, item_c]) | ||
|
||
item_d = Electronics(age=3) | ||
item_e = Decor(age=3) | ||
item_f = Electronics(age=1) | ||
parker = Vendor(inventory=[item_d, item_e, item_f]) | ||
|
||
result = charlotte.swap_newest_by_category( | ||
other=parker, | ||
my_priority="Decor", | ||
their_priority="Electronics" | ||
) | ||
|
||
assert result is False | ||
assert len(charlotte.inventory) == 3 | ||
assert len(parker.inventory) == 3 | ||
for item in charlotte.inventory: | ||
assert item.category != "Electronics" | ||
|
||
def test_swap_newest_by_category_no_other_inventory_is_false(): | ||
item_a = Decor(age=3) | ||
item_b = Electronics(age=1) | ||
item_c = Clothing(age=5) | ||
sage = Vendor(inventory=[item_a, item_b, item_c]) | ||
|
||
audrey = Vendor(inventory=[]) | ||
|
||
result = sage.swap_newest_by_category( | ||
other=audrey, | ||
my_priority="Decor", | ||
their_priority="Clothing" | ||
) | ||
|
||
assert not result | ||
assert len(sage.inventory) == 3 | ||
assert len(audrey.inventory) == 0 | ||
assert item_a in sage.inventory | ||
assert item_b in sage.inventory | ||
assert item_c in sage.inventory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
category
probably shouldn't be a parameter here since we don't want it to differ for different instances: