Skip to content

Puja Mukherjee-Lions #82

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

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4675213
wrote code for wave 1 part 1 and ran testcase 1
PujaMukh Oct 3, 2022
f1b025b
ran testcase 2
PujaMukh Oct 3, 2022
778e4ef
ran testcase 3 for wave 1 and added self in line 6 and 9
PujaMukh Oct 3, 2022
2f37f64
ran testcase 4 for wave 1 and added self.inventory in line 10
PujaMukh Oct 3, 2022
c3df7cb
ran testcase 5 for wave 1 and asserted this testcase
PujaMukh Oct 3, 2022
b806870
wrote code for wave 2 in item and vendor and ran testcase 1 for wave 2
PujaMukh Oct 3, 2022
c893a33
ran testcase 2 for wave 2 and added item.category in line 18 in vendo…
PujaMukh Oct 3, 2022
3f6b3a4
ran testcase 3 for wave 2 and added assert in this testcase
PujaMukh Oct 3, 2022
098efbc
ran testcase 1 for wave 3 and wrote code to return Hello World
PujaMukh Oct 4, 2022
b778456
ran testcase 2 of wave 2 and wrote code for all other testcases in wa…
PujaMukh Oct 4, 2022
032ed1e
ran testcase 3 for wave 3
PujaMukh Oct 4, 2022
abf3b82
ran testcase 4 for wave 3
PujaMukh Oct 4, 2022
c442e4d
ran testcase 5 for wave 3
PujaMukh Oct 4, 2022
cf1b0ba
ran testcase 6 for wave 3
PujaMukh Oct 4, 2022
ed788ea
implemented wave 4 and ran testcase 1 for wave 4
PujaMukh Oct 4, 2022
54570a8
Implemented Wave 4
PujaMukh Oct 4, 2022
d0f2949
ran testcase 2 for wave 4
PujaMukh Oct 4, 2022
6bc03df
ran testcase 3 for wave 4
PujaMukh Oct 4, 2022
9a8678c
checked the false condition 1st
PujaMukh Oct 4, 2022
198a606
Implemented 1st testcase of wave 5 and implemented Clothing class and…
PujaMukh Oct 4, 2022
ace8d39
Implemented Decor class and ran testcase 2 of wave 5
PujaMukh Oct 4, 2022
50c0a93
Implemented Electronics class and ran testcase 3 for wave 5
PujaMukh Oct 4, 2022
5b15ba6
ran testcase 4 for wave 5
PujaMukh Oct 4, 2022
59e8c24
used inheritance in Electronics,Clothing and Decor class and ran last…
PujaMukh Oct 5, 2022
c0c76d1
Implemented 1st part of wave 6 and ran testcase 1 for wave 6
PujaMukh Oct 5, 2022
1209751
ran testcase 2 for wavr 6
PujaMukh Oct 5, 2022
eb4888f
ran testcase 3 for wave 6
PujaMukh Oct 5, 2022
4232ec1
Implemented 2nd part of wave 6 and ran another testcase in wave 6
PujaMukh Oct 5, 2022
5ec9729
added assertions for testcase 4 in wave 6
PujaMukh Oct 5, 2022
2200d76
ran next testcase for wave 6
PujaMukh Oct 5, 2022
e5ac082
ran another testcase for wave 6
PujaMukh Oct 5, 2022
904122a
ran another testcase for wave 6
PujaMukh Oct 5, 2022
96c1587
ran another testcase and wrote assertions
PujaMukh Oct 5, 2022
be80bbb
ran last testcase of wave 6 and wrote assertions
PujaMukh Oct 5, 2022
54f3c9c
ran first integration test
PujaMukh Oct 5, 2022
7936689
ran second integration test
PujaMukh Oct 5, 2022
8530a72
refactored existing methods and added new method swap by newest and a…
PujaMukh 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
16 changes: 14 additions & 2 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
class Clothing:
pass
from swap_meet.item import Item

class Clothing(Item):
def __init__(self, category = "",condition = 0):
super().__init__(category = "Clothing", condition = condition)
Comment on lines +3 to +5

Choose a reason for hiding this comment

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

Nice use of super! Here, it would be a good idea to not have category be a parameter in the Clothing constructor. We know that we always want category to be "Clothing", so we shouldn't give the caller the illusion that they can change it.

Also a small style note: when using default/named parameters, do not put spaces before or after the equals sign. It should instead look like this:
condition=0.



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





Comment on lines +8 to +14

Choose a reason for hiding this comment

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

Please delete empty lines at the end of your file.

12 changes: 10 additions & 2 deletions swap_meet/decor.py
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):
def __init__(self, category = "",condition = 0):
super().__init__(category = "Decor", condition = condition)

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



11 changes: 9 additions & 2 deletions swap_meet/electronics.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
class Electronics:
pass
from swap_meet.item import Item
class Electronics(Item):
def __init__(self, category = "", condition = 0):
super().__init__(category = "Electronics", condition = condition)

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


22 changes: 21 additions & 1 deletion swap_meet/item.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
class Item:
pass
def __init__(self, age = 0, category = "", condition = 0):
self.category = category
self.condition = condition
self.age = age

# Wave 3
def __str__(self):
return "Hello World!"

# Wave 5
def condition_description(self):
condition_descriptions = ["I dont like zero", "I dont like one either",
"Maybe I like two", "Hmmmm.....probably three is nice", "I like four",
"Five is a nice number"]
return condition_descriptions[self.condition]
Comment on lines +12 to +16

Choose a reason for hiding this comment

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

This works if the condition is an integer, but what would happen if it were a float? (Some of the test data shows the condition as 3.5. How could you change this method to accommodate that?







98 changes: 97 additions & 1 deletion swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,98 @@
class Vendor:
pass
MAX_AGE = 1000

Choose a reason for hiding this comment

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

What would happen if we had a dinosaur fossil that was more than a thousand years old? To accommodate this case, we can set our max age to infinity using float('inf'). We can also consider doing this in the method itself instead of having a constant attached to our Vendor. The constant is just an implementation detail that helps us find the youngest object, it's not something that we need to expose to other parts of out code. I really like the idea of using a constant though!

# Wave 1
def __init__(self, inventory = None):
if inventory is None:
inventory = []
self.inventory = inventory
def add(self,item):
self.inventory.append(item)
return item
def remove(self,item):
for inventory_item in self.inventory:
if inventory_item == item:
self.inventory.remove(item)
return item
return False

# Wave 2
def get_by_category(self, category):
item_list = []
for item in self.inventory:
if item.category == category:
item_list.append(item)
return item_list
Comment on lines +19 to +24

Choose a reason for hiding this comment

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

Really nicely done! As an alternative, can you consider how this could be done using a list comprehension? Which method do you prefer?


# Wave 3
def swap_items(self, friend_vendor, my_item, their_item):
if my_item not in self.inventory or their_item not in friend_vendor.inventory:
return False

self.remove(my_item)
friend_vendor.add(my_item)
friend_vendor.remove(their_item)
self.add(their_item)
return True
Comment on lines +27 to +35

Choose a reason for hiding this comment

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

Nice re-use of your instance methods!



# Wave 4
def swap_first_item(self, friend_vendor):
if len(self.inventory) == 0 or len(friend_vendor.inventory) == 0:
return False

return self.swap_items(friend_vendor, self.inventory[0],
friend_vendor.inventory[0])


# Wave 6

def get_best_by_category(self, category):
matching_category_items = self.get_by_category(category)
highest_condition = 0
highest_item = None
for item in matching_category_items:
if item.condition > highest_condition:
highest_condition = item.condition
highest_item = item
return highest_item
Comment on lines +49 to +57

Choose a reason for hiding this comment

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

This works great! Can you consider how you would do this using max and a lambda? Which way do you prefer?




def swap_best_by_category(self, other, my_priority, their_priority):
my_best_item = self.get_best_by_category(their_priority)
their_best_item = other.get_best_by_category(my_priority)
if my_best_item == None or their_best_item == None:
return False
return self.swap_items(other, my_best_item, their_best_item)
Comment on lines +61 to +66

Choose a reason for hiding this comment

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

Really nice use of helpers! Small note, please use is None instead of == None.



# Optional Enhancement
def find_newest_item (self):
min_item_age = self.MAX_AGE
min_item = None
for item in self.inventory:
if item.age < min_item_age:
min_item_age = item.age
min_item = item
return min_item

def swap_by_newest(self, friend_vendor):
vendor_newest_item = self.find_newest_item()
friend_newest_item = friend_vendor.find_newest_item()
return self.swap_items(friend_vendor, vendor_newest_item, friend_newest_item)
Comment on lines +79 to +82

Choose a reason for hiding this comment

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

Great extra functionality!

















4 changes: 2 additions & 2 deletions tests/integration_tests/test_wave_01_02_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
def test_integration_wave_01_02_03():
# make a vendor
vendor = Vendor()
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/test_wave_04_05_06.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from swap_meet.decor import Decor
from swap_meet.electronics import Electronics

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

@pytest.mark.skip
# @pytest.mark.skip
def test_vendor_has_inventory():
vendor = Vendor()
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 +16,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 +27,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 +40,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 +49,11 @@ def test_removing_not_found_is_false():

result = vendor.remove(item)

raise Exception("Complete this test according to comments below.")
# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************
assert len(vendor.inventory) == 3
assert item not in vendor.inventory
assert result == False

# raise Exception("Complete this test according to comments below.")
# # *********************************************************************
# # ****** Complete Assert Portion of this test **********
# # *********************************************************************
19 changes: 12 additions & 7 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,12 @@ def test_get_no_matching_items_by_category():

items = vendor.get_by_category("electronics")

raise Exception("Complete this test according to comments below.")
# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************
assert len(items) == 0
assert item_a not in items
assert item_c not in items
assert item_b not in items
Comment on lines +37 to +40

Choose a reason for hiding this comment

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

This works, but we can make it simpler by removing lines 38-40. If the length of items is 0, we know that none of our items can be present in it.


# 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