diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index b8afdeb1e..b00f6482c 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,2 +1,11 @@ -class Clothing: - pass \ No newline at end of file +# Wave 5 +import uuid +from swap_meet.item import Item +class Clothing(Item): + def __init__(self, id = None, category = "", condition = 0, fabric = "Unknown"): + super().__init__(id, category, condition) + self.fabric = fabric + + def __str__(self): + item_message = super().__str__() + return f"{item_message}. It is made from {self.fabric} fabric." \ No newline at end of file diff --git a/swap_meet/decor.py b/swap_meet/decor.py index eab7a9dbe..2908cd44c 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,2 +1,12 @@ -class Decor: - pass \ No newline at end of file +# Wave 5 +import uuid +from swap_meet.item import Item +class Decor(Item): + def __init__(self, id = None, category = "", condition = 0, width = 0, length = 0): + super().__init__(id, category, condition) + self.width = width + self.length = length + + def __str__(self): + item_message = super().__str__() + return f"{item_message}. It takes up a {self.width} by {self.length} sized space." \ No newline at end of file diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 2f9dff68a..beeb9f105 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,2 +1,12 @@ -class Electronics: - pass +# Wave 5 +import uuid +from swap_meet.item import Item +class Electronics(Item): + def __init__(self, id = None, category = "", condition = 0, type = "Unknown"): + super().__init__(id, category, condition) + self.type = type + + def __str__(self): + item_message = super().__str__() + return f"{item_message}. This is a {self.type} device." + \ No newline at end of file diff --git a/swap_meet/item.py b/swap_meet/item.py index 560d759c2..ae6b14662 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,2 +1,28 @@ +#Wave 2 , 5 +from math import floor +import uuid +#from swap_meet.vendor import Vendor class Item: - pass \ No newline at end of file + def __init__(self, id = None, category = "", condition = 0): + + if id is not None and not isinstance(id,int): + raise ValueError("ID must be an integer") + self.id = id if id else uuid.uuid4().int + self.condition = condition + self.category = category + + def get_category(self): + return self.__class__.__name__#type(self).__name__ I would like to know which is best practice in these two + + +# Wave 3 + def __str__(self): + return f"An object of type {self.get_category()} with id {self.id}" + +# Wave 5 + def condition_description(self): + description_of_condition = ["Mint","Heavily Used","Like New","Gently Used","Best Used","New"] + + return description_of_condition[round(self.condition)] + + diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 87302c056..25738df61 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,2 +1,121 @@ +#Wave 1 + class Vendor: - pass \ No newline at end of file + def __init__(self, inventory = None): + if inventory is not None: + self.inventory = inventory + else: + self.inventory = [] + + def add(self, new_item): + self.inventory.append(new_item) + return new_item + + def remove(self, item_to_remove): + if item_to_remove in self.inventory: + self.inventory.remove(item_to_remove) + return item_to_remove + return None + + def get_by_id(self, id): + if id is None: + return None + for item in self.inventory: + if item.id == id: + return item + return None + +# Wave 3 + 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 + self.remove(my_item) + other_vendor.add(my_item) + other_vendor.remove(their_item) + self.add(their_item) + return True + +# Wave 4 + def swap_first_item(self, other_vendor): + if not self.inventory or not other_vendor.inventory: + return False + self.swap_items(other_vendor,self.inventory[0],other_vendor.inventory[0]) + return True + +# Wave 6 + def get_by_category(self, category): + if not self.inventory: + return [] + list_items_by_category = [] + + for item in self.inventory: + if item.get_category() == category: + list_items_by_category.append(item) + return list_items_by_category + + def get_best_by_category(self, category): + list_of_items_in_category = self.get_by_category(category) + if not list_of_items_in_category: + return None + best_item = max(list_of_items_in_category,key = lambda item: item.condition) + return best_item + + def swap_best_by_category(self, other_vendor, my_priority, their_priority): + best_item_from_my_inventory = self.get_best_by_category(their_priority) + best_item_from_their_inventory = other_vendor.get_best_by_category(my_priority) + if not best_item_from_my_inventory or not best_item_from_their_inventory: + return False + self.swap_items(other_vendor,best_item_from_my_inventory,best_item_from_their_inventory) + return True + +#Wave 7 + def display_inventory(self, category = ""): + if self.inventory == []: + print("No inventory to display.") + return + display_items = self.get_by_category(category) if category else self.inventory + + if not display_items: + print("No inventory to display.") + return + else: + for index, item in enumerate(display_items, start=1): + print(f"{index}. {item}") + return + + def swap_by_id(self, other_vendor, my_item_id = None, their_item_id = None): + my_item = self.get_by_id(my_item_id) + vendor_item = other_vendor.get_by_id(their_item_id) + if not my_item or not vendor_item: + return False + result = self.swap_items(other_vendor, my_item, vendor_item) + return result + + def choose_and_swap_items(self, other_vendor, category = ""): + if not category: + self.display_inventory() + other_vendor.display_inventory() + else: + self.display_inventory(category) + other_vendor.display_inventory(category) + my_item_id = int(input("Enter Id of the item you want to swap")) + vendor_item_id = int(input("Enter Id of your friend vendor's item you want to swap with")) + if not self.get_by_id(my_item_id) or not other_vendor.get_by_id(vendor_item_id): + return False + self.swap_by_id(other_vendor,my_item_id,vendor_item_id) + return True +''' + for index in range(len(display_items)): + print(f"{index +1}. {display_items[index]}") + return + + if category: + inventory_items_by_category = self.get_by_category(category) + if inventory_items_by_category: + for index in range(len(inventory_items_by_category)): + print(f"{index +1}. {inventory_items_by_category[index]}") + else: + print("No inventory to display.") + else: + for index in range(len(self.inventory)): + print(f"{index +1}. {self.inventory[index]}")''' \ 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..e3a892ea2 100644 --- a/tests/integration_tests/test_wave_01_02_03.py +++ b/tests/integration_tests/test_wave_01_02_03.py @@ -2,7 +2,7 @@ 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 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..3d5e628b5 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,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(capfd): camila = Vendor() diff --git a/tests/unit_tests/test_wave_01.py b/tests/unit_tests/test_wave_01.py index 019ff1d58..b6f57c0c9 100644 --- a/tests/unit_tests/test_wave_01.py +++ b/tests/unit_tests/test_wave_01.py @@ -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) @@ -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" @@ -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( @@ -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_returns_none(): item = "item to remove" vendor = Vendor( @@ -48,8 +48,15 @@ def test_removing_not_found_returns_none(): ) result = vendor.remove(item) - - raise Exception("Complete this test according to comments below.") + #assert + assert result == None + assert item not in vendor.inventory + assert len(vendor.inventory) == 3 + assert "a" in vendor.inventory + assert "b" in vendor.inventory + assert "c" in vendor.inventory + + #raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* diff --git a/tests/unit_tests/test_wave_02.py b/tests/unit_tests/test_wave_02.py index f4b512222..58a9d9e70 100644 --- a/tests/unit_tests/test_wave_02.py +++ b/tests/unit_tests/test_wave_02.py @@ -2,30 +2,31 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip +#@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 + +#@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 +#@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 +#@pytest.mark.skip def test_item_obj_returns_text_item_for_category(): item = Item() assert item.get_category() == "Item" -@pytest.mark.skip +#@pytest.mark.skip def test_get_item_by_id(): test_id = 12345 item_custom_id = Item(id=test_id) @@ -35,8 +36,21 @@ def test_get_item_by_id(): result_item = vendor.get_by_id(test_id) assert result_item is item_custom_id +######### New Test for Code coverage +#@pytest.mark.skip +def test_get_by_id_for_none_id(): + #Arrange + + item_with_no_id = Item() + vendor = Vendor( + inventory=[Item(),Item(),item_with_no_id] + ) + result_item = vendor.get_by_id(None) + #Assert + assert result_item == None + -@pytest.mark.skip +#@pytest.mark.skip def test_get_item_by_id_no_matching(): test_id = 12345 item_a = Item() @@ -47,6 +61,7 @@ def test_get_item_by_id_no_matching(): ) result_item = vendor.get_by_id(test_id) + assert result_item is None items = vendor.inventory diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index d4fd96017..6299044fa 100644 --- a/tests/unit_tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -2,7 +2,7 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip +#@pytest.mark.skip def test_item_overrides_to_string(): test_id = 12345 item = Item(id=test_id) @@ -12,7 +12,7 @@ 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 +#@pytest.mark.skip def test_swap_items_returns_true(): item_a = Item() item_b = Item() @@ -40,7 +40,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() item_b = Item() @@ -67,7 +67,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() item_b = Item() @@ -94,7 +94,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=[] @@ -114,7 +114,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() item_b = Item() @@ -130,8 +130,16 @@ def test_swap_items_from_their_empty_returns_false(): nobodys_item = Item() result = fatimah.swap_items(jolie, item_b, nobodys_item) - - raise Exception("Complete this test according to comments below.") + # Assert + assert result == False + assert nobodys_item not in fatimah.inventory + assert nobodys_item not in jolie.inventory + assert fatimah.inventory == [item_a, item_b, item_c] + assert jolie.inventory == [] + assert item_a in fatimah.inventory + assert item_b in fatimah.inventory + assert item_c in fatimah.inventory + #raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* diff --git a/tests/unit_tests/test_wave_04.py b/tests/unit_tests/test_wave_04.py index 87addbbf6..3d1433d1d 100644 --- a/tests/unit_tests/test_wave_04.py +++ b/tests/unit_tests/test_wave_04.py @@ -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() item_b = Item() @@ -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=[] @@ -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() item_b = Item() diff --git a/tests/unit_tests/test_wave_05.py b/tests/unit_tests/test_wave_05.py index 7770aee07..d13a34efd 100644 --- a/tests/unit_tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -7,17 +7,17 @@ # ~~~~~ Clothing Tests ~~~~~ -@pytest.mark.skip +#@pytest.mark.skip def test_clothing_has_default_uuid_length_id(): clothing = Clothing() check_for_default_uuid_length_id(clothing) -@pytest.mark.skip +#@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 +#@pytest.mark.skip def test_clothing_has_expected_default_to_str(): clothing = Clothing(id=TEST_CUSTOM_ID) expected_str = ( @@ -26,7 +26,7 @@ def test_clothing_has_expected_default_to_str(): ) assert str(clothing) == expected_str -@pytest.mark.skip +#@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 +37,17 @@ def test_clothing_has_expected_to_str_with_custom_fabric(): # ~~~~~ Decor Tests ~~~~~ -@pytest.mark.skip +#@pytest.mark.skip def test_decor_has_default_uuid_length_id(): decor = Decor() check_for_default_uuid_length_id(decor) -@pytest.mark.skip +#@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 +#@pytest.mark.skip def test_decor_has_expected_default_to_str(): decor = Decor(id=TEST_CUSTOM_ID) expected_str = ( @@ -56,7 +56,7 @@ def test_decor_has_expected_default_to_str(): ) assert str(decor) == expected_str -@pytest.mark.skip +#@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 +67,17 @@ def test_decor_has_expected_to_str_with_custom_size(): # ~~~~~ Electronics Tests ~~~~~ -@pytest.mark.skip +#@pytest.mark.skip def test_electronics_has_default_uuid_length_id(): electronics = Electronics() check_for_default_uuid_length_id(electronics) -@pytest.mark.skip +#@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 +#@pytest.mark.skip def test_electronics_has_expected_default_to_str(): electronics = Electronics(id=TEST_CUSTOM_ID) expected_str = ( @@ -86,7 +86,7 @@ def test_electronics_has_expected_default_to_str(): ) assert str(electronics) == expected_str -@pytest.mark.skip +#@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 +97,7 @@ def test_electronics_has_expected_to_str_with_custom_type(): # ~~~~~ Item Tests ~~~~~ -@pytest.mark.skip +#@pytest.mark.skip def test_items_have_condition_as_float(): items = [ Clothing(condition=3.5), @@ -107,7 +107,7 @@ def test_items_have_condition_as_float(): for item in items: assert item.condition == pytest.approx(3.5) -@pytest.mark.skip +#@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..c405e567d 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -5,7 +5,7 @@ from swap_meet.decor import Decor from swap_meet.electronics import Electronics -@pytest.mark.skip +#@pytest.mark.skip def test_get_items_by_category(): item_a = Clothing() item_b = Electronics() @@ -22,7 +22,7 @@ def test_get_items_by_category(): assert item_a in items assert item_c in items -@pytest.mark.skip +#@pytest.mark.skip def test_get_no_matching_items_by_category(): item_a = Clothing() item_b = Item() @@ -32,13 +32,15 @@ def test_get_no_matching_items_by_category(): ) items = vendor.get_by_category("Electronics") - - raise Exception("Complete this test according to comments below.") + # Assert + assert items == [] + assert len(items) == 0 + #raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* -@pytest.mark.skip +#@pytest.mark.skip def test_best_by_category(): item_a = Clothing(condition=2.0) item_b = Decor(condition=2.0) @@ -54,7 +56,7 @@ def test_best_by_category(): assert best_item.get_category() == "Clothing" assert best_item.condition == pytest.approx(4.0) -@pytest.mark.skip +#@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 +69,7 @@ def test_best_by_category_no_matches_is_none(): assert best_item is None -@pytest.mark.skip +#@pytest.mark.skip def test_best_by_category_with_duplicates(): # Arrange item_a = Clothing(condition=2.0) @@ -84,7 +86,7 @@ def test_best_by_category_with_duplicates(): assert best_item.get_category() == "Clothing" assert best_item.condition == pytest.approx(4.0) -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category(): # Arrange # me @@ -109,8 +111,17 @@ def test_swap_best_by_category(): my_priority="Clothing", their_priority="Decor" ) - - raise Exception("Complete this test according to comments below.") + #Assert + assert result == True + assert item_c in jesse.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_f in tai.inventory + assert item_a in tai.inventory + assert item_b in tai.inventory + assert len(tai.inventory) == 3 + assert len(jesse.inventory) == 3 + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* @@ -119,7 +130,7 @@ def test_swap_best_by_category(): # - 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 -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category_reordered(): # Arrange item_a = Decor(condition=2.0) @@ -131,7 +142,7 @@ def test_swap_best_by_category_reordered(): item_d = Clothing(condition=2.0) item_e = Decor(condition=4.0) - item_f = Clothing(condition=4.0) + item_f = Clothing(condition=3.3) jesse = Vendor( inventory=[item_f, item_e, item_d] ) @@ -142,8 +153,17 @@ def test_swap_best_by_category_reordered(): my_priority="Clothing", their_priority="Decor" ) - - raise Exception("Complete this test according to comments below.") + #Assert + assert result == True + assert item_c in jesse.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_b in tai.inventory + assert item_a in tai.inventory + assert item_f in tai.inventory + assert len(tai.inventory) == 3 + assert len(jesse.inventory) == 3 + #raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* @@ -152,7 +172,7 @@ 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 +#@pytest.mark.skip def test_swap_best_by_category_no_inventory_is_false(): tai = Vendor( inventory=[] @@ -178,7 +198,7 @@ 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 +#@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 +224,7 @@ 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 +#@pytest.mark.skip def test_swap_best_by_category_no_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -227,8 +247,15 @@ def test_swap_best_by_category_no_match_is_false(): my_priority="Clothing", their_priority="Clothing" ) - - raise Exception("Complete this test according to comments below.") + #Assert + assert result == False + assert item_d in jesse.inventory + assert item_f in jesse.inventory + assert item_e in jesse.inventory + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_c in tai.inventory + #raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* @@ -237,7 +264,7 @@ def test_swap_best_by_category_no_match_is_false(): # - That tai and jesse's inventories are the correct length # - That all the correct items are in tai and jesse's inventories -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category_no_other_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -260,8 +287,15 @@ def test_swap_best_by_category_no_other_match_is_false(): my_priority="Electronics", their_priority="Decor" ) - - raise Exception("Complete this test according to comments below.") + #Assert + assert result == False + assert item_a in tai.inventory + assert item_c in tai.inventory + assert item_b in tai.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_f in jesse.inventory + #raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* diff --git a/tests/unit_tests/test_wave_07.py b/tests/unit_tests/test_wave_07.py index 005b82ecc..8e1836886 100644 --- a/tests/unit_tests/test_wave_07.py +++ b/tests/unit_tests/test_wave_07.py @@ -7,7 +7,7 @@ # ~~~~~ display_inventory Tests ~~~~~ -@pytest.mark.skip +#@pytest.mark.skip def test_display_inventory_with_items_no_category(capfd): # Arrange item_a = Clothing(id=123, fabric="Striped") @@ -31,7 +31,7 @@ def test_display_inventory_with_items_no_category(capfd): ) assert captured.out == expected_str -@pytest.mark.skip +#@pytest.mark.skip def test_display_inventory_with_items_and_category(capfd): # Arrange item_a = Decor(id=123, width=2, length=4) @@ -52,7 +52,7 @@ def test_display_inventory_with_items_and_category(capfd): ) assert captured.out == expected_str -@pytest.mark.skip +#@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 +72,7 @@ def test_display_inventory_with_category_and_no_matching_items(capfd): ) assert captured.out == expected_str -@pytest.mark.skip +#@pytest.mark.skip def test_display_inventory_no_items_no_category(capfd): # Arrange vendor = Vendor(inventory=[]) @@ -87,7 +87,7 @@ def test_display_inventory_no_items_no_category(capfd): ) assert captured.out == expected_str -@pytest.mark.skip +#@pytest.mark.skip def test_display_inventory_no_items_with_category(capfd): # Arrange vendor = Vendor(inventory=[]) @@ -104,7 +104,7 @@ def test_display_inventory_no_items_with_category(capfd): # ~~~~~ swap_by_id Tests ~~~~~ -@pytest.mark.skip +#@pytest.mark.skip def test_swap_by_id_success_returns_true(): # Arrange item_a = Decor(id=123) @@ -141,7 +141,7 @@ def test_swap_by_id_success_returns_true(): assert item_e in jesse.inventory assert item_f in jesse.inventory -@pytest.mark.skip +#@pytest.mark.skip def test_swap_by_id_with_caller_empty_inventory_returns_false(): # Arrange tai = Vendor(inventory=[]) @@ -169,7 +169,7 @@ 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 +#@pytest.mark.skip def test_swap_by_id_with_other_empty_inventory_returns_false(): # Arrange item_a = Decor(id=123) @@ -198,7 +198,7 @@ def test_swap_by_id_with_other_empty_inventory_returns_false(): assert len(jesse.inventory) == 0 -@pytest.mark.skip +#@pytest.mark.skip def test_swap_by_id_fails_if_caller_missing_item(): # Arrange item_a = Decor(id=123) @@ -235,7 +235,7 @@ 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 +#@pytest.mark.skip def test_swap_by_id_fails_if_other_missing_item(): # Arrange item_a = Decor(id=123) @@ -274,7 +274,7 @@ def test_swap_by_id_fails_if_other_missing_item(): # ~~~~~ choose_and_swap_items Tests ~~~~~ -@pytest.mark.skip +#@pytest.mark.skip def test_choose_and_swap_items_success(monkeypatch): # Arrange item_a = Decor(id=123) @@ -311,7 +311,7 @@ def test_choose_and_swap_items_success(monkeypatch): assert item_d in jesse.inventory assert item_e in jesse.inventory -@pytest.mark.skip +#@pytest.mark.skip def test_choose_and_swap_items_with_calling_inventory_empty(monkeypatch): # Arrange tai = Vendor(inventory=[]) @@ -339,7 +339,7 @@ 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 +#@pytest.mark.skip def test_choose_and_swap_items_with_other_inventory_empty(monkeypatch): # Arrange item_a = Decor(id=123) @@ -368,7 +368,7 @@ def test_choose_and_swap_items_with_other_inventory_empty(monkeypatch): assert len(jesse.inventory) == 0 -@pytest.mark.skip +#@pytest.mark.skip def test_choose_and_swap_items_with_caller_missing_item(monkeypatch): # Arrange item_a = Decor(id=123) @@ -405,7 +405,7 @@ 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 +#@pytest.mark.skip def test_choose_and_swap_items_with_other_vendor_missing_item(monkeypatch): # Arrange item_a = Decor(id=123) @@ -440,4 +440,43 @@ def test_choose_and_swap_items_with_other_vendor_missing_item(monkeypatch): assert len(jesse.inventory) == 3 assert item_d in jesse.inventory assert item_e in jesse.inventory - assert item_f in jesse.inventory \ No newline at end of file + assert item_f in jesse.inventory + + ########### New Test for code covergae ############################# +#@pytest.mark.skip +def test_choose_and_swap_items_with_other_inventory_category_given(monkeypatch): + # Arrange + item_a = Decor(id=123) + item_b = Electronics(id=456) + item_c = Decor(id=789) + tai = Vendor( + inventory=[item_a, item_b, item_c] + ) + + item_d = Clothing(id=321) + item_e = Decor(id=654) + item_f = Clothing(id=987) + jesse = Vendor( + inventory=[item_d, item_e, item_f] + ) + # Mock user input for picking item ids + input_responses = iter(["654","123"]) + monkeypatch.setattr('builtins.input', lambda msg: next(input_responses)) + + # Act + result = jesse.choose_and_swap_items(other_vendor=tai,category = Decor) + + # Assert + + assert result == True + assert len(tai.inventory) == 3 + assert len(jesse.inventory) == 3 + assert item_a in jesse.inventory + assert item_b in tai.inventory + assert item_c in tai.inventory + assert item_f in jesse.inventory + assert item_d in jesse.inventory + assert item_e in tai.inventory + + +