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

Ruby - Ruth M #75

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e928afd
added init, add fucntion and remove function to vendor.py
rmora101 Apr 5, 2023
a21542d
unskipped tests and completed the last test
rmora101 Apr 5, 2023
2b018b5
created __init__ and a fucntion to return the string name of class
rmora101 Apr 6, 2023
0e40064
added the get_by_id to return item or none
rmora101 Apr 6, 2023
77be6b2
unskipped the tests
rmora101 Apr 6, 2023
3591554
added the stringify instance to item.py
rmora101 Apr 6, 2023
d751131
finiished stringify function
rmora101 Apr 6, 2023
ed08d07
added the swap meet instance
rmora101 Apr 6, 2023
cf76b80
unskipped tests and completed my last test
rmora101 Apr 6, 2023
1e0ac1c
started the fourth wave
rmora101 Apr 6, 2023
037ff4a
added the condition to return false if list is empty. working on the …
rmora101 Apr 6, 2023
cd6b572
all functions seem to pass tests but theres an error with return true
rmora101 Apr 6, 2023
2575d50
unskipped tests
rmora101 Apr 6, 2023
0085387
finished the swap first function. all tests pass
rmora101 Apr 6, 2023
9115242
started clothing.py
rmora101 Apr 6, 2023
15a8787
clothing function working
rmora101 Apr 6, 2023
d9588a8
passed first 4 tests of clothing
rmora101 Apr 6, 2023
3e6ce22
completed decor.py
rmora101 Apr 6, 2023
d4f789d
cleared the tests for decor
rmora101 Apr 6, 2023
30ee078
electronics class done
rmora101 Apr 6, 2023
18ec9ac
added condition description to item.py. imported item class to clothi…
rmora101 Apr 6, 2023
55fcfc0
Added the condidtion attributes
rmora101 Apr 6, 2023
5c01ca8
fized the condition description fucntion
rmora101 Apr 6, 2023
73d72d7
all tests cleared
rmora101 Apr 6, 2023
27669f9
unskipped integration tests
rmora101 Apr 6, 2023
a51ac3a
trying to get the get category to work
rmora101 Apr 6, 2023
52aac73
unskipped the tests
rmora101 Apr 6, 2023
c817e67
finished some tests
rmora101 Apr 6, 2023
9e1900a
started the get best category
rmora101 Apr 6, 2023
9c4d94e
unskipped some tests
rmora101 Apr 6, 2023
62a1cd2
updating project to turn in whatver i have so far
rmora101 Apr 7, 2023
b1608b4
updating to turn in what i have so far
rmora101 Apr 7, 2023
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
17 changes: 15 additions & 2 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
class Clothing:
pass

from swap_meet.item import Item

class Clothing(Item):
def __init__(self,id = None, fabric = "Unknown", condition = 0):
super().__init__(id, condition)
self.fabric = fabric



def get_category(self):
return (self.__class__.__name__)

def __str__(self):
return( f'An object of type {self.get_category()} with id {self.id}. It is made from {self.fabric} fabric.')
15 changes: 13 additions & 2 deletions swap_meet/decor.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
class Decor:
pass

from swap_meet.item import Item

class Decor(Item):

def __init__(self, id = None, width = 0, length = 0, condition = 0):
super().__init__(id, condition)
self.width = width
self.length = length

def __str__(self):
return f'An object of type {self.get_category()} with id {self.id}. It takes up a {self.width} by {self.length} sized space.'

13 changes: 11 additions & 2 deletions swap_meet/electronics.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
class Electronics:
pass
from swap_meet.item import Item

class Electronics(Item):
def __init__(self, id = None, type = "Unknown", condition = 0):
super().__init__(id,condition)
self.type = type


def __str__(self):
return f'{super().__str__()} This is a {self.type} device.'

32 changes: 31 additions & 1 deletion swap_meet/item.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
import uuid


class Item:
pass

def __init__(self, id = None, condition = 0):
if not id:
id = int(uuid.uuid4())
self.id = id
Comment on lines +7 to +9

Choose a reason for hiding this comment

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

A ternary is also fine here:

        self.id = id if id else uuid.uuid4().int

self.condition = condition

def condition_description(self):
if self.condition == 0:
return 'this is Garbage!'
elif 1 <= self.condition < 2:

Choose a reason for hiding this comment

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

Careful about statements like this. They sometimes have unexpected behavior. Prefer writing out the logical expression:

elif 1 <= self.condition and self.condition < 2:

Also, worth noting: what happens if self.condition is between 0 and 1?

return 'ITS A SCAM'
elif 2 <= self.condition < 3:
return "not bad! It's your money though"
elif 3 <= self.condition <= 5:
return "OMG GET IT!"



def get_category(self):
return (self.__class__.__name__)


def __str__(self):
return f'An object of type {self.get_category()} with id {self.id}.'



83 changes: 82 additions & 1 deletion swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,83 @@

class Vendor:
pass

def __init__(self, inventory=None):
if not inventory:
inventory = []
self.inventory = inventory

def add(self,item):
self.inventory.append(item)
return item

def remove(self,item):
if item in self.inventory:
self.inventory.remove(item)
return item
return False


def get_by_id(self,id):
for item in self.inventory:
if item.id == 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)

#if vendor inventory doesnt contain my item return false
# if vendor doesnt contain their_item return false
return True

def swap_first_item(self,other_vendor):

if not self.inventory or not other_vendor.inventory:
return False

other_vendor.add(self.inventory[0])

self.add(other_vendor.inventory[0])

self.remove(self.inventory[0])

other_vendor.remove(other_vendor.inventory[0])
Comment on lines +46 to +52

Choose a reason for hiding this comment

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

[nit] No need to space between each function call


return True

def get_by_category(self,category):

self.category = category

Choose a reason for hiding this comment

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

Careful here! It's probably unexpected if calling a get function modifies the instance object. Nothing is wrong with the class as-is because you don't use self.category in any other method. If you did use it elsewhere, this could have unintended side effects.


objects = []

for stuff in self.inventory:
if stuff.get_category() == category:
objects.append(stuff)

return objects
Comment on lines +60 to +66

Choose a reason for hiding this comment

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

Notice this pattern of:

result_list = []
for element in source_list:
    if some_condition(element):
        result_list.append(element)

can be rewritten using a list comprehension as:

result_list = [element for element in source_list if some_condition(element)]

Which here would look like:

objects = [stuff for stuff in self.inventory if stuff.get_category() == category]
return objects

At first, this may seem more difficult to read, but comprehensions are a very common python style, so I encourage y’all to try working with them!


# def get_best_by_category(self, category_condition):

self.category_condition = category_condition

best_condition = 0

for stuff in self.inventory(category_condition):
if stuff.condition_description() < best_condition:
best_condition = category_condition
Comment on lines +74 to +76

Choose a reason for hiding this comment

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

You're on the right track! Some things to think about...

  1. You want to get the things from the self.inventory that have a specific category_condition. You wrote a method above this that can do that!
  2. Your "best" condition is the highest one, not the lowest
  3. You want to keep track of the best condition and the best stuff you've seen, too.

With those things in mind, see if you can come up with how to modify this code. If you still get stuck, here's a snippet that I think might help get you there: https://gist.github.com/mmcknett-ada/26444ed29c91927c05dc7d577d5bd67e

return

return




2 changes: 1 addition & 1 deletion tests/integration_tests/test_wave_01_02_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

@pytest.mark.skip
# @pytest.mark.skip

Choose a reason for hiding this comment

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

[nit] you can remove these

@pytest.mark.integration_test
def test_integration_wave_01_02_03():
# make a vendor
Expand Down
17 changes: 8 additions & 9 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,6 @@ def test_removing_not_found_is_false():

result = vendor.remove(item)

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


12 changes: 6 additions & 6 deletions tests/unit_tests/test_wave_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
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)
Expand All @@ -36,7 +36,7 @@ def test_get_item_by_id():
result_item = vendor.get_by_id(test_id)
assert result_item is item_custom_id

@pytest.mark.skip
# @pytest.mark.skip
def test_get_item_by_id_no_matching():
test_id = 12345
item_a = Item()
Expand Down
18 changes: 8 additions & 10 deletions tests/unit_tests/test_wave_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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=[]
Expand All @@ -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()
Expand All @@ -131,7 +131,5 @@ 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 not result

6 changes: 3 additions & 3 deletions tests/unit_tests/test_wave_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,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()
Expand Down Expand Up @@ -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=[]
Expand All @@ -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()
Expand Down
Loading