-
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 - Thea V. #76
base: main
Are you sure you want to change the base?
Ruby - Thea V. #76
Changes from all commits
d7c44ea
bb5b6e7
a8b42af
78b7c6c
0b07314
74bf6f3
13bf5b7
a904e60
3e81263
f7ac77b
1840c38
b2e30dd
b907fba
bf2565b
b8e15d4
b096e63
2464956
8da77bf
e077af7
aef41a7
8067003
a21952a
a31ad6f
9f27198
e6d5868
0e543cf
b2a3c2a
d5410ed
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,40 @@ | ||
|
||
import uuid | ||
|
||
|
||
class Clothing: | ||
pass | ||
def __init__(self, fabric="Unknown", condition=0, id=None): | ||
if id: | ||
self.id = id | ||
else: | ||
# using uuid to generate random id | ||
self.id = int(uuid.uuid4()) | ||
|
||
self.fabric = fabric | ||
self.condition = condition | ||
|
||
def get_category(self): | ||
return "Clothing" | ||
|
||
def stringify(self): | ||
return f"An object of type {self.get_category()} with id {self.id}. It is made from {self.fabric} fabric." | ||
|
||
# calling the stringfy method | ||
def __str__(self): | ||
return self.stringify() | ||
|
||
def condition_description(self): | ||
if self.condition == 0: | ||
return "very bad" | ||
elif self.condition == 1: | ||
return "bad" | ||
elif self.condition == 2: | ||
return "fair" | ||
elif self.condition == 3: | ||
return "good" | ||
elif self.condition == 4: | ||
return "very good" | ||
elif self.condition == 5: | ||
return "great" | ||
|
||
return "not acceptable" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,39 @@ | ||
import uuid | ||
|
||
|
||
class Decor: | ||
pass | ||
def __init__(self, width=0, length=0, condition=0, id=None): | ||
if id: | ||
self.id = id | ||
else: | ||
# using uuid to generate random id | ||
self.id = int(uuid.uuid4()) | ||
|
||
self.width = width | ||
self.length = length | ||
self.condition = condition | ||
|
||
def get_category(self): | ||
return "Decor" | ||
|
||
def stringify(self): | ||
return f"An object of type {self.get_category()} with id {self.id}. It takes up a {self.width} by {self.length} sized space." | ||
Comment on lines
+19
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. Instead of creating a helper function that's only one line, this line of code can go into the |
||
|
||
def __str__(self): | ||
return self.stringify() | ||
|
||
def condition_description(self): | ||
if self.condition == 0: | ||
return "very bad" | ||
elif self.condition == 1: | ||
return "bad" | ||
elif self.condition == 2: | ||
return "fair" | ||
elif self.condition == 3: | ||
return "good" | ||
elif self.condition == 4: | ||
return "very good" | ||
elif self.condition == 5: | ||
return "great" | ||
|
||
return "not acceptable" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,38 @@ | ||
import uuid | ||
|
||
|
||
class Electronics: | ||
pass | ||
def __init__(self, type="Unknown", condition=0, id=None): | ||
if id: | ||
self.id = id | ||
else: | ||
# using uuid to generate random id | ||
self.id = int(uuid.uuid4()) | ||
|
||
self.type = type | ||
self.condition = condition | ||
|
||
def get_category(self): | ||
return "Electronics" | ||
|
||
def stringify(self): | ||
return f"An object of type {self.get_category()} with id {self.id}. This is a {self.type} device." | ||
|
||
def __str__(self): | ||
return self.stringify() | ||
|
||
def condition_description(self): | ||
if self.condition == 0: | ||
return "very bad" | ||
elif self.condition == 1: | ||
return "bad" | ||
elif self.condition == 2: | ||
return "fair" | ||
elif self.condition == 3: | ||
return "good" | ||
elif self.condition == 4: | ||
return "very good" | ||
elif self.condition == 5: | ||
return "great" | ||
|
||
return "not acceptable" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,34 @@ | ||
import uuid | ||
# from swap_meet import Vendor | ||
|
||
|
||
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 | ||
def __init__(self, id=None, condition=0): | ||
if id: | ||
self.id = id | ||
else: | ||
# using uuid to generate random id | ||
self.id = int(uuid.uuid4()) | ||
self.conditon = condition | ||
|
||
def get_category(self): | ||
return "Item" | ||
|
||
def __str__(self): | ||
return f"An object of type Item with id {self.id}." | ||
|
||
def condition_description(self): | ||
if self.condition == 0: | ||
return "very bad" | ||
elif self.condition == 1: | ||
return "bad" | ||
elif self.condition == 2: | ||
return "fair" | ||
elif self.condition == 3: | ||
return "good" | ||
elif self.condition == 4: | ||
return "very good" | ||
elif self.condition == 5: | ||
return "great" | ||
|
||
return "not acceptable" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,103 @@ | ||
|
||
|
||
class Vendor: | ||
pass | ||
# | ||
def __init__(self, inventory=None): | ||
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 truthy, values will be assigned to inventory | ||
if inventory: | ||
self.inventory = inventory | ||
# otherwise, [] | ||
else: | ||
self.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! |
||
self.inventory.append(item) | ||
return item | ||
|
||
# if theres a match, item gets removed | ||
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! |
||
|
||
if item in self.inventory: | ||
self.inventory.remove(item) | ||
return item | ||
|
||
else: | ||
return False | ||
|
||
# chhecking if id matches any in the invetory | ||
# | ||
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 each_item in self.inventory: | ||
if each_item.id == id: | ||
return each_item | ||
|
||
return None | ||
|
||
def swap_items(self, other_vendor, my_item, their_item): | ||
# if either of these are not found, returns False | ||
if my_item not in self.inventory: | ||
return False | ||
|
||
if their_item not in other_vendor.inventory: | ||
return False | ||
# if found | ||
# performs the swap | ||
self_item_idx = self.inventory.index(my_item) | ||
their_item_idx = other_vendor.inventory.index(their_item) | ||
# using a temp variable to hold the value then swap values | ||
temp = self.inventory[self_item_idx] | ||
self.inventory[self_item_idx] = their_item | ||
other_vendor.inventory[their_item_idx] = temp | ||
Comment on lines
+45
to
+50
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. Instead of using index to add/remove items, it would be better to reuse the |
||
|
||
return True | ||
|
||
def swap_first_item(self, other_vendor): | ||
|
||
# check if any is empty | ||
if self.inventory == []: | ||
return False | ||
|
||
if other_vendor.inventory == []: | ||
return False | ||
# swap the first items | ||
self.inventory[0], other_vendor.inventory[0] = other_vendor.inventory[0], self.inventory[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. This would be a great place to reuse the |
||
|
||
return True | ||
|
||
# loops through the inventory to sotre items in the list | ||
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! |
||
|
||
category_list = [] | ||
for each_item in self.inventory: | ||
if each_item.get_category() == category: | ||
category_list.append(each_item) | ||
return category_list | ||
|
||
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! |
||
|
||
items = self.get_by_category(category) | ||
if not items: | ||
return None | ||
|
||
best_item = items[0] | ||
# get best item in items list | ||
for item in items: | ||
if item.condition > best_item.condition: | ||
best_item = item | ||
return best_item | ||
|
||
def swap_best_by_category(self, other_vendor, my_priority, their_priority): | ||
# get best - their_priority | ||
my_best = self.get_best_by_category(their_priority) | ||
# get best - my_priority | ||
their_best = other_vendor.get_best_by_category(my_priority) | ||
|
||
if not my_best or not their_best: | ||
return False | ||
# removing my_best and theirs in my inventory and vice versa | ||
self.remove(my_best) | ||
other_vendor.remove(their_best) | ||
self.add(their_best) | ||
other_vendor.add(my_best) | ||
Comment on lines
+98
to
+101
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. Another great place to use the |
||
|
||
return True |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,15 @@ | |
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 +19,8 @@ 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 +31,8 @@ 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 +45,8 @@ 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 +55,4 @@ def test_removing_not_found_is_false(): | |
|
||
result = vendor.remove(item) | ||
|
||
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 start! It would be good to also have an assert to make sure the number of items in the inventory hasn't changed and that nothing was accidentally removed. |
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.
The requirements for the project stated that the Clothing, Decor, and Electronics classes should inherit from the Item class. Since this was not done, this project is a yellow.
Inheritance helps with keeping the code DRY. There is a lot of functionality that is the same between Clothing, Decor, Electronics, and Item that can be eliminated if we use inheritance.