Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Swap Meet

# Another challenging week begins!

## Skills Assessed

- Following directions and reading comprehension
Expand Down
13 changes: 11 additions & 2 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
class Clothing:
pass
from swap_meet.item import Item

class Clothing(Item):
def __init__(self, category = "Clothing", condition = 0):

Choose a reason for hiding this comment

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

Great job! We actually don't want to have category in the __init__ function. Since Clothing objects should always have "Clothing" as the category we do not want to let the user to put in their own information. On line 5 instead of category you can put "Clothing" to pass to the super class.

super().__init__(category, condition)
# self.category = "Clothing"

def __str__(self):
return "The finest clothing you could wear."


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

class Decor(Item):

Choose a reason for hiding this comment

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

Great job!

def __init__(self, category = "Decor", condition = 0):
super().__init__(category, condition)
# self.category = "Decor"

def __str__(self):
return "Something to decorate your 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):

Choose a reason for hiding this comment

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

Great job!

def __init__(self, category = "Electronics", condition = 0):
super().__init__(category, condition)
# self.category = "Electronics"

def __str__(self):
return "A gadget full of buttons and secrets."



35 changes: 34 additions & 1 deletion swap_meet/item.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
# from attr import validate

class Item:
pass
def __init__(self, category = None, condition = 0):

Choose a reason for hiding this comment

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

The default for category can be "" instead of None. We use None for mutable data types like lists or dictionaries. Since string are immutable in Python, we do not need None.

# category is an empty string
if category is None:
category = ""
self.category = category
self.condition = condition

def __str__(self):
return "Hello World!"

def condition_description(self):

Choose a reason for hiding this comment

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

It looks like you were changing some of the conditions in the if statements, but didn't finish. The logic has some gaps in it. Good start though!

if self.condition > 0 and self.condition < 2:
return "1 star"
elif self.condition > 1 and self.condition < 3:
return "2 stars"
elif self.condition > 2 and self.condition < 3:
return "3 stars"
elif self.condition > 4 and self.condition < 5:
return "4 stars"
elif self.condition == 5:
return "5 stars"
else:
return "Invalid number"









101 changes: 100 additions & 1 deletion swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,101 @@
# from xmlrpc.client import INVALID_ENCODING_CHAR

# from attr import s

class Vendor:
pass
def __init__(self, inventory = None):

Choose a reason for hiding this comment

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

Excellent!

# inventory is a empty list
if inventory is None:
inventory = []
self.inventory = inventory

def add(self, item):

Choose a reason for hiding this comment

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

Excellent!

self.inventory.append(item)
return item

def remove(self, item):

Choose a reason for hiding this comment

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

Excellent!

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



def get_by_category(self, str_category):

Choose a reason for hiding this comment

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

Excellent! One small note, the elements in self.inventory are Items. Using string as the variable in the for loop isn't as descriptive as it could be.

category_list = []
for string in self.inventory:
if string.category == str_category:
category_list.append(string)
return category_list



def swap_items(self, another_vendor, my_item, their_item):
if my_item not in self.inventory or\
their_item not in another_vendor.inventory:
# another_vendor.inventory --> (parameter_name.attribute_name)
return False

another_vendor.inventory.append(self.remove(my_item))
another_vendor.inventory.remove(their_item)
self.inventory.append(their_item)
Comment on lines +39 to +41

Choose a reason for hiding this comment

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

This would have been a good place to use the add and remove functions from earlier rather than accessing the inventories directly.


# self.inventory.remove(my_item)
# another_vendor.inventory.append(my_item)
# another_vendor.inventory.remove(their_item)
# self.inventory.append(their_item)
return True


def swap_first_item(self, another_vendor):

Choose a reason for hiding this comment

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

Great job!

if self.inventory == [] or another_vendor.inventory == []:
return False

my_item = self.inventory[0]
their_item = another_vendor.inventory[0]
self.inventory.remove(my_item)
self.inventory.append(their_item)
another_vendor.inventory.remove(their_item)
another_vendor.inventory.append(my_item)

return True


def get_best_by_category(self, str_category):

Choose a reason for hiding this comment

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

Excellent!

category_list = self.get_by_category(str_category)
# call the get_by_category funtion and assign to a variable
if len(category_list) == 0:
return None
best_condition = category_list[0]
for item in category_list:
if item.condition > best_condition.condition:
best_condition = item
# will only get the first one that appear with the best condition
return best_condition


def swap_best_by_category(self, other, my_priority, their_priority):

Choose a reason for hiding this comment

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

Excellent!

# other, which represents another Vendor instance to trade with
# my_priority, which represents a category that the Vendor wants to receive
# their_priority, which represents a category that other wants to receive
my_best = self.get_best_by_category(their_priority)
their_best = other.get_best_by_category(my_priority)
# if not my_best or not their_best:
# return False
return self.swap_items(other, my_best, their_best)
# return True















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
# @pytest.mark.skip
# @pytest.mark.integration_test

Choose a reason for hiding this comment

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

Please do not remove this! Pytest needs to know that this is an integration test. Please only remove the skip one above.

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
# @pytest.mark.skip
# @pytest.mark.integration_test
def test_integration_wave_04_05_06():
camila = Vendor()
valentina = Vendor()
Expand Down
16 changes: 10 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,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 len(vendor.inventory) == 3
assert item not in vendor.inventory
assert result == False
Comment on lines +51 to +53

Choose a reason for hiding this comment

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

Excellent asserts!

# raise Exception("Complete this test according to comments below.")


raise Exception("Complete this test according to comments below.")
# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************
13 changes: 9 additions & 4 deletions tests/unit_tests/test_wave_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

@pytest.mark.skip
# @pytest.mark.skip
def test_items_have_blank_default_category():
item = Item()
assert item.category == ""

@pytest.mark.skip
# @pytest.mark.skip
def test_get_items_by_category():
item_a = Item(category="clothing")
item_b = Item(category="electronics")
Expand All @@ -23,7 +23,7 @@ def test_get_items_by_category():
assert item_c in items
assert item_b not in items

@pytest.mark.skip
# @pytest.mark.skip
def test_get_no_matching_items_by_category():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand All @@ -34,7 +34,12 @@ def test_get_no_matching_items_by_category():

items = vendor.get_by_category("electronics")

raise Exception("Complete this test according to comments below.")

assert len(items) == 0
assert item_a not in items
assert item_c not in items
assert item_b not in items
Comment on lines +39 to +41

Choose a reason for hiding this comment

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

Great asserts! These three aren't necessary since the first one tells us there's nothing in the list. We don't need to check each individual item.


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

@pytest.mark.skip
# @pytest.mark.skip
def test_item_overrides_to_string():
item = Item()

stringified_item = str(item)

assert stringified_item == "Hello World!"

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_items_returns_true():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand Down Expand Up @@ -38,7 +38,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(category="clothing")
item_b = Item(category="clothing")
Expand All @@ -65,7 +65,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(category="clothing")
item_b = Item(category="clothing")
Expand All @@ -92,7 +92,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 @@ -112,7 +112,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(category="clothing")
item_b = Item(category="clothing")
Expand Down
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
# @pytest.mark.skip
def test_swap_first_item_returns_true():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
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
# @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
# @pytest.mark.skip
def test_swap_first_item_from_their_empty_returns_false():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand Down
Loading