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

Ada c17 whales-Nishat Salsabil #96

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 9 additions & 2 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
class Clothing:
pass
from .item import Item

class Clothing(Item):
def __init__(self, category = "Clothing", condition = 0, age = 0):
super().__init__(category, condition, age)


def __str__(self):
return "The finest clothing you could wear."
11 changes: 9 additions & 2 deletions swap_meet/decor.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
class Decor:
pass
from .item import Item

class Decor(Item):
def __init__(self, category = "Decor", condition = 0, age = 0):
super().__init__(category, condition, age)


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 .item import Item

class Electronics(Item):
def __init__(self, category = "Electronics", condition = 0, age = 0):
super().__init__(category, condition, age)


def __str__(self):
return "A gadget full of buttons and secrets."
31 changes: 30 additions & 1 deletion swap_meet/item.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,31 @@
class Item:
pass
def __init__(self, category = None, condition = 0, age = 0):
if not category:

Choose a reason for hiding this comment

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

If we don't specify a category, it will be None because of category = None in the constructor!

category = ""
self.category = category
self.condition = condition
self.age = age


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


def age_statement(self):

Choose a reason for hiding this comment

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

Nice addition of an age statement!

return f"This item was made {self.age} months ago."


def condition_description(self):
if self.condition == 0:
description = "horrendous quality"
elif self.condition == 1:
description = "terrible quality"
elif self.condition == 2:
description = "bad quality"
elif self.condition == 3:
description = "decent quality"
elif self.condition == 4:
description = "great quality"
elif self.condition == 5:
description = "exquisite quality"
return f"This item's condition is {description}"
102 changes: 101 additions & 1 deletion swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,102 @@
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

Choose a reason for hiding this comment

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

Nice use of short-circuiting and returning False at the end!



def get_by_category(self, category):
inventory_by_category = []
for item in self.inventory:
if item.category == category:
inventory_by_category.append(item)
return inventory_by_category


def swap_items(self, other_vendor, my_item, their_item):
if my_item in self.inventory and their_item in other_vendor.inventory:
other_vendor.add(my_item)
self.remove(my_item)
self.add(their_item)
other_vendor.remove(their_item)
return True
return False


def swap_first_item(self, other_vendor):
try:
my_item = self.inventory[0]
their_item = other_vendor.inventory[0]
first_items = self.swap_items(other_vendor, my_item, their_item)
return first_items
except IndexError:

Choose a reason for hiding this comment

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

Wonderful try-except and catching IndexError!

return False


def get_best_by_category(self, category):
max_condition = 0
max_item = None
for item in self.inventory:
if item.condition > max_condition and item.category == category:
max_condition = item.condition
max_item = item
return max_item


def swap_best_by_category(self, other, my_priority, their_priority):
my_item = other.get_best_by_category(my_priority)
their_item = self.get_best_by_category(their_priority)
return self.swap_items(other, their_item, my_item)

Choose a reason for hiding this comment

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

Great use of helper functions to DRY your code!




############### Optional Enhancement for Wave 07 ###############
def get_newest_item(self):
newest_age = 1000

Choose a reason for hiding this comment

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

Clever! We could also use something like float("inf") to represent an infinity value. We didn't cover this in class - just something extra you can research into!

newest_item = None
for item in self.inventory:
if item.age < newest_age:
newest_age = item.age
newest_item = item
return newest_item


def swap_by_newest(self, other, my_item, their_item):
their_item = self.get_newest_item()
my_item = other.get_newest_item()
return self.swap_items(other, their_item, my_item)

Choose a reason for hiding this comment

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

Again, great use of helper functions to DRY your code!
























5 changes: 3 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,9 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

@pytest.mark.skip
@pytest.mark.integration_test
# Test 15
#@pytest.mark.skip
#@pytest.mark.integration_test
def test_integration_wave_01_02_03():
# make a vendor
vendor = Vendor()
Expand Down
5 changes: 3 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,9 @@
from swap_meet.decor import Decor
from swap_meet.electronics import Electronics

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

@pytest.mark.skip
# Test 1
#@pytest.mark.skip
def test_vendor_has_inventory():
vendor = Vendor()
assert len(vendor.inventory) == 0

@pytest.mark.skip
# Test 2
#@pytest.mark.skip
def test_vendor_takes_optional_inventory():
inventory = ["a", "b", "c"]
vendor = Vendor(inventory=inventory)
Expand All @@ -16,18 +18,19 @@ def test_vendor_takes_optional_inventory():
assert "b" in vendor.inventory
assert "c" in vendor.inventory

@pytest.mark.skip
# Test 3
#@pytest.mark.skip
def test_adding_to_inventory():
vendor = Vendor()
item = "new item"

result = vendor.add(item)

assert len(vendor.inventory) == 1
assert item in vendor.inventory
assert result == item

@pytest.mark.skip
# Test 4
#@pytest.mark.skip
def test_removing_from_inventory_returns_item():
item = "item to remove"
vendor = Vendor(
Expand All @@ -39,8 +42,10 @@ def test_removing_from_inventory_returns_item():
assert len(vendor.inventory) == 3
assert item not in vendor.inventory
assert result == item


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

result = vendor.remove(item)

raise Exception("Complete this test according to comments below.")
#raise Exception("Complete this test according to comments below.")
# *********************************************************************
# ****** Complete Assert Portion of this test **********
assert result == False

Choose a reason for hiding this comment

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

Great; another "pythonic" and and human-readable way to express this is assert not result

# *********************************************************************
14 changes: 9 additions & 5 deletions tests/unit_tests/test_wave_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

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

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

@pytest.mark.skip
# Test 8
#@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 +37,8 @@ def test_get_no_matching_items_by_category():

items = vendor.get_by_category("electronics")

raise Exception("Complete this test according to comments below.")
#raise Exception("Complete this test according to comments below.")
# *********************************************************************
# ****** Complete Assert Portion of this test **********
assert items == []
assert len(items) == 0

Choose a reason for hiding this comment

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

👍🏻

# *********************************************************************
18 changes: 12 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,17 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

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

stringified_item = str(item)

assert stringified_item == "Hello World!"

@pytest.mark.skip
# Test 10
#@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 +40,8 @@ def test_swap_items_returns_true():
assert item_b in jolie.inventory
assert result

@pytest.mark.skip
# Test 11
#@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 +68,8 @@ def test_swap_items_when_my_item_is_missing_returns_false():
assert item_e in jolie.inventory
assert not result

@pytest.mark.skip
# Test 12
#@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 +96,8 @@ def test_swap_items_when_their_item_is_missing_returns_false():
assert item_e in jolie.inventory
assert not result

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

@pytest.mark.skip
# Test 14
#@pytest.mark.skip
def test_swap_items_from_their_empty_returns_false():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand Down
9 changes: 6 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,8 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

@pytest.mark.skip
# Test 16
#@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 +31,8 @@ def test_swap_first_item_returns_true():
assert item_a in jolie.inventory
assert result

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

@pytest.mark.skip
# Test 18
#@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