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

Paper, Al #61

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
21 changes: 21 additions & 0 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
############### TEST WAVE 5 (5 tests) PASSED ###############
from swap_meet.item import Item

### test 5.1 PASSED ###
# Has an attribute category that is "Clothing"
# these subclasses are teaching me about the default-arguments/optional
# in this subclass - the argument "category" is "Clothing" - it is constant and not variable
# Clothing is a special type of item where the category is always "Clothing"
# Need to look out for when to make attributes default/optional/variable OR constant

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

def __str__(self):
return "The finest clothing you could wear."
#stringify method returns "The finest clothing you could wear."
def clothing_condition_description(self, condition):
super().condition_description()
Comment on lines +18 to +19

Choose a reason for hiding this comment

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

I don't think these methods are needed.

# All 3 classes and Item class have an attribute called condition, which can be default = 0 - rendering it optional in the initializer
# All 3 classes and Item class have an instance method: condition_description() describes the condition in words
17 changes: 17 additions & 0 deletions swap_meet/decor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
############### TEST WAVE 5 (5 tests) PASSED ###############
from swap_meet.item import Item

### test 5.2 PASSED ###
# Has an attribute category that is "Decor"
class Decor(Item):
def __init__(self, condition = 0):
super().__init__("Decor", condition)

def __str__(self):
return "Something to decorate your space."
# stringify method returns "Something to decorate your space."
def decor_condition_description(self, condition):
super().condition_description()
# All 3 classes and Item class have an attribute called condition, which can be default = 0 - rendering it optional in the initializer
# All 3 classes and Item class have an instance method:
# condition_description() describes the condition in words
16 changes: 16 additions & 0 deletions swap_meet/electronics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
############### TEST WAVE 5 (5 tests) PASSED ###############
from swap_meet.item import Item

### test 5.3 PASSED ###
# Has an attribute category that is "Electronics"
class Electronics(Item):
def __init__(self, condition = 0):
super().__init__("Electronics", condition)

def __str__(self):
return "A gadget full of buttons and secrets."
# stringify method returns "A gadget full of buttons and secrets." call it with str(instance)
def elect_condition_description(self, condition):
super().condition_description()
# All 3 classes and Item class have an attribute called condition, which can be default = 0 - rendering it optional in the initializer
# All 3 classes and Item class have an instance method: condition_description() describes the condition in words
46 changes: 46 additions & 0 deletions swap_meet/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
############### TEST WAVE 2 (3 tests) ###############
############### TEST WAVE 5 (5 tests) ###############
# from vendor.swap_meet import Vendor??
# the instances/obects of the Item class will be components of the Vendor class' instance - vendor objects "have many" item objects

### test 2.1 PASSED ### setting the default argument makes it optional
class Item:

Choose a reason for hiding this comment

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

👍

def __init__(self, category = None, condition = None):
if category == None:
self.category = ""
else:
self.category = category
### test 5.4 PASSED ###
# make sure all conditions are a float
if condition is None:
self.condition = float(0)
else:
self.condition = float(condition)

### test 3.1 PASSED ### override_to_string / stringify
def __str__(self):
return "Hello World!" # use str() to call this method and convert item to the str "Hello World"
# could also return "items category: {self.category}".format(self=self)
# this method turns an item instance into the string "Hello world"

### test 5.5 F ###
def condition_description(self):
condition_description = ""
# if self.condition < 0 or condition > 5:
# return None
if 4 < self.condition <= 5:
condition_description = "supreme"
elif 3 <= self.condition <= 4:
condition_description = "pretty darn good"
elif 2 <= self.condition <= 3:
condition_description = "pleantifly medicore"
elif 1 <= self.condition <= 2:
condition_description = "some wear and tear, the condition is fair"
elif self.condition <= 1:
condition_description = "A hot mess"
return str(condition_description)

# if self.condition <= 5 and self.condition > 4:
# elif self.condition <= 4 and condition > 3:
# elif self.condition <= 3 and condition > 2:
# elif self.condition <= 2 and condition > 1:
93 changes: 93 additions & 0 deletions swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
############### TEST WAVE 1 (5 tests) PASSED ###############
############### TEST WAVE 2 (3 tests) PASSED ###############
############### TEST WAVE 4 (3 tests) PASSED ###############
############### TEST WAVE 6 (6 tests) ###############
# from item.swap_meet import Item - why is this not needed?

### test 1.1 PASSED ### test 1.2 PASSED ###
class Vendor:
def __init__(self, inventory = None): #get_by_category,

Choose a reason for hiding this comment

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

👍

# you can't make an argument/parameter of a mutable data type
# In python, if the inventory default is set to an empty list as the paramenter - then one instance update ...will change all the instances -
if inventory == None:
self.inventory = []
else:
self.inventory = inventory
# self.get_by_category = get_by_category() -- this is a Vendor method and does not need to be an attribute.

Choose a reason for hiding this comment

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

True


### test 1.3 PASSED ###
def add(self, item):

Choose a reason for hiding this comment

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

👍

self.inventory.append(item)
return item

### test 1.4 PASSED ### test 1.5 PASSED ###
def remove(self, item):

Choose a reason for hiding this comment

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

👍

if self.inventory == []:
return None
elif item not in self.inventory:
return False
Comment on lines +25 to +28

Choose a reason for hiding this comment

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

This could be merged

Suggested change
if self.inventory == []:
return None
elif item not in self.inventory:
return False
if item not in self.inventory:
return False

else:
for remove_item in self.inventory:

Choose a reason for hiding this comment

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

Do you need the loop here? You could just do self.inventory.remove(remove_item)

if item == remove_item:
self.inventory.remove(remove_item)
return remove_item

### test 2.2 PASSED ### test 2.3 PASSED ###
def get_by_category(self, category):

Choose a reason for hiding this comment

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

👍

items_by_category_list = []
for item in self.inventory:
if category == item.category: # syntax that refers to an item object by its category "str"
items_by_category_list.append(item)
return items_by_category_list

# tests 2.2 and 2.3 are looking at ^ this Vendor class method
# get_by_category() is a Vendor class method.
# ^^^It works with the many item-instances that belong to the Vendor-instance's inventory.
# tests 2.2
# ^^^returns a list of item-instances that belong to the category passed in.
# tests 2.3
#^^^returns an empty list if no item-instances belong to the category passed in.

## PASSED ## test 3.2 ## test 3.3 ## test 3.4 ## test 3.5 ## test 3.6 ##
def swap_items(self, friendor, my_item, their_item):

Choose a reason for hiding this comment

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

👍 , but you don't need the else: See my example further below.

if my_item not in self.inventory or their_item not in friendor.inventory:
return False
else:
self.inventory.remove(my_item)
friendor.inventory.append(my_item)
friendor.inventory.remove(their_item)
self.inventory.append(their_item)
return True

### test 4.1 PASSED ### test 4.2 PASSED ### test 4.3 PASSED ###
def swap_first_item(self, friendor):
if self.inventory == [] or friendor.inventory == []:
return False
else:
print("something else")
friendor.inventory.append(self.inventory[0])
self.inventory.remove(self.inventory[0])
self.inventory.append(friendor.inventory[0])
friendor.inventory.remove(friendor.inventory[0])
return True
Comment on lines +66 to +72

Choose a reason for hiding this comment

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

You don't need the else: here.

Suggested change
else:
print("something else")
friendor.inventory.append(self.inventory[0])
self.inventory.remove(self.inventory[0])
self.inventory.append(friendor.inventory[0])
friendor.inventory.remove(friendor.inventory[0])
return True
friendor.inventory.append(self.inventory[0])
self.inventory.remove(self.inventory[0])
self.inventory.append(friendor.inventory[0])
friendor.inventory.remove(friendor.inventory[0])
return True

Also friendor??


### test 6.1 PASSED ### test 6.2 PASSED ### test 6.3 PASSED ###
def get_best_by_category(self, category):

Choose a reason for hiding this comment

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

Nice use of a lambda (sort of) function!

def get_condition(item):
return item.condition
items_by_category = self.get_by_category(category)
if len(items_by_category) > 0:
return max(items_by_category, key=get_condition)
else:
return None


### test 6.4 PASSED ### test 6.5 PASSED ### test 6.6 PASSED ###
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.

👍 Good reuse of methods!


my_category = self.get_best_by_category(their_priority)
their_category = other.get_best_by_category(my_priority)
success = self.swap_items(other, my_category, their_category)
return success


11 changes: 6 additions & 5 deletions tests/test_wave_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# The following line imports the Vendor class from the module vendor inside the swap_meet package.
from swap_meet.vendor import Vendor


#### WAVE 1###
### test 1.1 PASSED ###
def test_vendor_has_inventory():
vendor = Vendor()
assert len(vendor.inventory) is 0


### test 1.2 PASSED ###
def test_vendor_takes_optional_inventory():
inventory = ["a", "b", "c"]
vendor = Vendor(inventory=inventory)
Expand All @@ -16,7 +17,7 @@ def test_vendor_takes_optional_inventory():
assert "b" in inventory
assert "c" in inventory


### test 1.3 PASSED ###
def test_adding_to_inventory():
vendor = Vendor()
item = "new item"
Expand All @@ -27,7 +28,7 @@ def test_adding_to_inventory():
assert item in vendor.inventory
assert result is item


### test 1.4 PASSED ###
def test_removing_from_inventory_returns_item():
item = "item to remove"
vendor = Vendor(
Expand All @@ -40,7 +41,7 @@ def test_removing_from_inventory_returns_item():
assert item not in vendor.inventory
assert result is item


### test 1.5 PASSED ###
def test_removing_not_found_is_false():
item = "item to remove"
vendor = Vendor(
Expand Down
7 changes: 4 additions & 3 deletions tests/test_wave_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item


#### WAVE 2###
### test 2.1 PASSED ###
def test_items_have_blank_default_category():
item = Item()
assert item.category == ""


### test 2.2 PASSED ###
def test_get_items_by_category():
item_a = Item(category="clothing")
item_b = Item(category="electronics")
Expand All @@ -23,7 +24,7 @@ def test_get_items_by_category():
assert item_c in items
assert item_b not in items


### test 2.3 PASSED ###
def test_get_no_matching_items_by_category():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand Down