-
Notifications
You must be signed in to change notification settings - Fork 103
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
Ruby - Mikayla H #84
base: main
Are you sure you want to change the base?
Ruby - Mikayla H #84
Changes from all commits
de18297
024c0ae
5815cab
ed8372f
59c43e2
eaa357b
ee3c09d
8e44891
1089237
d245ba0
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,17 @@ | ||
class Clothing: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self, id=None, fabric="Unknown", condition = 0): | ||
self.fabric = fabric | ||
# self.condition = condition | ||
super().__init__(id, condition) | ||
|
||
|
||
def get_category(self): | ||
return "Clothing" | ||
Comment on lines
+10
to
+11
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 method is not necessary! The |
||
|
||
def __str__(self): | ||
return f"An object of type Clothing with id {self.id}. It is made from {self.fabric} fabric." | ||
|
||
def condition_description(self): | ||
return super().condition_description() | ||
Comment on lines
+16
to
+17
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 the only thing you're doing is calling the super, then you don't need to override the method! If Python sees that the Clothing class does not have a |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
class Decor: | ||
pass | ||
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. Excellent! |
||
def __init__(self, id=None, width=0, length=0, condition = 0): | ||
self.width = width | ||
self.length = length | ||
# self.condition = condition | ||
super().__init__(id, condition) | ||
|
||
|
||
def get_category(self): | ||
return "Decor" | ||
|
||
def __str__(self): | ||
return f'An object of type Decor with id {self.id}. It takes up a {self.width} by {self.length} sized space.' | ||
|
||
def condition_description(self): | ||
return super().condition_description() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,16 @@ | ||
class Electronics: | ||
pass | ||
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. Excellent! |
||
def __init__(self, id=None, type="Unknown", condition = 0): | ||
self.type = type | ||
# self.condition = condition | ||
super().__init__(id, condition) | ||
|
||
def get_category(self): | ||
return "Electronics" | ||
|
||
def __str__(self): | ||
return f'An object of type Electronics with id {self.id}. This is a {self.type} device.' | ||
|
||
def condition_description(self): | ||
return super().condition_description() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,37 @@ | ||
import uuid | ||
|
||
class 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. Excellent! |
||
pass | ||
# Each item will have an attribute named id | ||
#initialize an instance of item optionally pass in an int | ||
def __init__(self, id=None, condition=0): | ||
if id is None: | ||
# func provides unique numbers to be used to id | ||
# create a unique int | ||
self.id = uuid.uuid4().int | ||
else: | ||
self.id = id | ||
self.condition = condition | ||
|
||
def get_category(self): | ||
# return a string holding the name of the class | ||
return self.__class__.__name__ | ||
|
||
def __str__(self): | ||
return f"An object of type Item with id {self.id}." | ||
|
||
def condition_description(self): | ||
# condition = {0:'Trendy', 1: 'heavily used', 2:'incredible', 3:'outrageous', 4:'cute', 5:'ugly'} | ||
|
||
if self.condition == 0: | ||
return 'Trendy' | ||
if self.condition == 1: | ||
return 'heavily used' | ||
if self.condition == 2: | ||
return'incredible' | ||
if self.condition == 3: | ||
return'outrageous' | ||
if self.condition == 4: | ||
return'cute' | ||
if self.condition == 5: | ||
return'ugly' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,108 @@ | ||
class Vendor: | ||
pass | ||
|
||
def __init__(self, inventory=None): # inventory = empty list. Optionally pass in Keyword argument inventory? | ||
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. Excellent! |
||
if inventory is None: | ||
inventory = [] | ||
self.inventory = inventory | ||
|
||
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. Excellent! |
||
# add the item to the inventory | ||
self.inventory.append(item) | ||
# return the item that was added | ||
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. Excellent! |
||
# method removes the matching item from the inventory | ||
if item in self.inventory: | ||
self.inventory.remove(item) | ||
# return the item that was removed | ||
return item | ||
# If there is no matching item in the inventory, the method should return False | ||
return False | ||
|
||
def get_by_id(self, id): | ||
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. Excellent! |
||
for item in self.inventory: | ||
#return the item with a matching if from the inventory | ||
if item.id == id: | ||
return item | ||
return None | ||
|
||
def swap_items(self, other_vendor, 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. Excellent! |
||
if my_item not in self.inventory or their_item not in other_vendor.inventory: | ||
return False | ||
|
||
# remove my_item from this Vendor's inventory | ||
self.remove(my_item) | ||
# adds it to the friend's inventory | ||
other_vendor.add(my_item) | ||
# remove their_item from the other Vendor's inventory | ||
other_vendor.remove(their_item) | ||
# add it to this Vendor's inventory | ||
self.add(their_item) | ||
|
||
return True | ||
|
||
def swap_first_item(self, other_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. Excellent! |
||
if self.inventory == [] or other_vendor.inventory == []: | ||
return False | ||
|
||
my_item = self.inventory[0] | ||
their_item = other_vendor.inventory[0] | ||
|
||
self.swap_items(other_vendor, my_item, their_item) | ||
|
||
return True | ||
|
||
def get_by_category(self, category): | ||
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. Excellent! |
||
# input : sting rep a category | ||
# output: list of objects in the inv with that catergory | ||
|
||
# create empty list to hold results | ||
result = [] | ||
# iterate over the inv to find the item that has category clothing | ||
for item in self.inventory: | ||
# get first item and use items get_category method to get the cagtegory string | ||
if item.get_category() == category: | ||
# compare | ||
result.append(item) | ||
# print(result) | ||
# if the category matches then add it to list for the category | ||
return result | ||
|
||
def get_best_by_category(self, category): | ||
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. Excellent! |
||
# input: a string representing a category | ||
# output: the item with the best condition in the category, or None if no such item exists | ||
|
||
# get a list of items in the category | ||
items_in_category = self.get_by_category(category) | ||
|
||
# if there are no items in the category, return None | ||
if not items_in_category: | ||
return None | ||
|
||
# find the item with the highest condition in the category | ||
best_item = items_in_category[0] | ||
for item in items_in_category: | ||
if item.condition > best_item.condition: | ||
best_item = item | ||
|
||
return best_item | ||
|
||
def swap_best_by_category(self, other_vendor, 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. Excellent! |
||
# input: another Vendor instance to trade with, a category that this Vendor wants to receive, | ||
# a category that the other Vendor wants to receive | ||
# output: True if the swap was successful, False otherwise | ||
|
||
# get the best item from each vendor in the specific categories | ||
my_best_item = self.get_best_by_category(their_priority) | ||
their_best_item = other_vendor.get_best_by_category(my_priority) | ||
|
||
# if either vendor has no item in the specific category, return False | ||
if not my_best_item or not their_best_item: | ||
return False | ||
|
||
self.swap_items(other_vendor, my_best_item, their_best_item) | ||
|
||
return True | ||
|
||
|
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,8 @@ def test_removing_not_found_is_false(): | |
|
||
result = vendor.remove(item) | ||
|
||
raise Exception("Complete this test according to comments below.") | ||
# assert item not in vendor.inventory | ||
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 start! It would also be good to check the length of the inventory to make sure nothing was removed accidentally. |
||
# ********************************************************************* | ||
# ****** Complete Assert Portion of this test ********** | ||
# ********************************************************************* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
from swap_meet.vendor import Vendor | ||
from swap_meet.item import Item | ||
|
||
@pytest.mark.skip | ||
#@pytest.mark.skip | ||
def test_item_overrides_to_string(): | ||
test_id = 12345 | ||
item = Item(id=test_id) | ||
|
@@ -12,7 +12,7 @@ def test_item_overrides_to_string(): | |
expected_result = f"An object of type Item with id {test_id}." | ||
assert item_as_string == expected_result | ||
|
||
@pytest.mark.skip | ||
#@pytest.mark.skip | ||
def test_swap_items_returns_true(): | ||
item_a = Item() | ||
item_b = Item() | ||
|
@@ -40,7 +40,7 @@ def test_swap_items_returns_true(): | |
assert item_b in jolie.inventory | ||
assert result | ||
|
||
@pytest.mark.skip | ||
#@pytest.mark.skip | ||
def test_swap_items_when_my_item_is_missing_returns_false(): | ||
item_a = Item() | ||
item_b = Item() | ||
|
@@ -67,7 +67,7 @@ def test_swap_items_when_my_item_is_missing_returns_false(): | |
assert item_e in jolie.inventory | ||
assert not result | ||
|
||
@pytest.mark.skip | ||
#@pytest.mark.skip | ||
def test_swap_items_when_their_item_is_missing_returns_false(): | ||
item_a = Item() | ||
item_b = Item() | ||
|
@@ -94,7 +94,7 @@ def test_swap_items_when_their_item_is_missing_returns_false(): | |
assert item_e in jolie.inventory | ||
assert not result | ||
|
||
@pytest.mark.skip | ||
#@pytest.mark.skip | ||
def test_swap_items_from_my_empty_returns_false(): | ||
fatimah = Vendor( | ||
inventory=[] | ||
|
@@ -114,7 +114,7 @@ def test_swap_items_from_my_empty_returns_false(): | |
assert len(jolie.inventory) == 2 | ||
assert not result | ||
|
||
@pytest.mark.skip | ||
#@pytest.mark.skip | ||
def test_swap_items_from_their_empty_returns_false(): | ||
item_a = Item() | ||
item_b = Item() | ||
|
@@ -131,7 +131,7 @@ def test_swap_items_from_their_empty_returns_false(): | |
|
||
result = fatimah.swap_items(jolie, item_b, nobodys_item) | ||
|
||
raise Exception("Complete this test according to comments below.") | ||
assert not result | ||
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. Excellent! |
||
# ********************************************************************* | ||
# ****** 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.
Excellent!