diff --git a/README.md b/README.md index e90419fb0..ffcd61d84 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +# Testing git push # Swap Meet ## Skills Assessed diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index b8afdeb1e..a822f97ea 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,2 +1,13 @@ -class Clothing: - pass \ No newline at end of file +from swap_meet.item import Item + +class Clothing(Item): + def __init__(self, id=None, condition=0, fabric="Unknown"): + super().__init__(id, condition) + self.fabric = fabric + + def get_category(self): + return "Clothing" + + def __str__(self): + return f"An object of type Clothing with id {self.id}. 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..daf96dc64 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,2 +1,13 @@ -class Decor: - pass \ No newline at end of file +from swap_meet.item import Item + +class Decor(Item): + def __init__(self, id=None, condition=0, width=0, length=0): + super().__init__(id, condition) + self.width = width + self.length = length + + def get_category(self): + return "Decor" + + def __str__(self): + return f"An object of type Decor with id {self.id}. 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..2bb2dde6a 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,2 +1,12 @@ -class Electronics: - pass +from swap_meet.item import Item + +class Electronics(Item): + def __init__(self, id=None, condition=0, type="Unknown"): + super().__init__(id, condition) + self.type = type + + def get_category(self): + return "Electronics" + + def __str__(self): + return f"An object of type Electronics with id {self.id}. 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..834d91f2d 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,2 +1,27 @@ +import uuid + class Item: - pass \ No newline at end of file + def __init__(self, id=None, condition=0): + if id is None: + id = uuid.uuid4().int + self.id = id + self.condition = condition + + def get_category(self): + return "Item" + + def __str__(self): + return f"An object of type Item with id {self.id}." + + def condition_description(self): + condition_dict = { + 0: "Trash", + 1: "Yikes", + 2: "Meh", + 3: "Okay", + 4: "Pretty good", + 5: "Brilliant, incredible, amazing, show stopping, spectacular, never the same, totally unique, completely not ever been done before" + } + + if self.condition in condition_dict: + return condition_dict[self.condition] \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 87302c056..60f150837 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,2 +1,71 @@ class Vendor: - pass \ No newline at end of file + def __init__(self, inventory = None): + if inventory is None: + inventory = [] + self.inventory = inventory + + def add(self, item): + self.inventory.append(item) + return item + + def remove(self, item): + if item in self.inventory: + self.inventory.remove(item) + return item + + return False + + def get_by_id(self, item_id): + 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 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 + + 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 + + def get_by_category(self, category): + category_items = [] + + for item in self.inventory: + if item.get_category() == category: + category_items.append(item) + + return category_items + + def get_best_by_category(self, category): + best_item = None + condition = 0 + + for item in self.inventory: + if item.get_category() == category and item.condition > condition: + condition = item.condition + best_item = item + return best_item + + def swap_best_by_category(self, other_vendor, my_priority, their_priority): + my_best_item = self.get_best_by_category(their_priority) + their_best_item = other_vendor.get_best_by_category(my_priority) + + if my_best_item and their_best_item: + self.swap_items(other_vendor, my_best_item, their_best_item) + return True + return False + \ 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 58478ccf9..25a3a94ba 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_is_false(): item = "item to remove" vendor = Vendor( @@ -49,7 +49,8 @@ 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 ********** # ********************************************************************* diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index c85da6797..993fa2196 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() @@ -131,7 +131,11 @@ 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.") + assert len(fatimah.inventory) == 3 + assert len(jolie.inventory) == 0 + assert not result + + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index ad51bf42d..05023c74b 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() @@ -31,14 +31,16 @@ def test_get_no_matching_items_by_category(): inventory=[item_a, item_b, item_c] ) - items = vendor.get_by_category("Electronics") + items = vendor.get_by_category("Electronics") - raise Exception("Complete this test according to comments below.") + assert len(items) == 0 + assert items == [] + # 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,13 +86,13 @@ 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 item_a = Decor(condition=2.0) item_b = Electronics(condition=4.0) - item_c = Decor(condition=4.0) + item_c = Decor(condition=4.0) tai = Vendor( inventory=[item_a, item_b, item_c] ) @@ -98,7 +100,7 @@ def test_swap_best_by_category(): # them item_d = Clothing(condition=2.0) item_e = Decor(condition=4.0) - item_f = Clothing(condition=4.0) + item_f = Clothing(condition=4.0) jesse = Vendor( inventory=[item_d, item_e, item_f] ) @@ -110,7 +112,17 @@ def test_swap_best_by_category(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") + assert 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_f in tai.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_c in jesse.inventory + + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* @@ -119,7 +131,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) @@ -143,7 +155,20 @@ def test_swap_best_by_category_reordered(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") + # Assert + assert result + assert len(tai.inventory) == 3 + assert len(jesse.inventory) == 3 + assert item_c not in tai.inventory + assert item_f not in jesse.inventory + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_f in tai.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_c in jesse.inventory + + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* @@ -152,7 +177,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 +203,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 +229,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) @@ -228,7 +253,17 @@ def test_swap_best_by_category_no_match_is_false(): their_priority="Clothing" ) - raise Exception("Complete this test according to comments below.") + 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 + + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* @@ -237,7 +272,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) @@ -261,7 +296,17 @@ def test_swap_best_by_category_no_other_match_is_false(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") + 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 + + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # *********************************************************************