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

Tigers - Masha & Soleil #24

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a2899e7
added add method and remove method
soleilherring Oct 3, 2022
f3ba8e8
unskipped tests
soleilherring Oct 3, 2022
00ee0b4
Changes for wave 2, 1 test is not working yet
mariia-iureva Oct 3, 2022
8433589
Added assert to the last test of wave 2
mariia-iureva Oct 4, 2022
0d6d6bc
Added functions to wave 3, 4, and 5
soleilherring Oct 4, 2022
dfffc28
Wave 6 first attempt
soleilherring Oct 4, 2022
eb9f4e0
Wave 6 second attempt
soleilherring Oct 4, 2022
6e37649
wave 6 updated get best category function
soleilherring Oct 4, 2022
746e5a2
Wave 6 second function
mariia-iureva Oct 5, 2022
c8383f7
playing around with tests
soleilherring Oct 5, 2022
4958922
adding playtester
mariia-iureva Oct 5, 2022
76d828e
modified play tester and wave 6
soleilherring Oct 5, 2022
be4eeb6
fixed original function for swap_best_by_category
soleilherring Oct 5, 2022
8f535d7
created assertions for wave 6
soleilherring Oct 5, 2022
f87c744
tested integration test
soleilherring Oct 5, 2022
43d90c1
tested again for integration test
soleilherring Oct 5, 2022
e436df2
changed item to include dictionary instead of if statements
soleilherring Oct 5, 2022
738ada4
changed item to include dictionary deleted if statment
soleilherring Oct 5, 2022
1385620
Some refactoring on Wave 6 and drying the code
mariia-iureva Oct 5, 2022
ef67a75
refactored get best by category
soleilherring Oct 5, 2022
8a4984e
Refactored vendor.py, removed excessive else statements
mariia-iureva Oct 6, 2022
8822bd8
updated wave 6 tests
soleilherring Oct 6, 2022
fe0bbdb
Added tests for Wave 7, added possible age functions intovendor
mariia-iureva Oct 6, 2022
43386ae
Merge branch 'master' of https://github.com/mariia-iureva/swap-meet
mariia-iureva Oct 6, 2022
21fdb1e
added more tests to wave 6
soleilherring Oct 6, 2022
b0df797
finished wave 7 created get_newest function and revised tests
soleilherring Oct 6, 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
33 changes: 33 additions & 0 deletions play_tester.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

Choose a reason for hiding this comment

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

This probably doesn't need to be committed.

from swap_meet.vendor import Vendor
from swap_meet.clothing import Clothing
from swap_meet.decor import Decor
from swap_meet.electronics import Electronics

#def test_swap_best_by_category():
# Arrange
# me
item_a = Decor(condition=2.0)
item_b = Electronics(condition=4.0)
item_c = Decor(condition=4.0)
tai = Vendor(
inventory=[item_a, item_b, item_c]
)

# them
item_d = Clothing(condition=2.0)
item_e = Decor(condition=4.0)
item_f = Clothing(condition=4.0)
jesse = Vendor(
inventory=[item_d, item_e, item_f]
)

# Act
result = tai.swap_best_by_category(
other=jesse,
my_priority="Clothing",
their_priority="Decor"
)
# print(tai.inventory)
# print(jesse.inventory)
#print(result)
12 changes: 10 additions & 2 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
class Clothing:
pass
from swap_meet.item import Item

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


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

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, condition = 0, age = 0):
super().__init__(category = "Decor", condition = condition, age = 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):
def __init__(self, condition = 0, age = 0):
super().__init__(category = "Electronics", condition = condition, age = 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 @@
# from swap_meet.vendor import Vendor

class Item:
pass

def __init__(self, category = None, condition = 0, age = 0):
self.category = category if category is not None else ""
self.condition = condition
self.age = age

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

def condition_description(self):

Choose a reason for hiding this comment

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

Nice 👍

self.condition = round(self.condition)
condition_dict = {
0 : "garbage",
1 : "bad",
2 : "used",
3 : "lightly used",
4 : "like new",
5 : "new"
}
return condition_dict[self.condition]

107 changes: 106 additions & 1 deletion swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,107 @@
from swap_meet.item import Item

class Vendor:
pass
def __init__(self, inventory=None):
self.inventory = inventory if inventory is not None else []

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_category(self, category):
list_of_items = []
for item in self.inventory:
if item.category == category:
list_of_items.append(item)

return list_of_items

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

other_vendor.remove(their_item)
self.add(their_item)
self.remove(my_item)
other_vendor.add(my_item)
return True

def swap_first_item(self, other_vendor):
if not self.inventory or not other_vendor.inventory:
return False

my_item = self.inventory[0]
their_item = other_vendor.inventory[0]
self.swap_items(other_vendor, my_item, their_item)
return True

def get_best_by_category(self, category):
items_with_category = self.get_by_category(category)
if not items_with_category:
return None

max_item_condition = max(items_with_category, key=lambda item: item.condition)
return max_item_condition


def swap_best_by_category(self, other, my_priority, their_priority):
my_best_by_category = self.get_best_by_category(their_priority)
their_best_by_category = other.get_best_by_category(my_priority)

if not my_best_by_category or not their_best_by_category:
return False

result = self.swap_items(other, my_best_by_category, their_best_by_category)
return result

def get_newest(self, any_list=None):
# any_list = self.inventory if self.inventory is not None else []
# other version #
if any_list is None:
any_list = self.inventory

if not self.inventory or not any_list:
return None

return min(any_list, key=lambda item: item.age)

Choose a reason for hiding this comment

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

Nice use of a lambda!



def get_newest_by_category(self, category):
newest_items_with_category = self.get_by_category(category)
if not newest_items_with_category:
return None

newest_item = self.get_newest(newest_items_with_category)
return newest_item


def swap_newest(self, other):
my_newest_item = self.get_newest()
other_newest_item = other.get_newest()
if not my_newest_item or not other_newest_item:
return False

self.swap_items(other, my_newest_item, other_newest_item)
return True



def swap_newest_by_category(self, other, my_priority=None, their_priority=None):
my_newest_by_category = self.get_newest_by_category(their_priority)
their_newest_by_category = other.get_newest_by_category(my_priority)
if not my_newest_by_category or not their_newest_by_category:
return False

self.swap_items(other, my_newest_by_category, their_newest_by_category)
return True




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
14 changes: 8 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,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,9 @@ def test_removing_not_found_is_false():

result = vendor.remove(item)

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

#raise Exception("Complete this test according to comments below.")
# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************
10 changes: 6 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,9 @@ 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
Loading