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
Sea Turtles - Esther Annorzie #106
Open
estherannorzie
wants to merge
17
commits into
ada-c17:master
Choose a base branch
from
estherannorzie: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.
+254
−52
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fa75748
passed wave 1 unit tests
estherannorzie 6e8bfbc
passed wave 2 unit tests
estherannorzie 6a33677
finished first test in wave 3
estherannorzie a928b5e
passed wave 3 unit tests
estherannorzie 8e4a74d
added main.py
estherannorzie 12a0b1b
passed wave 4 unit tests
estherannorzie 98c1c35
passed 4/5 wave 5 unit tests
estherannorzie 5efb5df
passed wave 5 unit tests
estherannorzie b18eae7
passed first three wave 6 tests
estherannorzie 6e65688
added some wave 6 assertions
estherannorzie f95379f
fixed some class inheritance issues
estherannorzie ed3141d
refactored tests 1-3 in wave 6
estherannorzie d90cb23
passed more 4/8 wave 6 tests
estherannorzie 5439fd7
passed all tests
estherannorzie 3612871
refactored swap_best_by_category
estherannorzie c813457
added docstrings
estherannorzie 7d074af
refactored based on instructor feedback
estherannorzie 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from swap_meet.item import Item | ||
from swap_meet.vendor import Vendor | ||
|
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,8 @@ | ||
class Clothing: | ||
pass | ||
from .item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self, condition=0): | ||
super().__init__("Clothing", condition) | ||
|
||
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,8 @@ | ||
class Decor: | ||
pass | ||
from .item import Item | ||
|
||
class Decor(Item): | ||
def __init__(self, condition=0): | ||
super().__init__("Decor", condition) | ||
|
||
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,8 @@ | ||
class Electronics: | ||
pass | ||
from .item import Item | ||
|
||
class Electronics(Item): | ||
def __init__(self, condition=0): | ||
super().__init__("Electronics", condition) | ||
|
||
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,19 @@ | ||
class Item: | ||
pass | ||
def __init__(self, category="", condition=0): | ||
self.category = category | ||
self.condition = condition | ||
|
||
def __str__(self): | ||
return "Hello World!" | ||
|
||
def condition_description(self): | ||
condition_chart = { | ||
0: "This item has been heavily used.", | ||
1: "This item has been moderately used.", | ||
2: "This item has been partially used.", | ||
3: "This item is in good condition.", | ||
4: "This item is in great condition.", | ||
5: "This item is brand new" | ||
} | ||
|
||
return condition_chart[self.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,127 @@ | ||
class Vendor: | ||
pass | ||
def __init__(self, inventory=None): | ||
self.inventory = [] if not inventory else inventory | ||
|
||
def add(self, item): | ||
"""Adds an item to the instance's inventory and returns it.""" | ||
self.inventory.append(item) | ||
return item | ||
|
||
def remove(self, item): | ||
""" | ||
Removes items from the instance's inventory. | ||
|
||
Parameter: | ||
item (str): Inventory item to be removed. | ||
|
||
Returns: | ||
Instance or bool: False if item is not in inventory, returns item | ||
otherwise. | ||
""" | ||
|
||
if item not in self.inventory: | ||
return False | ||
|
||
self.inventory.remove(item) | ||
return item | ||
|
||
def get_by_category(self, specific_category): | ||
""" | ||
Collects the items in the instance's inventory that are of a specific | ||
category. | ||
|
||
Parameters: | ||
specific_category (str): A category. | ||
|
||
Returns: | ||
category_matches (list): Items in the inventory matching the category. | ||
""" | ||
|
||
return [item for item in self.inventory | ||
if item.category == specific_category] | ||
|
||
def swap_items(self, friend, my_item, their_item): | ||
""" | ||
Swaps items in vendor's inventory and friend's inventory. | ||
|
||
Parameters: | ||
friend (class): Vendor instance of friend. | ||
my_item (str): Category the vendor wants to receive. | ||
their_item (str): Category friends wants to receive. | ||
|
||
Returns: | ||
(bool): False if swapping does not occurs, True otherwise. | ||
""" | ||
|
||
if my_item not in self.inventory or their_item not in friend.inventory: | ||
return False | ||
|
||
friend.inventory.append(my_item) | ||
self.inventory.remove(my_item) | ||
|
||
self.inventory.append(their_item) | ||
friend.inventory.remove(their_item) | ||
return True | ||
|
||
def swap_first_item(self, friend): | ||
''' | ||
Swaps the first item from a vendor's inventory and a friend's inventory. | ||
|
||
Parameter: | ||
friend (class): An instance of another Vendor. | ||
|
||
Returns: | ||
(bool): False if an item does not exist in the Vendor | ||
or the friend's inventory, | ||
True otherwise. | ||
''' | ||
if not self.inventory or not friend.inventory: | ||
return False | ||
|
||
self.inventory[0], friend.inventory[0] = friend.inventory[0], self.inventory[0] | ||
return True | ||
|
||
def get_best_by_category(self, specific_category): | ||
''' | ||
Returns the item with the best condition in a specific category. | ||
|
||
Parameters: | ||
specific_category (str): Represents a category. | ||
|
||
Returns: | ||
(instance or bool): Returns the vendor's instance of an item | ||
in a specfic category's best condition or None if not found. | ||
''' | ||
best_by_category = None | ||
highest_condition = 0 | ||
|
||
for item in self.inventory: | ||
if (item.category == specific_category and | ||
item.condition > highest_condition): | ||
best_by_category = item | ||
highest_condition = item.condition | ||
|
||
return best_by_category | ||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
''' | ||
Determines if vendor's item priority and other's item | ||
priority exists and swaps items. | ||
|
||
Parameters: | ||
other (class): The other Vendor instance. | ||
my_priority (str): The category that the Vendor wants to receive. | ||
their_priority (str): The category that the other party wants to | ||
receive. | ||
|
||
Returns: | ||
(bool): True if items are swapped, False is not. | ||
''' | ||
|
||
their_best_item = self.get_best_by_category(their_priority) | ||
my_best_item = other.get_best_by_category(my_priority) | ||
|
||
if not their_best_item or not my_best_item: | ||
return False | ||
|
||
return self.swap_items(other, their_best_item, my_best_item) |
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 |
---|---|---|
|
@@ -2,12 +2,12 @@ | |
import pytest | ||
from swap_meet.vendor import Vendor | ||
|
||
@pytest.mark.skip | ||
# @pytest.mark.skip | ||
def test_vendor_has_inventory(): | ||
vendor = Vendor() | ||
assert len(vendor.inventory) == 0 | ||
|
||
@pytest.mark.skip | ||
# @pytest.mark.skip | ||
def test_vendor_takes_optional_inventory(): | ||
inventory = ["a", "b", "c"] | ||
vendor = Vendor(inventory=inventory) | ||
|
@@ -16,7 +16,7 @@ def test_vendor_takes_optional_inventory(): | |
assert "b" in vendor.inventory | ||
assert "c" in vendor.inventory | ||
|
||
@pytest.mark.skip | ||
# @pytest.mark.skip | ||
def test_adding_to_inventory(): | ||
vendor = Vendor() | ||
item = "new item" | ||
|
@@ -27,7 +27,7 @@ def test_adding_to_inventory(): | |
assert item in vendor.inventory | ||
assert result == item | ||
|
||
@pytest.mark.skip | ||
# @pytest.mark.skip | ||
def test_removing_from_inventory_returns_item(): | ||
item = "item to remove" | ||
vendor = Vendor( | ||
|
@@ -40,7 +40,7 @@ def test_removing_from_inventory_returns_item(): | |
assert item not in vendor.inventory | ||
assert result == item | ||
|
||
@pytest.mark.skip | ||
# @pytest.mark.skip | ||
def test_removing_not_found_is_false(): | ||
item = "item to remove" | ||
vendor = Vendor( | ||
|
@@ -49,7 +49,10 @@ 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 len(vendor.inventory) == 3 | ||
assert item not in vendor.inventory | ||
assert result == False | ||
Comment on lines
+56
to
+58
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 checks for all the relevant data! |
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.
Great code reuse!