From 82f2914ab2d0fac0b1421211ba58e39c075e300c Mon Sep 17 00:00:00 2001 From: KARLA TORRES Date: Mon, 5 Apr 2021 17:01:07 -0400 Subject: [PATCH 1/6] Completed wave 1-5 completed inheritance by importing Item --- swap_meet/clothing.py | 9 ++++++ swap_meet/decor.py | 8 ++++++ swap_meet/electronics.py | 8 ++++++ swap_meet/item.py | 23 +++++++++++++++ swap_meet/vendor.py | 60 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 108 insertions(+) create mode 100644 swap_meet/clothing.py create mode 100644 swap_meet/decor.py create mode 100644 swap_meet/electronics.py create mode 100644 swap_meet/item.py create mode 100644 swap_meet/vendor.py diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py new file mode 100644 index 000000000..f5b34dbb4 --- /dev/null +++ b/swap_meet/clothing.py @@ -0,0 +1,9 @@ +from swap_meet.item import Item +class Clothing(Item): + pass + def __init__(self,condition = 0.0): + self.category = "Clothing" + self.condition = condition + def __str__(self): + return "The finest clothing you could wear." + diff --git a/swap_meet/decor.py b/swap_meet/decor.py new file mode 100644 index 000000000..6f8dbac51 --- /dev/null +++ b/swap_meet/decor.py @@ -0,0 +1,8 @@ +from swap_meet.item import Item +class Decor(Item): + pass + def __init__(self,condition = 0.0): + self.category = "Decor" + self.condition = condition + def __str__(self): + return "Something to decorate your space." diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py new file mode 100644 index 000000000..0067a7045 --- /dev/null +++ b/swap_meet/electronics.py @@ -0,0 +1,8 @@ +from swap_meet.item import Item +class Electronics(Item): + pass + def __init__(self,condition = 0.0): + self.category = "Electronics" + self.condition = condition + def __str__(self): + return "A gadget full of buttons and secrets." diff --git a/swap_meet/item.py b/swap_meet/item.py new file mode 100644 index 000000000..02b082ca0 --- /dev/null +++ b/swap_meet/item.py @@ -0,0 +1,23 @@ +class Item: + pass + def __init__(self, category="", condition = 0.0): + self.category = category + self.condition = condition + def __str__(self): + return "Hello World!" + def condition_description(self): + if self.condition == 0: + return "mint condition" + elif self.condition == 1: + return "like new" + elif self.condition == 2: + return "gently used" + elif self.condition == 3: + return "used" + elif self.condition == 4: + return "clean this before using it" + elif self.condition == 5: + return "Please clean 2x over" + + + \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py new file mode 100644 index 000000000..084ed93c3 --- /dev/null +++ b/swap_meet/vendor.py @@ -0,0 +1,60 @@ +class Vendor: + pass + def __init__(self, inventory = None): + if inventory == None: + self.inventory= [] + else: + self.inventory = inventory + def add(self, add_item): + self.inventory.append(add_item) + return add_item + def remove(self, remove_item): + if remove_item not in self.inventory: + return False + else: + self.inventory.remove(remove_item) + return remove_item + def get_by_category(self, category): + item_list = [] + for item in self.inventory: + if category == item.category: + item_list.append(item) + return item_list + def swap_items(self, vendor, my_item, their_item): + if my_item not in self.inventory or their_item not in vendor.inventory: + return False + if my_item in self.inventory and their_item in vendor.inventory: + self.remove(my_item) + vendor.add(my_item) + vendor.remove(their_item) + self.add(their_item) + return True + def swap_first_item(self, vendor_list): + if len(self.inventory) > 0 and len(vendor_list.inventory) > 0: + my_first_item = self.inventory [0] + their_first_item = vendor_list.inventory[0] + self.inventory.remove(my_first_item) + self.inventory.insert(0, their_first_item) + vendor_list.inventory.remove(their_first_item) + vendor_list.inventory.insert(0,my_first_item) + return True + else: + return False + + + + + + + + + +#"""if my_item in self.inventory +# self.remove(my_item) +# vendor.add(my_item) +# if their_item in vendor.inventory: +# vendor.remove(their_item) +# self.add(their_item)""" + + + From 60ace77b289661fba7f37231d484da9446757109 Mon Sep 17 00:00:00 2001 From: KARLA TORRES Date: Mon, 5 Apr 2021 19:22:58 -0400 Subject: [PATCH 2/6] Successful pass for all tests in wave 6// still need to apply DRY principle --- swap_meet/vendor.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 084ed93c3..c14c36dbb 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -40,21 +40,25 @@ def swap_first_item(self, vendor_list): return True else: return False - - - - - - - - - -#"""if my_item in self.inventory -# self.remove(my_item) -# vendor.add(my_item) -# if their_item in vendor.inventory: -# vendor.remove(their_item) -# self.add(their_item)""" - + def get_best_by_category(self, category): + items = self.get_by_category(category) + if len(items) == 0: + return None + best_by_category = items[0] + for item in items: + if item.condition > best_by_category.condition: + best_by_category = item + return best_by_category + def swap_best_by_category(self, other, my_priority, their_priority): + my_item = self.get_best_by_category(their_priority) + their_item = other.get_best_by_category(my_priority) + if my_item and their_item: + other.inventory.remove(their_item) + self.inventory.remove(my_item) + self.inventory.append(their_item) + other.inventory.append(my_item) + return True + else: + return False From f2cff8987c06be3ebc06a78fd43fb451b93dc48c Mon Sep 17 00:00:00 2001 From: KARLA TORRES Date: Tue, 6 Apr 2021 22:59:46 -0400 Subject: [PATCH 3/6] Reduced the amount of repeated code from swap_best_by_category and swap_first_item by making use of swap_items method. --- swap_meet/vendor.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index c14c36dbb..e8f5bd8bb 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -29,15 +29,16 @@ def swap_items(self, vendor, my_item, their_item): vendor.remove(their_item) self.add(their_item) return True - def swap_first_item(self, vendor_list): - if len(self.inventory) > 0 and len(vendor_list.inventory) > 0: + def swap_first_item(self, vendor): + if len(self.inventory) > 0 and len(vendor.inventory) > 0: my_first_item = self.inventory [0] - their_first_item = vendor_list.inventory[0] - self.inventory.remove(my_first_item) - self.inventory.insert(0, their_first_item) - vendor_list.inventory.remove(their_first_item) - vendor_list.inventory.insert(0,my_first_item) - return True + their_first_item = vendor.inventory[0] + return self.swap_items(vendor, my_first_item, their_first_item) + # self.inventory.remove(my_first_item) + # vendor.inventory.remove(their_first_item) + # vendor.inventory.append(my_first_item) + # self.inventory.append(their_first_item) + # return True else: return False def get_best_by_category(self, category): @@ -53,11 +54,12 @@ def swap_best_by_category(self, other, my_priority, their_priority): my_item = self.get_best_by_category(their_priority) their_item = other.get_best_by_category(my_priority) if my_item and their_item: - other.inventory.remove(their_item) - self.inventory.remove(my_item) - self.inventory.append(their_item) - other.inventory.append(my_item) - return True + return self.swap_items(other, my_item, their_item) + # other.inventory.remove(their_item) + # self.inventory.remove(my_item) + # self.inventory.append(their_item) + # other.inventory.append(my_item) + # return True else: return False From de3cdc1b8a2450341a54622ef405249b6a8998e8 Mon Sep 17 00:00:00 2001 From: KARLA TORRES Date: Tue, 6 Apr 2021 23:05:11 -0400 Subject: [PATCH 4/6] removed all unnecessary comments. --- swap_meet/vendor.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index e8f5bd8bb..999e4dc8f 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -34,11 +34,6 @@ def swap_first_item(self, vendor): my_first_item = self.inventory [0] their_first_item = vendor.inventory[0] return self.swap_items(vendor, my_first_item, their_first_item) - # self.inventory.remove(my_first_item) - # vendor.inventory.remove(their_first_item) - # vendor.inventory.append(my_first_item) - # self.inventory.append(their_first_item) - # return True else: return False def get_best_by_category(self, category): @@ -55,11 +50,6 @@ def swap_best_by_category(self, other, my_priority, their_priority): their_item = other.get_best_by_category(my_priority) if my_item and their_item: return self.swap_items(other, my_item, their_item) - # other.inventory.remove(their_item) - # self.inventory.remove(my_item) - # self.inventory.append(their_item) - # other.inventory.append(my_item) - # return True else: return False From 80672ad20aa8c9859c3ef8fab7f4a200722a5cef Mon Sep 17 00:00:00 2001 From: KARLA TORRES Date: Wed, 7 Apr 2021 10:33:08 -0400 Subject: [PATCH 5/6] Entered two comments on lines 36 and 52 --- swap_meet/vendor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 999e4dc8f..8f28069f0 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -33,7 +33,7 @@ def swap_first_item(self, vendor): if len(self.inventory) > 0 and len(vendor.inventory) > 0: my_first_item = self.inventory [0] their_first_item = vendor.inventory[0] - return self.swap_items(vendor, my_first_item, their_first_item) + return self.swap_items(vendor, my_first_item, their_first_item) #adjusted line for "DRY" else: return False def get_best_by_category(self, category): @@ -49,7 +49,7 @@ def swap_best_by_category(self, other, my_priority, their_priority): my_item = self.get_best_by_category(their_priority) their_item = other.get_best_by_category(my_priority) if my_item and their_item: - return self.swap_items(other, my_item, their_item) + return self.swap_items(other, my_item, their_item) #adjusted line for "DRY" else: return False From 634cc3a6ffea6a4a71d27385a739e204a81dfe7a Mon Sep 17 00:00:00 2001 From: KARLA TORRES Date: Thu, 8 Apr 2021 14:48:55 -0400 Subject: [PATCH 6/6] removed 'else' from lines 37 and 53 because test all test passed without it --- swap_meet/vendor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 8f28069f0..961444cda 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -34,8 +34,8 @@ def swap_first_item(self, vendor): my_first_item = self.inventory [0] their_first_item = vendor.inventory[0] return self.swap_items(vendor, my_first_item, their_first_item) #adjusted line for "DRY" - else: - return False + + return False def get_best_by_category(self, category): items = self.get_by_category(category) if len(items) == 0: @@ -50,7 +50,7 @@ def swap_best_by_category(self, other, my_priority, their_priority): their_item = other.get_best_by_category(my_priority) if my_item and their_item: return self.swap_items(other, my_item, their_item) #adjusted line for "DRY" - else: - return False + + return False