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

Cheetahs - Lynn Jansheski #93

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4a99471
completed wave 1, 5 tests passed
1lynnj Oct 3, 2022
a8d38e2
completed wave 2, unit tests passed
1lynnj Oct 3, 2022
154cf97
wave 3 complete, all but one integration test passed
1lynnj Oct 4, 2022
ebf0073
cleaned up print statements and other misc comments
1lynnj Oct 4, 2022
bece982
refactored wave 1 to pass integration tests
1lynnj Oct 4, 2022
918ee22
wave 5 complete, passed all unit tests
1lynnj Oct 4, 2022
4f23363
wave 6 complete, unit tests without exceptions passed
1lynnj Oct 4, 2022
1bb0d6a
refactored swap_best_by_category function to pass test_swap_best_by_c…
1lynnj Oct 5, 2022
166ca54
refactored get_best_by_category function to pass all integration tests
1lynnj Oct 5, 2022
d82db9c
cleaning up print statements and misc comments
1lynnj Oct 5, 2022
989abd8
starting refactor of all code, will specify in coming commits
1lynnj Oct 5, 2022
74dc31a
updated doc strings in vendor class, refactored swap_best_by_category…
1lynnj Oct 5, 2022
25a7dc6
refactored clothing, decor and electronics classes to include super i…
1lynnj Oct 6, 2022
3816d79
refactored electronics, clothing and decor classes to clean up super …
1lynnj Oct 6, 2022
89eee41
added test function test_items_have_condition_description_strings_cor…
1lynnj Oct 6, 2022
d50ffbf
refactored item.py to remove unecessary lines of code
1lynnj Oct 6, 2022
08ebf5e
added get_newest and swap_by_newest functions to vendor.py, added tes…
1lynnj Oct 7, 2022
599180b
refactored get_by_category function and get_newest_item functions, ad…
1lynnj Oct 7, 2022
3b1ac5d
added doc strings to each class. Final commit for project submission.
1lynnj Oct 7, 2022
a5bf167
removed Item from Vendor class as parent. Noticed during class code r…
1lynnj Oct 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
class Clothing:
pass
from swap_meet.item import Item

class Clothing(Item):
'''Creating child class of item for clothing category.'''
def __init__(self, condition=0, age=0):
super().__init__("Clothing", condition, age)

def __str__(self):
return "The finest clothing you could wear."


13 changes: 11 additions & 2 deletions swap_meet/decor.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
class Decor:
pass
from swap_meet.item import Item

class Decor(Item):
'''Creating child class of item for decor category.'''
def __init__(self, condition=0, age=0):
super().__init__("Decor", condition, age)

def __str__(self):
return "Something to decorate your space."


12 changes: 10 additions & 2 deletions swap_meet/electronics.py
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):

Choose a reason for hiding this comment

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

Great job with wave 5 and using inheritance! Nice work hardcoding the category too 🥳

'''Creating child class of item for electronics category.'''
def __init__(self, condition=0, age=0):
super().__init__("Electronics", condition, age)

def __str__(self):
return "A gadget full of buttons and secrets."

24 changes: 23 additions & 1 deletion swap_meet/item.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
class Item:
pass
'''Creating parent class for all items to include category, condition and age.'''
def __init__(self, category="", condition=0, age=0):
self.category = category
self.condition = condition
self.age = age

def __str__(self):
return "Hello World!"

def condition_description(self):
if self.condition == 0:
return "This is pretty much garbage."
elif self.condition <= 1:
return "Not great."
elif self.condition <= 2:
return "This is ok."
elif self.condition <= 3:
return "Not too bad."
elif self.condition <= 4:
return "Looking good."
elif self.condition <= 5:
return "Perfect."

110 changes: 108 additions & 2 deletions swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,108 @@
class Vendor:
pass
from tkinter import N
from xml.dom.expatbuilder import theDOMImplementation
from swap_meet.item import Item

class Vendor():
'''Creating vendor with inventory. Includes methods for adding and removing
items from inventory by category and condition. Includes methods for swapping
items by category, condition and age.'''
def __init__(self, inventory=None):
if inventory is None:
self.inventory = []
else:
self.inventory = inventory # list of item objects

def add(self, item):
'''Add item to inventory list.'''

Choose a reason for hiding this comment

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

Beautiful docstrings ✨

self.inventory.append(item)
return item

def remove(self, item):
'''Remove item from inventory list.'''
if item in self.inventory:

Choose a reason for hiding this comment

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

This approach works, but consider how a try-except block could improve your time complexity. 🤔 💭 😌

self.inventory.remove(item)
return item

def get_by_category(self, category):
'''Get item from inventory by category.'''
inventory_by_category = []

for item in self.inventory: # items in inventory have categories
if item.category == category:
inventory_by_category.append(item)

return inventory_by_category

def swap_items(self, another_vendor, my_item, their_item):
'''Swap item between self and another vendor. Call add and remove
methods.'''
if len(self.inventory) == 0 or len(another_vendor.inventory) == 0:
return False

if my_item in self.inventory and their_item in another_vendor.inventory:
self.add(their_item)
self.remove(my_item)
another_vendor.add(my_item)
another_vendor.remove(their_item)
return True

return False


def swap_first_item(self, another_vendor):
'''Swap first item in self inventory with first item in another
vendor's inventory.'''
if len(self.inventory) > 0 and len(another_vendor.inventory) > 0:
my_item = self.inventory[0]
their_item = another_vendor.inventory[0]
return self.swap_items(another_vendor, my_item, their_item)

else:
return False


def get_best_by_category(self, category):
'''Get item in best condition by category.'''

if len(self.get_by_category(category)) == 0:
return None
else:
return max(self.get_by_category(category), key=lambda item: item.condition)

Choose a reason for hiding this comment

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

Oooo! Great usage of the max() function with a lambda function!! 🤩



def swap_best_by_category(self, other, my_priority, their_priority):
'''Swap item in best condition by desired category of other vendor
and vice versa. Returns False if desired category not in either
inventory.'''
my_best_by_category = self.get_best_by_category(their_priority)
their_best_by_category = other.get_best_by_category(my_priority)

if my_best_by_category and their_best_by_category:
self.swap_items(other, my_best_by_category, their_best_by_category)

return True

else:
return False

###############Extra#################

def get_newest_item(self):
'''Get newest item from inventory.'''
if len(self.inventory) > 0:

Choose a reason for hiding this comment

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

Since a list with 1 or more values is truthy, the Pythonic way to write this if statement would be:

if self.inventory:

😊 🐍

return min(self.inventory, key=lambda item: item.age)
else:
return False

def swap_by_newest(self, other):

Choose a reason for hiding this comment

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

Great job with the optional enhancements! 🎉

'''Swap newest item from inventory with newest item from another vendor. Returns false
if either inventory is empty.'''
if len(self.inventory) > 0 and len(other.inventory) > 0:

my_newest = self.get_newest_item()
their_newest = other.get_newest_item()

return self.swap_items(other, my_newest, their_newest)

else:
return False
5 changes: 4 additions & 1 deletion tests/integration_tests/test_wave_01_02_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

@pytest.mark.skip
# @pytest.mark.skip
@pytest.mark.integration_test
def test_integration_wave_01_02_03():
# make a vendor
vendor = Vendor()
print(len(vendor.inventory))
assert len(vendor.inventory) == 0

# add an item
Expand Down Expand Up @@ -36,12 +37,14 @@ def test_integration_wave_01_02_03():

# get item by category, falsy
items = vendor.get_by_category("Clothing")

assert len(items) == 0

other_vendor = Vendor()

# swap items
item3 = Item(category="Decor")

other_vendor.add(item3)

vendor.swap_items(other_vendor, item2, item3)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/test_wave_04_05_06.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from swap_meet.decor import Decor
from swap_meet.electronics import Electronics

@pytest.mark.skip
# @pytest.mark.skip
@pytest.mark.integration_test
def test_integration_wave_04_05_06():
camila = Vendor()
Expand Down
15 changes: 9 additions & 6 deletions tests/unit_tests/test_wave_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import pytest
from swap_meet.vendor import Vendor

@pytest.mark.skip
# @pytest.mark.skip
def test_vendor_has_inventory():
vendor = Vendor()
print(f"{vendor.inventory=}")
assert len(vendor.inventory) == 0

@pytest.mark.skip
# @pytest.mark.skip
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 vendor.inventory
assert "c" in vendor.inventory

@pytest.mark.skip
# @pytest.mark.skip
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 == item

@pytest.mark.skip
# @pytest.mark.skip
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 == item

@pytest.mark.skip
# @pytest.mark.skip
def test_removing_not_found_is_false():
item = "item to remove"
vendor = Vendor(
Expand All @@ -49,7 +50,9 @@ def test_removing_not_found_is_false():

result = vendor.remove(item)

raise Exception("Complete this test according to comments below.")
assert result == "item to remove"

Choose a reason for hiding this comment

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

Be sure to read the instructions and test names carefully! the Vendor remove method is supposed to return False if the item is not found.


# raise Exception("Complete this test according to comments below.")
# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************
9 changes: 5 additions & 4 deletions tests/unit_tests/test_wave_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

@pytest.mark.skip
# @pytest.mark.skip
def test_items_have_blank_default_category():
item = Item()
assert item.category == ""

@pytest.mark.skip
# @pytest.mark.skip
def test_get_items_by_category():
item_a = Item(category="clothing")
item_b = Item(category="electronics")
Expand All @@ -23,7 +23,7 @@ def test_get_items_by_category():
assert item_c in items
assert item_b not in items

@pytest.mark.skip
# @pytest.mark.skip
def test_get_no_matching_items_by_category():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand All @@ -34,7 +34,8 @@ def test_get_no_matching_items_by_category():

items = vendor.get_by_category("electronics")

raise Exception("Complete this test according to comments below.")
assert items == []
# raise Exception("Complete this test according to comments below.")
# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************
12 changes: 6 additions & 6 deletions tests/unit_tests/test_wave_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

@pytest.mark.skip
# @pytest.mark.skip
def test_item_overrides_to_string():
item = Item()

stringified_item = str(item)

assert stringified_item == "Hello World!"

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_items_returns_true():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand Down Expand Up @@ -38,7 +38,7 @@ def test_swap_items_returns_true():
assert item_b in jolie.inventory
assert result

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_items_when_my_item_is_missing_returns_false():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand All @@ -65,7 +65,7 @@ def test_swap_items_when_my_item_is_missing_returns_false():
assert item_e in jolie.inventory
assert not result

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_items_when_their_item_is_missing_returns_false():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand All @@ -92,7 +92,7 @@ def test_swap_items_when_their_item_is_missing_returns_false():
assert item_e in jolie.inventory
assert not result

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_items_from_my_empty_returns_false():
fatimah = Vendor(
inventory=[]
Expand All @@ -112,7 +112,7 @@ def test_swap_items_from_my_empty_returns_false():
assert len(jolie.inventory) == 2
assert not result

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_items_from_their_empty_returns_false():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/test_wave_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_first_item_returns_true():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand Down Expand Up @@ -30,7 +30,7 @@ def test_swap_first_item_returns_true():
assert item_a in jolie.inventory
assert result

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_first_item_from_my_empty_returns_false():
fatimah = Vendor(
inventory=[]
Expand All @@ -48,7 +48,7 @@ def test_swap_first_item_from_my_empty_returns_false():
assert len(jolie.inventory) == 2
assert not result

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_first_item_from_their_empty_returns_false():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand Down
Loading