-
Notifications
You must be signed in to change notification settings - Fork 71
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
base: master
Are you sure you want to change the base?
Paper, Al #61
Changes from all commits
2c962ed
01af45f
b8dc46d
0ec21ff
580cb08
cf49283
5eb206b
b263b0f
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 |
---|---|---|
@@ -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() | ||
# 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 |
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 |
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 |
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: | ||
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. 👍 |
||
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: |
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, | ||||||||||||||||||||||||||||
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. 👍 |
||||||||||||||||||||||||||||
# 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. | ||||||||||||||||||||||||||||
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. True |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
### test 1.3 PASSED ### | ||||||||||||||||||||||||||||
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. 👍 |
||||||||||||||||||||||||||||
self.inventory.append(item) | ||||||||||||||||||||||||||||
return item | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
### test 1.4 PASSED ### test 1.5 PASSED ### | ||||||||||||||||||||||||||||
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. 👍 |
||||||||||||||||||||||||||||
if self.inventory == []: | ||||||||||||||||||||||||||||
return None | ||||||||||||||||||||||||||||
elif item not in self.inventory: | ||||||||||||||||||||||||||||
return False | ||||||||||||||||||||||||||||
Comment on lines
+25
to
+28
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 could be merged
Suggested change
|
||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||
for remove_item in self.inventory: | ||||||||||||||||||||||||||||
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. Do you need the loop here? You could just do |
||||||||||||||||||||||||||||
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): | ||||||||||||||||||||||||||||
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. 👍 |
||||||||||||||||||||||||||||
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): | ||||||||||||||||||||||||||||
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. 👍 , but you don't need the |
||||||||||||||||||||||||||||
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
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. You don't need the
Suggested change
Also |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
### test 6.1 PASSED ### test 6.2 PASSED ### test 6.3 PASSED ### | ||||||||||||||||||||||||||||
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. 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): | ||||||||||||||||||||||||||||
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. 👍 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 | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
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.
I don't think these methods are needed.