Skip to content
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

C19 Sapphire - Linh Huynh #36

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ccd5164
Created Vendor class, set up attributes in dunder init method, and wr…
remitly-linh Apr 4, 2023
4fc27cf
Updated 'remove' instance methode in vendor.py to account for items t…
remitly-linh Apr 4, 2023
503209e
Corrected dunder init method in vendor.py to account for empty invent…
remitly-linh Apr 4, 2023
e143e94
Added assert line for test_removing_not_found_is_false() in unit test…
remitly-linh Apr 4, 2023
8cd2714
Created Item class and constructor with id attribute and method insta…
remitly-linh Apr 5, 2023
d1cdea2
Added method instance method named get_by_id in vendor.py module.
remitly-linh Apr 5, 2023
5cc4ba1
Removed all @pytest.mark.skip statements before each unit test functi…
remitly-linh Apr 5, 2023
ba47b83
Added __str__ instance method in the item.py module to return the str…
remitly-linh Apr 5, 2023
73a725a
Wrote instance method named swap_items in the vendor.py module.
remitly-linh Apr 5, 2023
e5912aa
Fixed TypeError (Vendor not iterable) error in swap_items instance me…
remitly-linh Apr 5, 2023
836a168
Fixed swap_items instance method in the vendor.py module to correctly…
remitly-linh Apr 5, 2023
8aa064c
Refactored my_item instance method in Item class.
remitly-linh Apr 5, 2023
364c122
Added assert statement in test_swap_items_from_their_empty_returns_fa…
remitly-linh Apr 5, 2023
184ec74
Forgot to press save before pushing my previous commit/update to the …
remitly-linh Apr 5, 2023
2fbf072
Removed all @pytest.mark.skip statments before each subtest/function …
remitly-linh Apr 7, 2023
598caee
Wrote swap_first_item in Vendor class of vendor.py module.
remitly-linh Apr 7, 2023
6c9967e
Refactored swap_items instance method of Vendor class in vendor.py mo…
remitly-linh Apr 7, 2023
3a76846
Wrote the dunder init, get_category, and __str__ functions/instance m…
remitly-linh Apr 7, 2023
7c309f4
Added attribute called condition to Item, Clothing, Decor, and Electr…
remitly-linh Apr 7, 2023
556d0f0
Wrote the condition_descrition function/instance method in the Item c…
remitly-linh Apr 7, 2023
40c6a75
Refactored dunder init and condition_description functions/instance m…
remitly-linh Apr 7, 2023
a547d71
Removed all @pytest.mark.skip statements before each subtest/function…
remitly-linh Apr 7, 2023
77024f5
Wrote get_by_category instance method within the Vendor class of the …
remitly-linh Apr 7, 2023
e4577e8
Wrote the get_best_by_category instance method for the Vendor class i…
remitly-linh Apr 7, 2023
dd3acb3
Wrote swap_best_by_category instance function for Vendor class in the…
remitly-linh Apr 7, 2023
f3ce6c4
Added assert statments to the following functions in the unit test_wa…
remitly-linh Apr 7, 2023
3dc5531
Refactored Vendor class in vendor.py module
remitly-linh Apr 7, 2023
9cf474c
Refactored Clothing, Decor, and Electronics classes in the clothing.p…
remitly-linh Apr 7, 2023
980bc49
Removed skip statements before each integration test module.
remitly-linh Apr 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
class Clothing:
pass
from .item import Item

class Clothing(Item):
def __init__(self, id = None, fabric = "Unknown", condition = 0):
super().__init__(id, condition)
self.fabric = fabric

# Initially wrote get_category instance method to return "Clothing". However, the code would be cleaner
# if I removed this instance method altogether, referenced the __str__ method instance in the Item class,
# and edited the return string in __str__ to remove any redundancy.
Comment on lines +8 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good decision for this project/context!


def __str__(self):
return f"{super().__str__()} It is made from {self.fabric} fabric."

16 changes: 14 additions & 2 deletions swap_meet/decor.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
class Decor:
pass
from .item import Item

class Decor(Item):
def __init__(self, id = None, width = 0, length = 0, condition = 0):
super().__init__(id, condition)
self.width = width
self.length = length

# Initially wrote get_category instance method to return "Decor". However, the code would be cleaner
# if I removed this instance method altogether, referenced the __str__ method instance in the Item class,
# and edited the return string in __str__ to remove any redundancy.

def __str__(self):
return f"{super().__str__()} It takes up a {self.width} by {self.length} sized space."
16 changes: 14 additions & 2 deletions swap_meet/electronics.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
class Electronics:
pass
from .item import Item

class Electronics(Item):
def __init__(self, id = None, type = "Unknown", condition = 0):
super().__init__(id, condition)
self.type = type

# Initially wrote get_category instance method to return "Electronics". However, the code would be cleaner
# if I removed this instance method altogether, referenced the __str__ method instance in the Item class,
# and edited the return string in __str__ to remove any redundancy.

def __str__(self):
return f"{super().__str__()} This is a {self.type} device."

23 changes: 22 additions & 1 deletion swap_meet/item.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
import uuid

class Item:
pass
def __init__(self, id = None, condition = 0):
self.id = int(uuid.uuid4()) if id is None else id
self.condition = condition

def get_category(self):
return type(self).__name__

def __str__(self):
return f"An object of type {self.get_category()} with id {self.id}."

def condition_description(self):
condition_rating = {
0: "Terrible: Unusable, broken, contaminated, or carries the possessed spirit of its previous owner. One might question why this was even considered sellable.",
1: "Poor: High likelihood of abnormalities, defects, or irremovable stains you probably don't want to know about. Probably best to scavenge for parts.",
2: "As-Is: Acceptable but of course, that's subjective. Consider at your own discretion.",
3: "Good: Functional or wearable. What more could you ask for a discounted price?",
4: "Gently worn: Practically like new. It's basically a steal. At least it's not cursed.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👻

5: "New: Pretty much in pristine condition with the added bonus of preventing existential crises and attracting good luck."
}
return condition_rating[self.condition]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the use of the dictionary/map

60 changes: 59 additions & 1 deletion swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,60 @@
#from .item import Item

class Vendor:
pass
def __init__(self, inventory = None):
self.inventory = [] if inventory is None else inventory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice post-fix conditional!



def add(self, item):
self.inventory.append(item)
return item


def remove(self, item):
if item not in self.inventory:
return False
else:
self.inventory.remove(item)
return item


def get_by_id(self, id):
for item in self.inventory:
if id == item.id:
return item
return None


def swap_items(self, other_vendor, my_item, their_item):
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


def swap_first_item(self, other_vendor):
try:
return self.swap_items(other_vendor, self.inventory[0], other_vendor.inventory[0])
except IndexError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice IndexError catch! I like how the code looks here.

return False


def get_by_category(self, category):
return [item for item in self.inventory if item.get_category() == category]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!!



def get_best_by_category(self, category):
category_selection = self.get_by_category(category)
try:
return max(category_selection, key=lambda item: item.condition)
except ValueError:
return None


def swap_best_by_category(self, other_vendor, my_priority, their_priority):
my_best_item = self.get_best_by_category(their_priority)
their_best_item = other_vendor.get_best_by_category(my_priority)
return self.swap_items(other_vendor, my_best_item, their_best_item)
4 changes: 2 additions & 2 deletions tests/integration_tests/test_wave_01_02_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

@pytest.mark.skip
@pytest.mark.integration_test


def test_integration_wave_01_02_03():
# make a vendor
vendor = Vendor()
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/test_wave_04_05_06.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from swap_meet.decor import Decor
from swap_meet.electronics import Electronics

@pytest.mark.skip
@pytest.mark.integration_test


def test_integration_wave_04_05_06():
camila = Vendor()
valentina = Vendor()
Expand Down
8 changes: 2 additions & 6 deletions tests/unit_tests/test_wave_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -49,7 +44,8 @@ def test_removing_not_found_is_false():

result = vendor.remove(item)

raise Exception("Complete this test according to comments below.")
assert result == False

# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************
12 changes: 6 additions & 6 deletions tests/unit_tests/test_wave_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
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

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)
Expand All @@ -36,7 +36,7 @@ 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()
Expand Down
9 changes: 2 additions & 7 deletions tests/unit_tests/test_wave_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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=[]
Expand All @@ -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()
Expand All @@ -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.")
assert result == False

# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************
6 changes: 3 additions & 3 deletions tests/unit_tests/test_wave_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

@pytest.mark.skip

def test_swap_first_item_returns_true():
item_a = Item()
item_b = Item()
Expand Down Expand Up @@ -30,7 +30,7 @@ def test_swap_first_item_returns_true():
assert item_a in jolie.inventory
assert result

@pytest.mark.skip

def test_swap_first_item_from_my_empty_returns_false():
fatimah = Vendor(
inventory=[]
Expand All @@ -48,7 +48,7 @@ def test_swap_first_item_from_my_empty_returns_false():
assert len(jolie.inventory) == 2
assert not result

@pytest.mark.skip

def test_swap_first_item_from_their_empty_returns_false():
item_a = Item()
item_b = Item()
Expand Down
Loading