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

Sapphire - Sophia Tran #71

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e078066
added comment to README to test git commit and push
sophiat8832 Apr 3, 2023
c017f59
implemented contructor for Vendor class
sophiat8832 Apr 3, 2023
ac142db
implemented instance method add in Vendor class
sophiat8832 Apr 3, 2023
5052082
implemented instance method remove in Vendor class
sophiat8832 Apr 3, 2023
0abff7f
implemented test_removing_not_found_is_false
sophiat8832 Apr 3, 2023
e766440
fixed default arg of constructor
sophiat8832 Apr 4, 2023
701f134
imported uuid and created constructor for Item class
sophiat8832 Apr 4, 2023
540e256
implemented get_category
sophiat8832 Apr 4, 2023
5f893f9
fixed default arg of constructor
sophiat8832 Apr 4, 2023
8fbd05a
implemented get_by_id
sophiat8832 Apr 4, 2023
d84bfb3
implemented __str__
sophiat8832 Apr 4, 2023
8b9e23c
implemented swap_items
sophiat8832 Apr 4, 2023
c249393
implemented test_swap_items_from_their_empty_returns_false
sophiat8832 Apr 4, 2023
42f2520
implemented swap_first_item
sophiat8832 Apr 4, 2023
88be6b1
imported Item class and implemented constructor for Clothing class
sophiat8832 Apr 4, 2023
4c54b28
implemented get_category in Clothing class
sophiat8832 Apr 4, 2023
24ad341
implemented __str__ in Clothing class
sophiat8832 Apr 4, 2023
e983a0d
fixed default arg id in constructor
sophiat8832 Apr 5, 2023
eee6a6d
imported Item class and created constructor for Decor class
sophiat8832 Apr 5, 2023
502e9f4
implemented get_category for Decor class
sophiat8832 Apr 5, 2023
ac7e52e
implemented __str__ in Decor
sophiat8832 Apr 5, 2023
957c23b
imported Item class into Electronics
sophiat8832 Apr 5, 2023
7ecbbb0
implemented constructor for Electronics
sophiat8832 Apr 5, 2023
2674624
implemented get_category for Electronics
sophiat8832 Apr 5, 2023
e08874b
implemented __str__ for Electronics
sophiat8832 Apr 5, 2023
9b75e93
added condition as an optional parameter for all classes
sophiat8832 Apr 5, 2023
08ec327
implemented condition_description
sophiat8832 Apr 5, 2023
25b7825
updated dict values in condition_description
sophiat8832 Apr 5, 2023
11fe273
implemented get_by_category
sophiat8832 Apr 6, 2023
3ac50cf
implemented assert portion of test_get_no_matching_items_by_category
sophiat8832 Apr 6, 2023
d5d6812
implemented get_best_by_category
sophiat8832 Apr 6, 2023
2b3abd7
implemented test_swap_best_by_category
sophiat8832 Apr 6, 2023
3226318
implemented swap_best_by_category
sophiat8832 Apr 6, 2023
cf4f071
implemented assert portion of test_swap_best_by_category_reordered
sophiat8832 Apr 6, 2023
43a7d2e
added and deleted assert statements in test_swap_best_by_category
sophiat8832 Apr 6, 2023
618c8d3
implemented assert portion of test_swap_best_by_category_no_match_is_…
sophiat8832 Apr 6, 2023
090f94a
implemented assert portion of test_swap_best_by_category_no_other_mat…
sophiat8832 Apr 6, 2023
55f9676
refactored swap_best_by_category
sophiat8832 Apr 7, 2023
8c3108e
spaced out code for readability
sophiat8832 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Testing git push
# Swap Meet

## Skills Assessed
Expand Down
15 changes: 13 additions & 2 deletions swap_meet/clothing.py
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):
def __init__(self, id=None, condition=0, fabric="Unknown"):
super().__init__(id, condition)
self.fabric = fabric

def get_category(self):
return "Clothing"

def __str__(self):
return f"An object of type Clothing with id {self.id}. It is made from {self.fabric} fabric."

15 changes: 13 additions & 2 deletions swap_meet/decor.py
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):
def __init__(self, id=None, condition=0, width=0, length=0):
super().__init__(id, condition)
self.width = width
self.length = length

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."
14 changes: 12 additions & 2 deletions swap_meet/electronics.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
class Electronics:
pass
from swap_meet.item import Item

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

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."
27 changes: 26 additions & 1 deletion swap_meet/item.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
import uuid

class Item:
pass
def __init__(self, id=None, condition=0):
if id is None:
id = uuid.uuid4().int
self.id = id
self.condition = 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):
condition_dict = {
0: "Trash",
1: "Yikes",
2: "Meh",
3: "Okay",
4: "Pretty good",
5: "Brilliant, incredible, amazing, show stopping, spectacular, never the same, totally unique, completely not ever been done before"
Copy link

Choose a reason for hiding this comment

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

💥 💥 💥 💥 💥 💥

}

if self.condition in condition_dict:
return condition_dict[self.condition]
71 changes: 70 additions & 1 deletion swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,71 @@
class Vendor:
pass
def __init__(self, inventory = None):
if inventory is None:
inventory = []
self.inventory = inventory

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

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

return False

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

return None

def swap_items(self, other_vendor, my_item, their_item):
if my_item not in self.inventory or their_item not in other_vendor.inventory:
return False

self.remove(my_item)
other_vendor.add(my_item)

other_vendor.remove(their_item)
self.add(their_item)
Comment on lines +29 to +33
Copy link

Choose a reason for hiding this comment

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

Nice work using add and remove!


return True

def swap_first_item(self, other_vendor):
if not self.inventory or not other_vendor.inventory:
return False

self.swap_items(other_vendor, self.inventory[0], other_vendor.inventory[0])
Copy link

Choose a reason for hiding this comment

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

Nice work using swap_items!

return True

def get_by_category(self, category):
category_items = []

for item in self.inventory:
if item.get_category() == category:
category_items.append(item)

return category_items

def get_best_by_category(self, category):
best_item = None
condition = 0

for item in self.inventory:
if item.get_category() == category and item.condition > condition:
condition = item.condition
best_item = item
return best_item
Comment on lines +54 to +61
Copy link

Choose a reason for hiding this comment

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

Your solution works, and it's a good solution especially since it only loops through inventory once! Optionally, there's a way to refactor this so it uses the get_by_category function and then calls max, if you wanted to practice that approach.


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)

if my_best_item and their_best_item:
self.swap_items(other_vendor, my_best_item, their_best_item)
return True
return False

13 changes: 7 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,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)
Expand All @@ -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"
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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 result == False
# raise Exception("Complete this test according to comments below.")
# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************
18 changes: 11 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,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)
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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=[]
Expand All @@ -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()
Expand All @@ -131,7 +131,11 @@ 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

# raise Exception("Complete this test according to comments below.")
# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************
Loading