-
Notifications
You must be signed in to change notification settings - Fork 103
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
Ruby - Ruth M #75
base: main
Are you sure you want to change the base?
Ruby - Ruth M #75
Changes from all commits
e928afd
a21542d
2b018b5
0e40064
77be6b2
3591554
d751131
ed08d07
cf76b80
1e0ac1c
037ff4a
cd6b572
2575d50
0085387
9115242
15a8787
d9588a8
3e6ce22
d4f789d
30ee078
18ec9ac
55fcfc0
5c01ca8
73d72d7
27669f9
a51ac3a
52aac73
c817e67
9e1900a
9c4d94e
62a1cd2
b1608b4
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,15 @@ | ||
class Clothing: | ||
pass | ||
|
||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self,id = None, fabric = "Unknown", condition = 0): | ||
super().__init__(id, condition) | ||
self.fabric = fabric | ||
|
||
|
||
|
||
def get_category(self): | ||
return (self.__class__.__name__) | ||
|
||
def __str__(self): | ||
return( f'An object of type {self.get_category()} with id {self.id}. It is made from {self.fabric} fabric.') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
class Decor: | ||
pass | ||
|
||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
|
||
def __init__(self, id = None, width = 0, length = 0, condition = 0): | ||
super().__init__(id, condition) | ||
self.width = width | ||
self.length = length | ||
|
||
def __str__(self): | ||
return f'An object of type {self.get_category()} with id {self.id}. It takes up a {self.width} by {self.length} sized space.' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
class Electronics: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Electronics(Item): | ||
def __init__(self, id = None, type = "Unknown", condition = 0): | ||
super().__init__(id,condition) | ||
self.type = type | ||
|
||
|
||
def __str__(self): | ||
return f'{super().__str__()} This is a {self.type} device.' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,32 @@ | ||
import uuid | ||
|
||
|
||
class Item: | ||
pass | ||
|
||
def __init__(self, id = None, condition = 0): | ||
if not id: | ||
id = int(uuid.uuid4()) | ||
self.id = id | ||
self.condition = condition | ||
|
||
def condition_description(self): | ||
if self.condition == 0: | ||
return 'this is Garbage!' | ||
elif 1 <= self.condition < 2: | ||
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. Careful about statements like this. They sometimes have unexpected behavior. Prefer writing out the logical expression: elif 1 <= self.condition and self.condition < 2: Also, worth noting: what happens if |
||
return 'ITS A SCAM' | ||
elif 2 <= self.condition < 3: | ||
return "not bad! It's your money though" | ||
elif 3 <= self.condition <= 5: | ||
return "OMG GET IT!" | ||
|
||
|
||
|
||
def get_category(self): | ||
return (self.__class__.__name__) | ||
|
||
|
||
def __str__(self): | ||
return f'An object of type {self.get_category()} with id {self.id}.' | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,83 @@ | ||
|
||
class Vendor: | ||
pass | ||
|
||
def __init__(self, inventory=None): | ||
if not inventory: | ||
inventory = [] | ||
self.inventory = inventory | ||
|
||
def add(self,item): | ||
self.inventory.append(item) | ||
return item | ||
|
||
def remove(self,item): | ||
if item in self.inventory: | ||
self.inventory.remove(item) | ||
return item | ||
return False | ||
|
||
|
||
def get_by_id(self,id): | ||
for item in self.inventory: | ||
if item.id == id: | ||
return item | ||
return None | ||
|
||
def swap_items(self, other_vendor, my_item, their_item): | ||
|
||
if my_item not in self.inventory or their_item not in other_vendor.inventory: | ||
return False | ||
|
||
self.remove(my_item) | ||
other_vendor.add(my_item) | ||
|
||
other_vendor.remove(their_item) | ||
self.add(their_item) | ||
|
||
#if vendor inventory doesnt contain my item return false | ||
# if vendor doesnt contain their_item return false | ||
return True | ||
|
||
def swap_first_item(self,other_vendor): | ||
|
||
if not self.inventory or not other_vendor.inventory: | ||
return False | ||
|
||
other_vendor.add(self.inventory[0]) | ||
|
||
self.add(other_vendor.inventory[0]) | ||
|
||
self.remove(self.inventory[0]) | ||
|
||
other_vendor.remove(other_vendor.inventory[0]) | ||
Comment on lines
+46
to
+52
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. [nit] No need to space between each function call |
||
|
||
return True | ||
|
||
def get_by_category(self,category): | ||
|
||
self.category = 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. Careful here! It's probably unexpected if calling a |
||
|
||
objects = [] | ||
|
||
for stuff in self.inventory: | ||
if stuff.get_category() == category: | ||
objects.append(stuff) | ||
|
||
return objects | ||
Comment on lines
+60
to
+66
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. Notice this pattern of: result_list = []
for element in source_list:
if some_condition(element):
result_list.append(element) can be rewritten using a list comprehension as: result_list = [element for element in source_list if some_condition(element)] Which here would look like: objects = [stuff for stuff in self.inventory if stuff.get_category() == category]
return objects At first, this may seem more difficult to read, but comprehensions are a very common python style, so I encourage y’all to try working with them! |
||
|
||
# def get_best_by_category(self, category_condition): | ||
|
||
self.category_condition = category_condition | ||
|
||
best_condition = 0 | ||
|
||
for stuff in self.inventory(category_condition): | ||
if stuff.condition_description() < best_condition: | ||
best_condition = category_condition | ||
Comment on lines
+74
to
+76
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're on the right track! Some things to think about...
With those things in mind, see if you can come up with how to modify this code. If you still get stuck, here's a snippet that I think might help get you there: https://gist.github.com/mmcknett-ada/26444ed29c91927c05dc7d577d5bd67e |
||
return | ||
|
||
return | ||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
from swap_meet.vendor import Vendor | ||
from swap_meet.item import Item | ||
|
||
@pytest.mark.skip | ||
# @pytest.mark.skip | ||
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. [nit] you can remove these |
||
@pytest.mark.integration_test | ||
def test_integration_wave_01_02_03(): | ||
# make a vendor | ||
|
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.
A ternary is also fine here: