diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index b8afdeb1e..a5b3db12e 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,2 +1,15 @@ -class Clothing: - pass \ No newline at end of file +from .item import Item + +class Clothing( Item ): + + def __init__( self, id = None, condition = None, fabric = None ): + super().__init__( id, condition ) + + if fabric == None: + self.fabric = "Unknown" + else: + self.fabric = fabric + + + def __str__( self ): + return f"An object of type {super().get_category()} with id {str(self.id)}. It is made from {str(self.fabric)} fabric." diff --git a/swap_meet/decor.py b/swap_meet/decor.py index eab7a9dbe..0249023e7 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,2 +1,18 @@ -class Decor: - pass \ No newline at end of file +from .item import Item + +class Decor( Item ): + + def __init__( self, id = None, condition = None, width = None, length = None ): + super().__init__(id, condition) + if not width: + self.width = 0 + else: + self.width = width + if not length: + self.lenght = 0 + else: + self.lenght = length + + def __str__(self): + + return f'''An object of type {super().get_category()} with id {str(self.id)}. It takes up a {str(self.width)} by {str(self.lenght)} sized space.''' \ No newline at end of file diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 2f9dff68a..96f92e3a8 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,2 +1,15 @@ -class Electronics: - pass +from .item import Item + +class Electronics(Item): + + def __init__( self, id = None, condition = None, type = None ): + super().__init__( id, condition ) + + if not type: + self.type = "Unknown" + else: + self.type = type + + + def __str__(self): + return f"An object of type {super().get_category()} with id {str(self.id)}. This is a {str(self.type)} device." diff --git a/swap_meet/item.py b/swap_meet/item.py index 560d759c2..3cc79d23b 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,2 +1,34 @@ +import uuid + class Item: - pass \ No newline at end of file + + def __init__( self, id = None, condition = None ): + if id == None: + self.id = uuid.uuid1().int + else: + self.id = id + + if condition == None: + self.condition = 0 + elif condition > 5 or condition < 0: + raise IndexError( "Please choose condition in range 0 - 5." ) + else: + self.condition = condition + + + def get_category( self ): + return self.__class__.__name__ + + + def __str__( self ): + return f"An object of type {self.get_category()} with id {str(self.id)}" + + + def condition_description( self ): + condition_list = ["Poor Condition", # condition = 0 + "Heavily Used", # condition = 1 + "Used - Good Condition", # condition = 2 + "Used - Very Good Condition", # condition = 3 + "Used - Great Condition", # condition = 4 + "New"] # condition = 5 + return condition_list[self.condition] \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 87302c056..1d6b15abd 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,2 +1,202 @@ class Vendor: - pass \ No newline at end of file + + def __init__( self, inventory = None ): + if inventory == None: + self.inventory = [] + else: + self.inventory = inventory + + + def add( self, item ): + self.inventory.append( item ) + return item + + + def remove( self, item ): + if self.inventory == None or item not in self.inventory: + return None + + self.inventory.remove( item ) + return item + + + def get_by_id (self, item_id ): + if not self.inventory: + return None + + for item in self.inventory: + if item.id == item_id: + return item + + return None + + + def swap_items( self, other_vendor, my_item, their_item ): + if not self.inventory or \ + not other_vendor.inventory or \ + not my_item or not their_item or \ + my_item not in self.inventory or \ + their_item not in other_vendor.inventory: + return False + + self.add( their_item ) + other_vendor.add( my_item ) + self.remove( my_item ) + other_vendor.remove( their_item ) + + return True + + + def swap_first_item( self, other_vendor ): + if not self.inventory or \ + not other_vendor.inventory: + return False + + return self.swap_items( other_vendor, self.inventory[0], other_vendor.inventory[0] ) + + + def get_by_category( self, category = None ): + list_of_objects = [] + + if not self.inventory or category == None: + return [] + + for item in self.inventory: + if item.get_category() == str(category): + list_of_objects.append( item ) + + return list_of_objects + + + def get_best_by_category( self, category ): + list_of_objects = self.get_by_category(category) + + if not list_of_objects: + return None + + best_item = list_of_objects[0] + for item in list_of_objects: + if item.condition > best_item.condition: + best_item = item + + return best_item + + + def swap_best_by_category( self, other_vendor, my_priority, their_priority ): + + best_item_for_them = self.get_best_by_category(their_priority) + best_item_for_me = other_vendor.get_best_by_category(my_priority) + + return self.swap_items(other_vendor, best_item_for_them, best_item_for_me) + + + def display_inventory(self, category = None): + if not self.inventory: + print("No inventory to display.") + return None + + if category == None: + + for index in range( len( self.inventory )): + print(f"{index+1}. {self.inventory[index]}") + + else: + count = 0 + for item in self.inventory: + if item.get_category() == category: + count += 1 + print(f"{count}. {item}") + + if count == 0: + print("No inventory to display.") + return None + + + def swap_by_id( self, other_vendor, my_item_id, their_item_id ): + my_item = self.get_by_id( my_item_id ) + their_item = other_vendor.get_by_id( their_item_id ) + + if not my_item or not their_item: + return False + + else: + return self.swap_items(other_vendor, my_item, their_item) + + def choose_and_swap_items( self, other_vendor, category = None ): + if category == None: + self.category = "" + else: + self.category = category + + self.display_inventory( self.category ) + other_vendor.display_inventory( self.category ) + + my_item_id = int( input( "Please enter the id of the item from my inventory:" )) + their_item_id = int( input( "Please enter the id of the item from their inventory:" )) + + if self.swap_by_id( other_vendor, my_item_id, their_item_id ): + return True + return False + +# Function swap first two clothing with the same attribute fabric +# If we want to swap all clothing with the same fabric +# we can use next function : swap_all_clothing_by_attributes( self, other_vendor ) + def swap_clothing_by_attributes( self, other_vendor ): + list_of_my_clothing = self.get_by_category( "Clothing" ) + list_of_their_clothing = other_vendor.get_by_category( "Clothing" ) + + for my_item in list_of_my_clothing: + for their_item in list_of_their_clothing: + + if my_item.fabric == their_item.fabric: + self.swap_by_id( other_vendor, my_item.id, their_item.id ) + return True + + return False + +# Function swap all clothing with the same attribute fabric + def swap_all_clothing_by_attributes( self, other_vendor ): + list_of_my_clothing = self.get_by_category( "Clothing" ) + list_of_their_clothing = other_vendor.get_by_category( "Clothing" ) + counter = 0 + + for my_item in list_of_my_clothing: + for their_item in list_of_their_clothing: + + if my_item.fabric == their_item.fabric: + counter +=1 + self.swap_by_id( other_vendor, my_item.id, their_item.id ) + + if counter > 0: + return True + + return False + + + def swap_decor_by_attributes( self, other_vendor ): + list_of_my_decor = self.get_by_category( "Decor" ) + list_of_their_decor = other_vendor.get_by_category( "Decor" ) + + for my_item in list_of_my_decor: + for their_item in list_of_their_decor: + + if my_item.width == their_item.width \ + and my_item.lenght == their_item.lenght \ + or my_item.width * my_item.lenght == their_item.width * their_item.lenght: + self.swap_by_id( other_vendor, my_item.id, their_item.id ) + return True + + return False + + def swap_electronics_by_attributes( self, other_vendor ): + list_of_my_electronics = self.get_by_category( "Electronics" ) + list_of_their_electronics = other_vendor.get_by_category( "Electronics" ) + + for my_item in list_of_my_electronics: + for their_item in list_of_their_electronics: + + if my_item.type == their_item.type: + self.swap_by_id( other_vendor, my_item.id, their_item.id ) + return True + + return False \ No newline at end of file diff --git a/tests/integration_tests/test_wave_01_02_03.py b/tests/integration_tests/test_wave_01_02_03.py index 404641a86..266808f30 100644 --- a/tests/integration_tests/test_wave_01_02_03.py +++ b/tests/integration_tests/test_wave_01_02_03.py @@ -2,7 +2,6 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip @pytest.mark.integration_test def test_integration_wave_01_02_03(): # make a vendor diff --git a/tests/integration_tests/test_wave_04_05_06_07.py b/tests/integration_tests/test_wave_04_05_06_07.py index cdbf79eaf..63fa63b9b 100644 --- a/tests/integration_tests/test_wave_04_05_06_07.py +++ b/tests/integration_tests/test_wave_04_05_06_07.py @@ -4,7 +4,6 @@ from swap_meet.decor import Decor from swap_meet.electronics import Electronics -@pytest.mark.skip @pytest.mark.integration_test def test_integration_wave_04_05_06(capfd): camila = Vendor() diff --git a/tests/my_tests/__init__.py b/tests/my_tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/my_tests/test_swap_by_same_atributes.py b/tests/my_tests/test_swap_by_same_atributes.py new file mode 100644 index 000000000..96a1abfa3 --- /dev/null +++ b/tests/my_tests/test_swap_by_same_atributes.py @@ -0,0 +1,443 @@ +import pytest +from swap_meet.item import Item +from swap_meet.vendor import Vendor +from swap_meet.clothing import Clothing +from swap_meet.decor import Decor +from swap_meet.electronics import Electronics + +############################################################################ +## testing swap clothing ## + +def test_swap_clothing_by_same_attributes_success_returns_true(): + # Arrange + item_a = Decor(id=123) + item_b = Clothing(fabric = "Cotton") + item_c = Decor(id=789) + tai = Vendor( + inventory=[item_a, item_b, item_c] + ) + + item_d = Clothing(fabric = "Cotton") + item_e = Decor(id=654) + item_f = Clothing(id=987) + jesse = Vendor( + inventory=[item_d, item_e, item_f] + ) + + # Act + result = tai.swap_clothing_by_attributes( + other_vendor=jesse) + + # Assert + assert result == True + + assert len(tai.inventory) == 3 + assert item_a in tai.inventory + assert item_c in tai.inventory + assert item_d in tai.inventory + + assert len(jesse.inventory) == 3 + assert item_b in jesse.inventory + assert item_e in jesse.inventory + assert item_f in jesse.inventory + + +def test_swap_all_clothing_by_same_attributes_success_returns_true(): + # Arrange + item_a = Clothing(fabric = "Silk") + item_b = Clothing(fabric = "Cotton") + item_c = Decor(id=789) + tai = Vendor( + inventory=[item_a, item_b, item_c] + ) + + item_d = Clothing(fabric = "Cotton") + item_e = Decor(id=654) + item_f = Clothing(fabric = "Silk") + jesse = Vendor( + inventory=[item_d, item_e, item_f] + ) + + # Act + result = tai.swap_all_clothing_by_attributes( + other_vendor=jesse) + + # Assert + assert result == True + + assert len(tai.inventory) == 3 + assert item_f in tai.inventory + assert item_c in tai.inventory + assert item_d in tai.inventory + + assert len(jesse.inventory) == 3 + assert item_b in jesse.inventory + assert item_e in jesse.inventory + assert item_a in jesse.inventory + + +def test_swap_one_clothing_by_same_attributes_more_then_one_success_returns_true(): + # Arrange + item_a = Decor(id=123) + item_b = Clothing(fabric = "Cotton") + item_c = Clothing(fabric = "Silk") + tai = Vendor( + inventory=[item_a, item_b, item_c] + ) + + item_d = Clothing(fabric = "Cotton") + item_e = Decor(id=654) + item_f = Clothing(fabric = "Silk") + jesse = Vendor( + inventory=[item_d, item_e, item_f] + ) + + # Act + result = tai.swap_clothing_by_attributes( + other_vendor=jesse) + + # Assert + assert result == True + + assert len(tai.inventory) == 3 + assert item_a in tai.inventory + assert item_c in tai.inventory + assert item_d in tai.inventory + + assert len(jesse.inventory) == 3 + assert item_b in jesse.inventory + assert item_e in jesse.inventory + assert item_f in jesse.inventory + + +def test_swap_clothing_by_same_attributes_empty_my_inventory_returns_False(): + # Arrange + tai = Vendor( + inventory=[] + ) + + item_a = Clothing(fabric = "Cotton") + item_b = Decor(id=654) + item_c = Clothing(id=987) + jesse = Vendor( + inventory=[item_a, item_b, item_c] + ) + + # Act + result = tai.swap_clothing_by_attributes( + other_vendor=jesse) + + # Assert + assert result == False + + assert len(tai.inventory) == 0 + assert len(jesse.inventory) == 3 + assert item_a in jesse.inventory + assert item_b in jesse.inventory + assert item_c in jesse.inventory + + +def test_swap_clothing_by_same_attributes_fails_if_caller_missing_item(): + # Arrange + item_b = Electronics(id=456) + item_c = Decor(id=789) + tai = Vendor( + inventory=[item_b, item_c] + ) + + item_d = Clothing(id=321) + item_e = Decor(id=654) + item_f = Clothing(fabric = "Floral") + jesse = Vendor( + inventory=[item_d, item_e, item_f] + ) + + # Act + result = tai.swap_clothing_by_attributes( + other_vendor=jesse) + + # Assert + assert result == False + + assert len(tai.inventory) == 2 + assert item_b in tai.inventory + assert item_c in tai.inventory + + assert len(jesse.inventory) == 3 + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_f in jesse.inventory + +def test_swap_clothing_by_same_attributes_fails_if_other_missing_item(): + # Arrange + item_a = Clothing(fabric = "Cotton") + item_b = Electronics(id=456) + item_c = Decor(id=789) + tai = Vendor( + inventory=[item_a, item_b, item_c] + ) + + item_e = Decor(id=654) + jesse = Vendor( + inventory=[item_e] + ) + + # Act + result = tai.swap_clothing_by_attributes( + other_vendor=jesse) + + # Assert + assert result == False + + assert len(tai.inventory) == 3 + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_c in tai.inventory + + assert len(jesse.inventory) == 1 + assert item_e in jesse.inventory + +############################################################################ +## testing swap decor ## + +def test_swap_decor_by_same_attributes_success_returns_true(): + # Arrange + item_a = Decor(width = 10, length = 20) + item_b = Clothing(fabric = "Cotton") + item_c = Decor(id=789) + tai = Vendor( + inventory=[item_a, item_b, item_c] + ) + + item_d = Clothing(fabric = "Cotton") + item_e = Decor(width = 10, length = 20) + item_f = Clothing(id=987) + jesse = Vendor( + inventory=[item_d, item_e, item_f] + ) + + # Act + result = tai.swap_decor_by_attributes( + other_vendor=jesse) + + # Assert + assert result == True + + assert len(tai.inventory) == 3 + assert item_e in tai.inventory + assert item_b in tai.inventory + assert item_c in tai.inventory + + assert len(jesse.inventory) == 3 + assert item_a in jesse.inventory + assert item_d in jesse.inventory + assert item_f in jesse.inventory + +def test_swap_decor_by_same_attributes_empty_my_inventory_returns_False(): + # Arrange + tai = Vendor( + inventory=[] + ) + + item_a = Clothing(fabric = "Cotton") + item_b = Decor(id=654) + item_c = Clothing(id=987) + jesse = Vendor( + inventory=[item_a, item_b, item_c] + ) + + # Act + result = tai.swap_decor_by_attributes( + other_vendor=jesse) + + # Assert + assert result == False + + assert len(tai.inventory) == 0 + assert len(jesse.inventory) == 3 + assert item_a in jesse.inventory + assert item_b in jesse.inventory + assert item_c in jesse.inventory + + +def test_swap_decor_by_same_attributes_fails_if_caller_missing_item(): + # Arrange + item_a = Clothing(fabric = "Cotton") + item_b = Electronics(id=456) + tai = Vendor( + inventory=[item_a, item_b] + ) + + item_d = Clothing(id=321) + item_f = Clothing(fabric = "Floral") + item_e = Decor(width = 10, length = 20) + jesse = Vendor( + inventory=[item_d, item_e, item_f] + ) + + # Act + result = tai.swap_decor_by_attributes( + other_vendor=jesse) + + # Assert + assert result == False + + assert len(tai.inventory) == 2 + assert item_a in tai.inventory + assert item_b in tai.inventory + assert len(jesse.inventory) == 3 + assert item_d in jesse.inventory + assert item_f in jesse.inventory + assert item_e in jesse.inventory + +def test_swap_decor_by_same_attributes_fails_if_other_missing_item(): + # Arrange + item_a = Clothing(fabric = "Cotton") + item_b = Electronics(id=456) + item_c = Decor(width = 10, length = 20) + tai = Vendor( + inventory=[item_a, item_b, item_c] + ) + + item_e = Clothing(id=654) + jesse = Vendor( + inventory=[item_e] + ) + + # Act + result = tai.swap_decor_by_attributes( + other_vendor=jesse) + + # Assert + assert result == False + + assert len(tai.inventory) == 3 + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_c in tai.inventory + + assert len(jesse.inventory) == 1 + assert item_e in jesse.inventory +############################################################################ +## testing swap electronics ## + +def test_swap_electronics_by_same_attributes_success_returns_true(): + # Arrange + item_a = Electronics(type = "Phone") + item_b = Electronics(type = "TV") + item_c = Decor(id=789) + tai = Vendor( + inventory=[item_a, item_b, item_c] + ) + + item_d = Electronics(type = "TV") + item_e = Decor(id=654) + item_f = Clothing(id=987) + jesse = Vendor( + inventory=[item_d, item_e, item_f] + ) + + # Act + result = tai.swap_electronics_by_attributes( + other_vendor=jesse) + + # Assert + assert result == True + + assert len(tai.inventory) == 3 + assert item_a in tai.inventory + assert item_c in tai.inventory + assert item_d in tai.inventory + + assert len(jesse.inventory) == 3 + assert item_b in jesse.inventory + assert item_e in jesse.inventory + assert item_f in jesse.inventory + +def test_swap_electronics_by_same_attributes_empty_my_inventory_returns_False(): + # Arrange + tai = Vendor( + inventory=[] + ) + + item_a = Clothing(fabric = "Cotton") + item_b = Decor(id=654) + item_c = Clothing(id=987) + jesse = Vendor( + inventory=[item_a, item_b, item_c] + ) + + # Act + result = tai.swap_electronics_by_attributes( + other_vendor=jesse) + + # Assert + assert result == False + + assert len(tai.inventory) == 0 + assert len(jesse.inventory) == 3 + assert item_a in jesse.inventory + assert item_b in jesse.inventory + assert item_c in jesse.inventory + +def test_swap_electronics_by_same_attributes_fails_if_caller_missing_item(): + # Arrange + item_a = Clothing(fabric = "Cotton") + item_b = Decor(id=654) + item_c = Decor(id=789) + tai = Vendor( + inventory=[item_a, item_b, item_c] + ) + + item_d = Clothing(id=321) + item_e = Electronics(type = "TV") + item_f = Clothing(fabric = "Floral") + jesse = Vendor( + inventory=[item_d, item_e, item_f] + ) + + # Act + result = tai.swap_electronics_by_attributes( + other_vendor=jesse) + + # Assert + assert result == False + + assert len(tai.inventory) == 3 + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_c in tai.inventory + + assert len(jesse.inventory) == 3 + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_f in jesse.inventory + +def test_swap_electronics_by_same_attributes_fails_if_other_missing_item(): + # Arrange + item_a = Clothing(fabric = "Cotton") + item_b = Electronics(type = "TV") + item_c = Decor(id=789) + tai = Vendor( + inventory=[item_a, item_b, item_c] + ) + + item_e = Decor(id=654) + jesse = Vendor( + inventory=[item_e] + ) + + # Act + result = tai.swap_clothing_by_attributes( + other_vendor=jesse) + + # Assert + assert result == False + + assert len(tai.inventory) == 3 + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_c in tai.inventory + + assert len(jesse.inventory) == 1 + assert item_e in jesse.inventory \ No newline at end of file diff --git a/tests/unit_tests/test_wave_01.py b/tests/unit_tests/test_wave_01.py index 019ff1d58..7a7e3e135 100644 --- a/tests/unit_tests/test_wave_01.py +++ b/tests/unit_tests/test_wave_01.py @@ -2,12 +2,10 @@ import pytest from swap_meet.vendor import Vendor -@pytest.mark.skip def test_vendor_has_inventory(): vendor = Vendor() assert len(vendor.inventory) == 0 -@pytest.mark.skip def test_vendor_takes_optional_inventory(): inventory = ["a", "b", "c"] vendor = Vendor(inventory=inventory) @@ -16,7 +14,6 @@ def test_vendor_takes_optional_inventory(): assert "b" in vendor.inventory assert "c" in vendor.inventory -@pytest.mark.skip def test_adding_to_inventory(): vendor = Vendor() item = "new item" @@ -27,7 +24,6 @@ def test_adding_to_inventory(): assert item in vendor.inventory assert result == item -@pytest.mark.skip def test_removing_from_inventory_returns_item(): item = "item to remove" vendor = Vendor( @@ -40,7 +36,6 @@ def test_removing_from_inventory_returns_item(): assert item not in vendor.inventory assert result == item -@pytest.mark.skip def test_removing_not_found_returns_none(): item = "item to remove" vendor = Vendor( @@ -48,8 +43,4 @@ def test_removing_not_found_returns_none(): ) result = vendor.remove(item) - - raise Exception("Complete this test according to comments below.") - # ********************************************************************* - # ****** Complete Assert Portion of this test ********** - # ********************************************************************* + assert result == None diff --git a/tests/unit_tests/test_wave_02.py b/tests/unit_tests/test_wave_02.py index f4b512222..c82ae5f3b 100644 --- a/tests/unit_tests/test_wave_02.py +++ b/tests/unit_tests/test_wave_02.py @@ -2,30 +2,25 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip def test_items_have_default_uuid_length_id(): item = Item() assert isinstance(item.id, int) assert len(str(item.id)) >= 32 -@pytest.mark.skip def test_item_instances_have_different_default_ids(): item_a = Item() item_b = Item() assert item_a.id != item_b.id -@pytest.mark.skip def test_items_use_custom_id_if_passed(): item = Item(id=12345) assert isinstance(item.id, int) assert item.id == 12345 -@pytest.mark.skip def test_item_obj_returns_text_item_for_category(): item = Item() assert item.get_category() == "Item" -@pytest.mark.skip def test_get_item_by_id(): test_id = 12345 item_custom_id = Item(id=test_id) @@ -36,15 +31,12 @@ def test_get_item_by_id(): result_item = vendor.get_by_id(test_id) assert result_item is item_custom_id -@pytest.mark.skip def test_get_item_by_id_no_matching(): test_id = 12345 item_a = Item() item_b = Item() item_c = Item() - vendor = Vendor( - inventory=[item_a, item_b, item_c] - ) + vendor = Vendor(inventory=[item_a, item_b, item_c]) result_item = vendor.get_by_id(test_id) assert result_item is None diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index d4fd96017..0ce297da1 100644 --- a/tests/unit_tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -2,7 +2,6 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip def test_item_overrides_to_string(): test_id = 12345 item = Item(id=test_id) @@ -12,7 +11,6 @@ def test_item_overrides_to_string(): expected_result = f"An object of type Item with id {test_id}" assert item_as_string == expected_result -@pytest.mark.skip def test_swap_items_returns_true(): item_a = Item() item_b = Item() @@ -40,7 +38,6 @@ def test_swap_items_returns_true(): assert item_b in jolie.inventory assert result -@pytest.mark.skip def test_swap_items_when_my_item_is_missing_returns_false(): item_a = Item() item_b = Item() @@ -67,7 +64,6 @@ def test_swap_items_when_my_item_is_missing_returns_false(): assert item_e in jolie.inventory assert not result -@pytest.mark.skip def test_swap_items_when_their_item_is_missing_returns_false(): item_a = Item() item_b = Item() @@ -94,7 +90,7 @@ def test_swap_items_when_their_item_is_missing_returns_false(): assert item_e in jolie.inventory assert not result -@pytest.mark.skip + def test_swap_items_from_my_empty_returns_false(): fatimah = Vendor( inventory=[] @@ -114,7 +110,6 @@ def test_swap_items_from_my_empty_returns_false(): assert len(jolie.inventory) == 2 assert not result -@pytest.mark.skip def test_swap_items_from_their_empty_returns_false(): item_a = Item() item_b = Item() @@ -122,6 +117,7 @@ def test_swap_items_from_their_empty_returns_false(): fatimah = Vendor( inventory=[item_a, item_b, item_c] ) + fatimah_len_l = len(fatimah.inventory) jolie = Vendor( inventory=[] @@ -131,7 +127,6 @@ def test_swap_items_from_their_empty_returns_false(): result = fatimah.swap_items(jolie, item_b, nobodys_item) - raise Exception("Complete this test according to comments below.") - # ********************************************************************* - # ****** Complete Assert Portion of this test ********** - # ********************************************************************* + assert result == False + assert len(jolie.inventory) == 0 + assert len(fatimah.inventory) == fatimah_len_l diff --git a/tests/unit_tests/test_wave_04.py b/tests/unit_tests/test_wave_04.py index 87addbbf6..156dda5d2 100644 --- a/tests/unit_tests/test_wave_04.py +++ b/tests/unit_tests/test_wave_04.py @@ -2,7 +2,6 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip def test_swap_first_item_returns_true(): item_a = Item() item_b = Item() @@ -30,7 +29,6 @@ def test_swap_first_item_returns_true(): assert item_a in jolie.inventory assert result -@pytest.mark.skip def test_swap_first_item_from_my_empty_returns_false(): fatimah = Vendor( inventory=[] @@ -48,7 +46,6 @@ def test_swap_first_item_from_my_empty_returns_false(): assert len(jolie.inventory) == 2 assert not result -@pytest.mark.skip def test_swap_first_item_from_their_empty_returns_false(): item_a = Item() item_b = Item() diff --git a/tests/unit_tests/test_wave_05.py b/tests/unit_tests/test_wave_05.py index 7770aee07..e1dd3125b 100644 --- a/tests/unit_tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -7,17 +7,14 @@ # ~~~~~ Clothing Tests ~~~~~ -@pytest.mark.skip def test_clothing_has_default_uuid_length_id(): clothing = Clothing() check_for_default_uuid_length_id(clothing) -@pytest.mark.skip def test_clothing_has_expected_category_and_custom_id(): clothing = Clothing(id=TEST_CUSTOM_ID) check_category_and_custom_id(clothing, TEST_CUSTOM_ID, "Clothing") -@pytest.mark.skip def test_clothing_has_expected_default_to_str(): clothing = Clothing(id=TEST_CUSTOM_ID) expected_str = ( @@ -26,7 +23,6 @@ def test_clothing_has_expected_default_to_str(): ) assert str(clothing) == expected_str -@pytest.mark.skip def test_clothing_has_expected_to_str_with_custom_fabric(): clothing = Clothing(id=TEST_CUSTOM_ID, fabric="Pinstriped") expected_str = ( @@ -37,17 +33,14 @@ def test_clothing_has_expected_to_str_with_custom_fabric(): # ~~~~~ Decor Tests ~~~~~ -@pytest.mark.skip def test_decor_has_default_uuid_length_id(): decor = Decor() check_for_default_uuid_length_id(decor) -@pytest.mark.skip def test_decor_has_expected_category_and_custom_id(): decor = Decor(id=TEST_CUSTOM_ID) check_category_and_custom_id(decor, TEST_CUSTOM_ID, "Decor") -@pytest.mark.skip def test_decor_has_expected_default_to_str(): decor = Decor(id=TEST_CUSTOM_ID) expected_str = ( @@ -56,7 +49,6 @@ def test_decor_has_expected_default_to_str(): ) assert str(decor) == expected_str -@pytest.mark.skip def test_decor_has_expected_to_str_with_custom_size(): decor = Decor(id=TEST_CUSTOM_ID, width=3, length=12) expected_str = ( @@ -67,17 +59,14 @@ def test_decor_has_expected_to_str_with_custom_size(): # ~~~~~ Electronics Tests ~~~~~ -@pytest.mark.skip def test_electronics_has_default_uuid_length_id(): electronics = Electronics() check_for_default_uuid_length_id(electronics) -@pytest.mark.skip def test_electronics_has_expected_category_and_custom_id(): electronics = Electronics(id=TEST_CUSTOM_ID) check_category_and_custom_id(electronics, TEST_CUSTOM_ID, "Electronics") -@pytest.mark.skip def test_electronics_has_expected_default_to_str(): electronics = Electronics(id=TEST_CUSTOM_ID) expected_str = ( @@ -86,7 +75,6 @@ def test_electronics_has_expected_default_to_str(): ) assert str(electronics) == expected_str -@pytest.mark.skip def test_electronics_has_expected_to_str_with_custom_type(): electronics = Electronics(id=TEST_CUSTOM_ID, type="Mobile Phone") expected_str = ( @@ -97,7 +85,6 @@ def test_electronics_has_expected_to_str_with_custom_type(): # ~~~~~ Item Tests ~~~~~ -@pytest.mark.skip def test_items_have_condition_as_float(): items = [ Clothing(condition=3.5), @@ -107,7 +94,6 @@ def test_items_have_condition_as_float(): for item in items: assert item.condition == pytest.approx(3.5) -@pytest.mark.skip def test_items_have_condition_descriptions_that_are_the_same_regardless_of_type(): items = [ Clothing(condition=5), diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index ad51bf42d..88afd1f65 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -5,7 +5,6 @@ from swap_meet.decor import Decor from swap_meet.electronics import Electronics -@pytest.mark.skip def test_get_items_by_category(): item_a = Clothing() item_b = Electronics() @@ -22,7 +21,6 @@ def test_get_items_by_category(): assert item_a in items assert item_c in items -@pytest.mark.skip def test_get_no_matching_items_by_category(): item_a = Clothing() item_b = Item() @@ -32,13 +30,9 @@ def test_get_no_matching_items_by_category(): ) items = vendor.get_by_category("Electronics") + assert items == [] + assert len(items) == 0 - raise Exception("Complete this test according to comments below.") - # ********************************************************************* - # ****** Complete Assert Portion of this test ********** - # ********************************************************************* - -@pytest.mark.skip def test_best_by_category(): item_a = Clothing(condition=2.0) item_b = Decor(condition=2.0) @@ -54,7 +48,6 @@ def test_best_by_category(): assert best_item.get_category() == "Clothing" assert best_item.condition == pytest.approx(4.0) -@pytest.mark.skip def test_best_by_category_no_matches_is_none(): item_a = Decor(condition=2.0) item_b = Decor(condition=2.0) @@ -67,7 +60,6 @@ def test_best_by_category_no_matches_is_none(): assert best_item is None -@pytest.mark.skip def test_best_by_category_with_duplicates(): # Arrange item_a = Clothing(condition=2.0) @@ -84,7 +76,6 @@ def test_best_by_category_with_duplicates(): assert best_item.get_category() == "Clothing" assert best_item.condition == pytest.approx(4.0) -@pytest.mark.skip def test_swap_best_by_category(): # Arrange # me @@ -94,6 +85,8 @@ def test_swap_best_by_category(): tai = Vendor( inventory=[item_a, item_b, item_c] ) + tai_inventory_len = len(tai.inventory) + tai_best_item = tai.get_best_by_category("Decor") # them item_d = Clothing(condition=2.0) @@ -102,7 +95,10 @@ def test_swap_best_by_category(): jesse = Vendor( inventory=[item_d, item_e, item_f] ) - + jesse_inventary_len = len(jesse.inventory) + jesse_best_item = jesse.get_best_by_category("Clothing") + + # Act result = tai.swap_best_by_category( other_vendor=jesse, @@ -110,16 +106,13 @@ def test_swap_best_by_category(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") - # ********************************************************************* - # ****** Complete Assert Portion of this test ********** - # ********************************************************************* - # Assertions should check: - # - That the results is truthy - # - That tai and jesse's inventories are the correct length - # - That all the correct items are in tai and jesse's inventories, including the items which were swapped from one vendor to the other + assert result + assert len(tai.inventory) == tai_inventory_len # 3 + assert len(jesse.inventory) == jesse_inventary_len # 3 + assert tai_best_item in jesse.inventory + assert jesse_best_item in tai.inventory + -@pytest.mark.skip def test_swap_best_by_category_reordered(): # Arrange item_a = Decor(condition=2.0) @@ -128,14 +121,18 @@ def test_swap_best_by_category_reordered(): tai = Vendor( inventory=[item_c, item_b, item_a] ) - + tai_inventory_len = len(tai.inventory) + tai_best_item = tai.get_best_by_category("Decor") + item_d = Clothing(condition=2.0) item_e = Decor(condition=4.0) item_f = Clothing(condition=4.0) jesse = Vendor( inventory=[item_f, item_e, item_d] ) - + jesse_inventary_len = len(jesse.inventory) + jesse_best_item = jesse.get_best_by_category("Clothing") + # Act result = tai.swap_best_by_category( other_vendor=jesse, @@ -143,7 +140,11 @@ def test_swap_best_by_category_reordered(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") + assert result + assert len(tai.inventory) == tai_inventory_len # 3 + assert len(jesse.inventory) == jesse_inventary_len # 3 + assert tai_best_item in jesse.inventory + assert jesse_best_item in tai.inventory # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* @@ -152,7 +153,6 @@ def test_swap_best_by_category_reordered(): # - That tai and jesse's inventories are the correct length # - That all the correct items are in tai and jesse's inventories, and that the items that were swapped are not there -@pytest.mark.skip def test_swap_best_by_category_no_inventory_is_false(): tai = Vendor( inventory=[] @@ -178,7 +178,6 @@ def test_swap_best_by_category_no_inventory_is_false(): assert item_b in jesse.inventory assert item_c in jesse.inventory -@pytest.mark.skip def test_swap_best_by_category_no_other_inventory_is_false(): item_a = Clothing(condition=2.0) item_b = Decor(condition=4.0) @@ -204,7 +203,6 @@ def test_swap_best_by_category_no_other_inventory_is_false(): assert item_b in tai.inventory assert item_c in tai.inventory -@pytest.mark.skip def test_swap_best_by_category_no_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -228,16 +226,18 @@ def test_swap_best_by_category_no_match_is_false(): their_priority="Clothing" ) - raise Exception("Complete this test according to comments below.") - # ********************************************************************* - # ****** Complete Assert Portion of this test ********** - # ********************************************************************* - # Assertions should check: - # - That result is falsy - # - That tai and jesse's inventories are the correct length - # - That all the correct items are in tai and jesse's inventories + assert not result + assert len(tai.inventory) == 3 + assert len(jesse.inventory) == 3 + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_c in tai.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_f in jesse.inventory + assert tai.get_by_category("Clothing") == [] + -@pytest.mark.skip def test_swap_best_by_category_no_other_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -261,11 +261,13 @@ def test_swap_best_by_category_no_other_match_is_false(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") - # ********************************************************************* - # ****** Complete Assert Portion of this test ********** - # ********************************************************************* - # Assertions should check: - # - That result is falsy - # - That tai and jesse's inventories are the correct length - # - That all the correct items are in tai and jesse's inventories + assert not result + assert len(tai.inventory) == 3 + assert len(jesse.inventory) == 3 + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_c in tai.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_f in jesse.inventory + diff --git a/tests/unit_tests/test_wave_07.py b/tests/unit_tests/test_wave_07.py index 005b82ecc..c2b1aa530 100644 --- a/tests/unit_tests/test_wave_07.py +++ b/tests/unit_tests/test_wave_07.py @@ -7,7 +7,6 @@ # ~~~~~ display_inventory Tests ~~~~~ -@pytest.mark.skip def test_display_inventory_with_items_no_category(capfd): # Arrange item_a = Clothing(id=123, fabric="Striped") @@ -31,7 +30,6 @@ def test_display_inventory_with_items_no_category(capfd): ) assert captured.out == expected_str -@pytest.mark.skip def test_display_inventory_with_items_and_category(capfd): # Arrange item_a = Decor(id=123, width=2, length=4) @@ -52,7 +50,6 @@ def test_display_inventory_with_items_and_category(capfd): ) assert captured.out == expected_str -@pytest.mark.skip def test_display_inventory_with_category_and_no_matching_items(capfd): # Arrange item_a = Decor(id=123, width=2, length=4) @@ -72,7 +69,6 @@ def test_display_inventory_with_category_and_no_matching_items(capfd): ) assert captured.out == expected_str -@pytest.mark.skip def test_display_inventory_no_items_no_category(capfd): # Arrange vendor = Vendor(inventory=[]) @@ -87,7 +83,6 @@ def test_display_inventory_no_items_no_category(capfd): ) assert captured.out == expected_str -@pytest.mark.skip def test_display_inventory_no_items_with_category(capfd): # Arrange vendor = Vendor(inventory=[]) @@ -104,7 +99,6 @@ def test_display_inventory_no_items_with_category(capfd): # ~~~~~ swap_by_id Tests ~~~~~ -@pytest.mark.skip def test_swap_by_id_success_returns_true(): # Arrange item_a = Decor(id=123) @@ -141,7 +135,6 @@ def test_swap_by_id_success_returns_true(): assert item_e in jesse.inventory assert item_f in jesse.inventory -@pytest.mark.skip def test_swap_by_id_with_caller_empty_inventory_returns_false(): # Arrange tai = Vendor(inventory=[]) @@ -169,7 +162,6 @@ def test_swap_by_id_with_caller_empty_inventory_returns_false(): assert item_e in jesse.inventory assert item_f in jesse.inventory -@pytest.mark.skip def test_swap_by_id_with_other_empty_inventory_returns_false(): # Arrange item_a = Decor(id=123) @@ -198,7 +190,6 @@ def test_swap_by_id_with_other_empty_inventory_returns_false(): assert len(jesse.inventory) == 0 -@pytest.mark.skip def test_swap_by_id_fails_if_caller_missing_item(): # Arrange item_a = Decor(id=123) @@ -235,7 +226,6 @@ def test_swap_by_id_fails_if_caller_missing_item(): assert item_e in jesse.inventory assert item_f in jesse.inventory -@pytest.mark.skip def test_swap_by_id_fails_if_other_missing_item(): # Arrange item_a = Decor(id=123) @@ -274,7 +264,6 @@ def test_swap_by_id_fails_if_other_missing_item(): # ~~~~~ choose_and_swap_items Tests ~~~~~ -@pytest.mark.skip def test_choose_and_swap_items_success(monkeypatch): # Arrange item_a = Decor(id=123) @@ -311,7 +300,6 @@ def test_choose_and_swap_items_success(monkeypatch): assert item_d in jesse.inventory assert item_e in jesse.inventory -@pytest.mark.skip def test_choose_and_swap_items_with_calling_inventory_empty(monkeypatch): # Arrange tai = Vendor(inventory=[]) @@ -339,7 +327,6 @@ def test_choose_and_swap_items_with_calling_inventory_empty(monkeypatch): assert item_e in jesse.inventory assert item_f in jesse.inventory -@pytest.mark.skip def test_choose_and_swap_items_with_other_inventory_empty(monkeypatch): # Arrange item_a = Decor(id=123) @@ -368,7 +355,6 @@ def test_choose_and_swap_items_with_other_inventory_empty(monkeypatch): assert len(jesse.inventory) == 0 -@pytest.mark.skip def test_choose_and_swap_items_with_caller_missing_item(monkeypatch): # Arrange item_a = Decor(id=123) @@ -405,7 +391,6 @@ def test_choose_and_swap_items_with_caller_missing_item(monkeypatch): assert item_e in jesse.inventory assert item_f in jesse.inventory -@pytest.mark.skip def test_choose_and_swap_items_with_other_vendor_missing_item(monkeypatch): # Arrange item_a = Decor(id=123)