Example #1
0
 def test(self):
     product = Product("coffee", 2.5)
     self.assertEqual(product.__class__.__name__, "Product")
     self.assertEqual(product.name, "coffee")
     self.assertEqual(product.price, 2.5)
     beverage = Beverage("coffee", 2.5, 50)
     self.assertEqual(beverage.__class__.__name__, "Beverage")
     self.assertEqual(beverage.__class__.__bases__[0].__name__, "Product")
     self.assertEqual(beverage.name, "coffee")
     self.assertEqual(beverage.price, 2.5)
     self.assertEqual(beverage.milliliters, 50)
     soup = Soup("fish soup", 9.90, 230)
     self.assertEqual(soup.__class__.__name__, "Soup")
     self.assertEqual(soup.__class__.__bases__[0].__name__, "Starter")
     self.assertEqual(soup.name, "fish soup")
     self.assertEqual(soup.price, 9.90)
     self.assertEqual(soup.grams, 230)
Example #2
0
from project.beverage.beverage import Beverage
from project.beverage.tea import Tea
from project.food.soup import Soup
from project.product import Product

product = Product("coffee", 2.5)
print(product.__class__.__name__)
print(product.name)
print(product.price)
beverage = Beverage("coffee", 2.5, 50)
print(beverage.__class__.__name__)
print(beverage.__class__.__bases__[0].__name__)
print(beverage.name)
print(beverage.price)
print(beverage.milliliters)
soup = Soup("fish soup", 9.90, 230)
print(soup.__class__.__name__)
print(soup.__class__.__bases__[0].__name__)
print(soup.name)
print(soup.price)
print(soup.grams)

Example #3
0
 def __init__(self, name, price, mililiters):
     Product.__init__(self, name, price)
     self._mililiters = mililiters
Example #4
0
 def setUp(self):
     self.product = Product('product', 150)
     self.drink = Drink('drink')
     self.food = Food('food')
     self.repo = ProductRepository()
Example #5
0
 def __init__(self, name, price, grams):
     Product.__init__(self, name, price)
     self._grams = grams
Example #6
0
class Tests(unittest.TestCase):
    def setUp(self):
        self.product = Product('product', 150)
        self.drink = Drink('drink')
        self.food = Food('food')
        self.repo = ProductRepository()

    def test_init_of_product(self):
        self.assertEqual(self.product.name, 'product')
        self.assertEqual(self.product.quantity, 150)

    def test_decrease_product(self):
        self.product.decrease(10)
        self.assertEqual(self.product.quantity, 140)

    def test_increase_product(self):
        self.product.increase(10)
        self.assertEqual(self.product.quantity, 160)

    def test_drink_init(self):
        self.assertEqual(self.drink.name, 'drink')
        self.assertEqual(self.drink.quantity, 10)
        self.assertEqual(self.drink.__class__.__base__.__name__, 'Product')

    def test_decrease_drink(self):
        self.drink.decrease(10)
        self.assertEqual(self.drink.quantity, 0)

    def test_increase_drink(self):
        self.drink.increase(10)
        self.assertEqual(self.drink.quantity, 20)

    def test_food_init(self):
        self.assertEqual(self.food.name, 'food')
        self.assertEqual(self.food.quantity, 15)
        self.assertEqual(self.food.__class__.__base__.__name__, 'Product')

    def test_decrease_food(self):
        self.food.decrease(10)
        self.assertEqual(self.food.quantity, 5)

    def test_increase_food(self):
        self.food.increase(10)
        self.assertEqual(self.food.quantity, 25)

    def test_init_repo(self):
        self.assertEqual(self.repo.products, [])

    def test_repo_add(self):
        self.repo.add(self.food)
        self.repo.add(self.drink)
        self.assertEqual(len(self.repo.products), 2)
        self.assertEqual(self.repo.products[0], self.food)
        self.assertEqual(self.repo.products[1], self.drink)

    def test_repo_remove(self):
        self.repo.products = [self.drink, self.food]
        self.repo.remove('drink')
        self.assertEqual(self.repo.products[0], self.food)
        self.repo.remove('drink')
        self.assertEqual(self.repo.products[0], self.food)

    def test_repo_repr(self):
        self.repo.add(self.food)
        self.repo.add(self.drink)
        actual = str(self.repo)
        expected = 'food: 15\ndrink: 10'
        self.assertEqual(expected, actual)
Example #7
0
 def __init__(self, name, quantity=15):
     Product.__init__(self, name, quantity)
Example #8
0
from project.product import Product
from project.beverage.beverage import Beverage
from project.food.food import Food
from project.food.starter import Starter
from project.food.soup import Soup

product = Product("coffee")
print(product.__class__.__name__)
print(product.name)
print(product.price)
beverage = Beverage("coffee", 2.5, 50)
print(beverage.__class__.__name__)
print(beverage.__class__.__bases__[0].__name__)
print(beverage.name)
print(beverage.price)
print(beverage.milliliters)
soup = Soup("fish soup", 9.90, 230)
print(soup.__class__.__name__)
print(soup.__class__.__bases__[0].__name__)
print(soup.name)
print(soup.price)
print(soup.grams)
Example #9
0
 def __init__(self, name: str, price: float, grams: float):
     Product.__init__(self, name, price)
     self._grams = grams
 def __init__(self, name: str, price: float, milliliters: float):
     Product.__init__(self, name, price)
     self._milliliters = milliliters