-
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 Class - Kimberly Lantigua #83
base: main
Are you sure you want to change the base?
Changes from all commits
6e38b13
b281e40
f7e559c
a6fb3c6
d8362ed
c44123c
f26aea4
9a68fdc
aaf42ef
7990f99
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,13 @@ | ||
class Clothing: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
|
||
# constructor | ||
def __init__(self, id = None, condition = 0.0, fabric = "Unknown"): | ||
super().__init__(id = id, condition = condition) | ||
self.fabric = fabric | ||
|
||
def __str__(self): | ||
return f"{super().__str__()} It is made from {self.fabric} fabric." | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
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! |
||
|
||
# constructor | ||
def __init__(self, id = None, condition = 0.0, width = 0, length = 0): | ||
super().__init__(id, condition) | ||
self.width = width | ||
self.length = length | ||
|
||
def __str__(self): | ||
return f"{super().__str__()} It takes up a {self.width} by {self.length} sized space." | ||
|
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): | ||
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! |
||
|
||
# constructor | ||
def __init__(self, id = None, condition = 0, type = "Unknown"): | ||
super().__init__(id, condition) | ||
self.type = type | ||
|
||
def __str__(self): | ||
return f"{super().__str__()} This is a {self.type} device." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,35 @@ | ||
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 | ||
|
||
# item constructor | ||
def __init__(self, id = None, condition = 0.0): | ||
if not id: | ||
id = uuid.uuid4().int | ||
self.id = id | ||
self.condition = condition | ||
|
||
# get by category method | ||
def get_category(self): | ||
return self.__class__.__name__ | ||
|
||
# stringify a method using dunder str | ||
def __str__(self): | ||
return f"An object of type {self.get_category()} with id {self.id}." | ||
|
||
def condition_description(self): | ||
approx_value = round(self.condition) | ||
if approx_value == 5: | ||
return "New" | ||
elif approx_value == 4: | ||
return "Like New" | ||
elif approx_value == 3: | ||
return "Used" | ||
elif approx_value == 2: | ||
return "...Very Used" | ||
elif approx_value == 1: | ||
return "Barely Usable/Functional" | ||
else: | ||
return "Scrap Materials for DIY Project" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,93 @@ | ||
from swap_meet.item import Item | ||
|
||
class Vendor: | ||
pass | ||
|
||
# constructor for the vendor class | ||
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 not inventory: | ||
inventory = [] | ||
self.inventory = inventory | ||
|
||
# add method | ||
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 | ||
|
||
# remove method | ||
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 | ||
|
||
return False | ||
|
||
# method that returns the item based on id | ||
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: | ||
if item.id == id: | ||
return item | ||
|
||
return None | ||
|
||
# method to swap items between two vendors | ||
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 in self.inventory and their_item in other_vendor.inventory: | ||
self.remove(my_item) | ||
self.add(their_item) | ||
|
||
other_vendor.remove(their_item) | ||
other_vendor.add(my_item) | ||
return True | ||
|
||
return False | ||
|
||
# method to swap first items between two vendors | ||
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! |
||
try: | ||
my_first_item = self.inventory[0] | ||
their_first_item = other_vendor.inventory[0] | ||
|
||
except IndexError: | ||
return False | ||
|
||
return self.swap_items(other_vendor, my_first_item, their_first_item) | ||
|
||
# method to retrieve all items in a particular category | ||
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! |
||
item_list = [] | ||
|
||
for item in self.inventory: | ||
if item.get_category() == category: | ||
item_list.append(item) | ||
|
||
return item_list | ||
|
||
# method to retrieve best condition item in a particular category | ||
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! |
||
best_condition = 0 | ||
best_item = None | ||
category_list = self.get_by_category(category) | ||
|
||
if not category_list: | ||
return best_item | ||
|
||
for item in category_list: | ||
if item.condition > best_condition: | ||
best_condition = item.condition | ||
best_item = item | ||
|
||
return best_item | ||
|
||
# method to swap the best item (best condition) with another vendor so long | ||
# as both vendors have the type of items the other is looking for | ||
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! |
||
|
||
my_best_item = self.get_best_by_category(their_priority) | ||
their_best_item = other_vendor.get_best_by_category(my_priority) | ||
|
||
if my_best_item is None or their_best_item is None: | ||
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,16 +40,20 @@ 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( | ||
inventory=["a", "b", "c"] | ||
) | ||
|
||
result = vendor.remove(item) | ||
# Assert | ||
assert len(vendor.inventory) == 3 | ||
assert item not in vendor.inventory | ||
assert result is False | ||
Comment on lines
+52
to
+54
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! The second assert statement is not necessary since the inventory never had the item to begin it. |
||
|
||
raise Exception("Complete this test according to comments below.") | ||
# raise Exception("Complete this test according to comments below.") | ||
# ********************************************************************* | ||
# ****** 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,10 @@ 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 len(fatimah.inventory) == 3 | ||
assert len(jolie.inventory) == 0 | ||
assert not result | ||
Comment on lines
+134
to
+136
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! |
||
# raise Exception("Complete this test according to comments below.") | ||
# ********************************************************************* | ||
# ****** 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!