-
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 - Laura Perez #81
base: main
Are you sure you want to change the base?
Changes from all commits
fdf519e
08ef1b9
a509f8d
46b2fa7
d95cdf2
2bc937c
d282be6
1f80372
4b7f39a
024b6a9
9a8cd92
31af158
549b0ce
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,4 +1,5 @@ | ||
# Swap Meet | ||
# First project with OOP | ||
|
||
## Skills Assessed | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
class Clothing: | ||
pass | ||
from swap_meet.item import Item | ||
class Clothing(Item): | ||
def __init__(self, id=None, fabric="Unknown", condition=0, age=0): | ||
super().__init__(id, condition, age) | ||
self.fabric = fabric | ||
|
||
|
||
def __str__(self): | ||
return f"An object of type {self.get_category()} with id {self.id}. It is made from {self.fabric} fabric." | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
class Decor: | ||
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, age=0): | ||
super().__init__(id, condition,age) | ||
self.width = width | ||
self.length = length | ||
|
||
|
||
def __str__(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." | ||
|
||
|
||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
class Electronics: | ||
pass | ||
from swap_meet.item import 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! |
||
class Electronics(Item): | ||
def __init__(self, id=None, type="Unknown", condition=0, age=0): | ||
super().__init__(id, condition,age) | ||
self.type = type | ||
|
||
def __str__(self): | ||
return f"An object of type {self.get_category()} with id {self.id}. This is a {self.type} device." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,44 @@ | ||
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 | ||
def __init__(self, id=None, condition=0, age=0): | ||
if not isinstance(id, int) and id is not None: | ||
raise TypeError("id needs to be integer") | ||
if not isinstance(condition, int) and not isinstance(condition, float): | ||
raise TypeError("condition needs to be integer or a float") | ||
if not isinstance(age, int) and not isinstance(age, float): | ||
raise TypeError("age needs to be integer or a float") | ||
|
||
if id is None: | ||
self.id = uuid.uuid4().int | ||
else: | ||
self.id = id | ||
|
||
self.condition = condition | ||
self.age = age | ||
|
||
#--- Wave 2 ---------------------------- | ||
def get_category(self): | ||
"""Return a string holding the name of the class""" | ||
return self.__class__.__name__ | ||
|
||
# --- Wave 3 ---------------------------- | ||
def __str__(self): | ||
return f"An object of type {self.get_category()} with id {self.id}." | ||
|
||
#--- Wave 5 ----------------------------- | ||
def condition_description(self): | ||
"""Return the condition in words based on the value""" | ||
if self.condition <= 1: | ||
return 'very used' | ||
elif self.condition <= 2: | ||
return 'some used' | ||
elif self.condition <= 3: | ||
return 'good' | ||
elif self.condition <= 4: | ||
return 'very good' | ||
else: | ||
return 'This is a treassure' | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,113 @@ | ||
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 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! |
||
"""Adds item to the inventory""" | ||
self.inventory.append(item) | ||
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! |
||
"""Removes the matching item from the inventory""" | ||
if item in self.inventory: | ||
self.inventory.remove(item) | ||
return item | ||
|
||
return False | ||
|
||
# ----- Wave 2 ----------------------------- | ||
|
||
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! |
||
"""Returns the item with matching id from inventory""" | ||
for item in self.inventory: | ||
if item.id == id: | ||
return item | ||
|
||
return None | ||
|
||
# ----- Wave 3 ----------------------------- | ||
|
||
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! |
||
"""Removes my_item from self.inventory, | ||
and adds it to the other_vendor's inventory | ||
Removes their_item from the other_vendor's inventory, | ||
and adds it to self.inventory""" | ||
if my_item not in self.inventory or their_item not in other_vendor.inventory: | ||
|
||
return False | ||
|
||
self.inventory.remove(my_item) | ||
other_vendor.inventory.append(my_item) | ||
other_vendor.inventory.remove(their_item) | ||
self.inventory.append(their_item) | ||
|
||
return True | ||
|
||
# ----- Wave 4 ----------------------------- | ||
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! |
||
"""removes the first item from its inventory, and adds the other_vendor's first item | ||
Removes the first item from the other_vendor's inventory, and adds the instances first item""" | ||
if len(self.inventory) == 0 or len(other_vendor.inventory) == 0: | ||
|
||
return False | ||
|
||
self.swap_items(other_vendor, self.inventory[0], other_vendor.inventory[0]) | ||
|
||
return True | ||
|
||
|
||
# --- Wave 6 ------------------------------- | ||
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! |
||
"""Argument: a string. | ||
Returns a list of objects (in that category) from the inventory""" | ||
item_by_category = [] | ||
for item in self.inventory: | ||
if category == item.get_category(): | ||
item_by_category.append(item) | ||
return item_by_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! |
||
"""Return the item with the best condition in a certain category""" | ||
item_by_category = self.get_by_category(category) | ||
if not item_by_category: | ||
return None | ||
best_item = item_by_category[0] | ||
for item in item_by_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): | ||
""" This method swaps the best item of certain categories with another Vendor""" | ||
if self.inventory == [] or other_vendor.inventory == []: | ||
return False | ||
if not self.get_by_category(their_priority) or not other_vendor.get_by_category(my_priority): | ||
return False | ||
Comment on lines
+89
to
+90
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 check is not necessary. If there are no items in the inventory in this category, you will see that when you run |
||
|
||
my_best = self.get_best_by_category(their_priority) | ||
their_best = other_vendor.get_best_by_category(my_priority) | ||
self.swap_items(other_vendor,my_best,their_best) | ||
return True | ||
|
||
|
||
def get_the_newest(self): | ||
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! |
||
"""Return the newest item in the inventory""" | ||
newest_item = self.inventory[0] | ||
for item in self.inventory: | ||
if item.age < newest_item.age: | ||
newest_item = item | ||
return newest_item | ||
|
||
def swap_by_newest(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! |
||
"""Swap the newest item in the inventory with another vendor's newest item""" | ||
if self.inventory == [] or other_vendor.inventory == []: | ||
return False | ||
my_newest = self.get_the_newest() | ||
other_vendor_newest = other_vendor.get_the_newest() | ||
self.swap_items(other_vendor, my_newest, other_vendor_newest) | ||
return True |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,10 @@ | |
import pytest | ||
from swap_meet.vendor import Vendor | ||
|
||
@pytest.mark.skip | ||
def test_vendor_has_inventory(): | ||
vendor = Vendor() | ||
assert len(vendor.inventory) == 0 | ||
|
||
@pytest.mark.skip | ||
def test_vendor_takes_optional_inventory(): | ||
inventory = ["a", "b", "c"] | ||
vendor = Vendor(inventory=inventory) | ||
|
@@ -16,7 +14,6 @@ def test_vendor_takes_optional_inventory(): | |
assert "b" in vendor.inventory | ||
assert "c" in vendor.inventory | ||
|
||
@pytest.mark.skip | ||
def test_adding_to_inventory(): | ||
vendor = Vendor() | ||
item = "new item" | ||
|
@@ -27,7 +24,6 @@ def test_adding_to_inventory(): | |
assert item in vendor.inventory | ||
assert result == item | ||
|
||
@pytest.mark.skip | ||
def test_removing_from_inventory_returns_item(): | ||
item = "item to remove" | ||
vendor = Vendor( | ||
|
@@ -40,7 +36,6 @@ def test_removing_from_inventory_returns_item(): | |
assert item not in vendor.inventory | ||
assert result == item | ||
|
||
@pytest.mark.skip | ||
def test_removing_not_found_is_false(): | ||
item = "item to remove" | ||
vendor = Vendor( | ||
|
@@ -49,7 +44,9 @@ 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 ********** | ||
# ********************************************************************* | ||
# my changes: | ||
assert len(vendor.inventory) == 3 | ||
assert item not in vendor.inventory | ||
assert result is False | ||
Comment on lines
+48
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. Excellent! |
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,30 +2,36 @@ | |
from swap_meet.vendor import Vendor | ||
from swap_meet.item import Item | ||
|
||
@pytest.mark.skip | ||
def test_items_have_default_uuid_length_id(): | ||
item = Item() | ||
assert isinstance(item.id, int) | ||
assert len(str(item.id)) >= 32 | ||
|
||
@pytest.mark.skip | ||
def test_item_instances_have_different_default_ids(): | ||
item_a = Item() | ||
item_b = Item() | ||
assert item_a.id != item_b.id | ||
|
||
@pytest.mark.skip | ||
def test_items_use_custom_id_if_passed(): | ||
item = Item(id=12345) | ||
assert isinstance(item.id, int) | ||
assert item.id == 12345 | ||
|
||
@pytest.mark.skip | ||
#my tests: | ||
def test_items_if_non_integer_id_raises_an_error(): | ||
test_id = "y" | ||
with pytest.raises(TypeError): | ||
Item(test_id) | ||
|
||
def test_items_if_non_integer_condition_raises_an_error(): | ||
Comment on lines
+21
to
+26
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 job adding new test cases for the edge cases you're handling! Great job taking on the optional enhancements! |
||
test_condition = "y" | ||
with pytest.raises(TypeError): | ||
Item(test_condition) | ||
|
||
def test_item_obj_returns_text_item_for_category(): | ||
item = Item() | ||
assert item.get_category() == "Item" | ||
|
||
@pytest.mark.skip | ||
def test_get_item_by_id(): | ||
test_id = 12345 | ||
item_custom_id = Item(id=test_id) | ||
|
@@ -36,7 +42,6 @@ def test_get_item_by_id(): | |
result_item = vendor.get_by_id(test_id) | ||
assert result_item is item_custom_id | ||
|
||
@pytest.mark.skip | ||
def test_get_item_by_id_no_matching(): | ||
test_id = 12345 | ||
item_a = Item() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
from swap_meet.vendor import Vendor | ||
from swap_meet.item import Item | ||
|
||
@pytest.mark.skip | ||
def test_item_overrides_to_string(): | ||
test_id = 12345 | ||
item = Item(id=test_id) | ||
|
@@ -12,7 +11,6 @@ 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 | ||
def test_swap_items_returns_true(): | ||
item_a = Item() | ||
item_b = Item() | ||
|
@@ -40,7 +38,6 @@ def test_swap_items_returns_true(): | |
assert item_b in jolie.inventory | ||
assert result | ||
|
||
@pytest.mark.skip | ||
def test_swap_items_when_my_item_is_missing_returns_false(): | ||
item_a = Item() | ||
item_b = Item() | ||
|
@@ -67,7 +64,6 @@ def test_swap_items_when_my_item_is_missing_returns_false(): | |
assert item_e in jolie.inventory | ||
assert not result | ||
|
||
@pytest.mark.skip | ||
def test_swap_items_when_their_item_is_missing_returns_false(): | ||
item_a = Item() | ||
item_b = Item() | ||
|
@@ -94,7 +90,6 @@ def test_swap_items_when_their_item_is_missing_returns_false(): | |
assert item_e in jolie.inventory | ||
assert not result | ||
|
||
@pytest.mark.skip | ||
def test_swap_items_from_my_empty_returns_false(): | ||
fatimah = Vendor( | ||
inventory=[] | ||
|
@@ -114,7 +109,6 @@ def test_swap_items_from_my_empty_returns_false(): | |
assert len(jolie.inventory) == 2 | ||
assert not result | ||
|
||
@pytest.mark.skip | ||
def test_swap_items_from_their_empty_returns_false(): | ||
item_a = Item() | ||
item_b = Item() | ||
|
@@ -131,7 +125,8 @@ 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.") | ||
# ********************************************************************* | ||
# ****** Complete Assert Portion of this test ********** | ||
# ********************************************************************* | ||
#my part of the test: | ||
assert len(fatimah.inventory) == 3 | ||
assert len(jolie.inventory) == 0 | ||
assert not result | ||
Comment on lines
+129
to
+131
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! |
||
|
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!