-
Notifications
You must be signed in to change notification settings - Fork 110
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
C18 Lions ADSF #102
base: master
Are you sure you want to change the base?
C18 Lions ADSF #102
Changes from all commits
9cfe636
8dc866b
f89dcb3
b2d93b8
425c383
9c62c83
e274e98
83bfef8
cc53960
d0ff20e
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 |
---|---|---|
@@ -1,2 +1,11 @@ | ||
class Clothing: | ||
pass | ||
# from pyparsing import condition_as_parse_action | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self, condition=0, age=0): | ||
category = 'Clothing' | ||
super().__init__(category = category, condition=condition, age = age) | ||
|
||
|
||
def __str__(self): | ||
return 'The finest clothing you could wear.' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
class Decor: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Decor(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. Excellent! |
||
def __init__(self, condition=0, age=0): | ||
category = 'Decor' | ||
super().__init__(category = category, condition=condition, age=age) | ||
|
||
|
||
def __str__(self): | ||
return "Something to decorate your space." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
class Electronics: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Electronics(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. Excellent! |
||
def __init__(self, condition=0, age=0): | ||
category = 'Electronics' | ||
super().__init__(category = category, condition=condition, age=age) | ||
|
||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,25 @@ | ||
|
||
# from attr import NOTHING | ||
|
||
class Item: | ||
pass | ||
def __init__(self, category = "", condition=None, age = None): | ||
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. Condition and age do not need to have |
||
if not condition: | ||
condition = 0.0 | ||
self.condition = condition | ||
self.category = category | ||
if not age: | ||
age = 0 | ||
self.age = age | ||
|
||
|
||
def __str__ (self): | ||
return "Hello World!" | ||
|
||
def condition_description(self): | ||
if self.condition >= 0 and self.condition <=2: | ||
return "Condition: imperfect" | ||
elif self.condition >=3 and self.condition <=4: | ||
return "Condition: gently used" | ||
else: | ||
return "Condition: like new" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,98 @@ | ||
# from pickle import FALSE | ||
# from operator import invert | ||
# from unittest import result | ||
# from swap_meet import item | ||
from operator import ne | ||
from swap_meet.item import Item | ||
Comment on lines
+5
to
+6
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. It looks like there were some imports that were accidentally added. It's good practice after you're done coding to make sure you only have the imports you need. 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. Thank you, I 'll check them. |
||
|
||
class Vendor: | ||
pass | ||
""" Object: create a profile with the inventory and some features of each item""" | ||
def __init__(self, inventory=None): | ||
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. Excellent! |
||
if not inventory: | ||
inventory = [] | ||
self.inventory = inventory | ||
|
||
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. Excellent! |
||
""" Append new items to the current inventory""" | ||
self.inventory.append(item) | ||
return item | ||
|
||
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. Excellent! |
||
""" Remove one item to the current inventory""" | ||
if item in self.inventory: | ||
self.inventory.remove(item) | ||
return item | ||
else: | ||
return False | ||
|
||
# wave_2 | ||
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. Excellent! |
||
""" Get a list of items with the same category""" | ||
items_list = [] | ||
for item in self.inventory: | ||
if item.category == category: | ||
items_list.append(item) | ||
return items_list | ||
|
||
# wave_3 | ||
def swap_items(self, swapping_other_vendor, my_item, their_item): | ||
""" Swap items, remove items from the original inventory and add it to other person's inventory""" | ||
if my_item in self.inventory and their_item in swapping_other_vendor.inventory: | ||
self.remove(my_item) | ||
swapping_other_vendor.remove(their_item) | ||
self.add(their_item) | ||
swapping_other_vendor.add(my_item) | ||
return True | ||
else: | ||
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 else is not necessary! Since the if has a return statement, we know that if the code keeps going past the if statement, we must be in the else. The else is implied. |
||
return False | ||
|
||
# Wave_4 | ||
def swap_first_item(self, swapping_other_vendor): | ||
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. Excellent! |
||
"""Swap the first item in the inventory""" | ||
if self.inventory == [] or swapping_other_vendor.inventory == []: | ||
return False | ||
|
||
self.swap_items(swapping_other_vendor, self.inventory[0], swapping_other_vendor.inventory[0]) | ||
return True | ||
|
||
# Wave_6 | ||
|
||
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. Excellent! |
||
"""Return the item with the hightest condition per category""" | ||
inventory_items_category = self.get_by_category(category) #list | ||
if inventory_items_category == []: | ||
return None | ||
|
||
highest_item = inventory_items_category[0] | ||
for item in inventory_items_category: | ||
if item.condition >= highest_item.condition: | ||
highest_item = item | ||
return highest_item | ||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
"""Swap the desire category items from the inventories """ | ||
if self.inventory == [] or other == []: | ||
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 if statement doesn't quite work because |
||
return False | ||
|
||
my_priority_item = other.get_best_by_category(my_priority) # item | ||
their_priority_item = self.get_best_by_category(their_priority) #item | ||
|
||
if my_priority_item in other.inventory and their_priority_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. We know for sure |
||
return self.swap_items(other, their_priority_item, my_priority_item) | ||
|
||
return False | ||
|
||
# Optional Enhancements | ||
|
||
def get_newest(self): | ||
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 try! |
||
pass | ||
if self.item.age == None: | ||
return None | ||
|
||
my_newest_item = min(self.inventory, key=lambda i:i[age]) | ||
return my_newest_item | ||
|
||
|
||
def swap_by_newest(self, age): | ||
pass | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
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. Please do NOT remove this. Pytest needs to know that this is an integration test. Only remove the skip one above. |
||
def test_integration_wave_01_02_03(): | ||
# make a vendor | ||
vendor = Vendor() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pytest | ||
from swap_meet.vendor import Vendor | ||
from swap_meet.clothing import Clothing | ||
from swap_meet.decor import Decor | ||
from swap_meet.electronics import Electronics | ||
from swap_meet.item import Item | ||
|
||
@pytest.mark.skip | ||
def test_get_newest(): | ||
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 start on the test! |
||
item_a = Item(age=10) | ||
item_b = Item(age=40) | ||
item_c = Item(age=6) | ||
|
||
vendor = Vendor( | ||
inventory=[item_a, item_b, item_c] | ||
) | ||
|
||
items = vendor.get_newest(vendor) | ||
|
||
assert len(items) == 1 | ||
# assert item_a in items | ||
# assert item_c in items | ||
# assert item_b not in items |
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.
Excellent!