Ejemplo n.º 1
0
class FoodItemTests(unittest.TestCase):

    def setUp(self):
        self.banana = FoodItem('banana')
        banana_nutrition = {
            'calories' : 110,
            'total_fat': 0,
            'sat_fat': 0,
            'poly_fat': 0,
            'mono_fat': 0,
            'trans_fat': 0,
            'cholesterol': 0,
            'sodium': 0,
            'potassium': 450,
            'total_carbs': 29,
            'dietary_fiber': 3,
            'sugars': 15,
            'protein': 1,
            'vitamin_a': 2,
            'vitamin_c': 20,
            'calcium': 0,
            'iron': 2
        }
        self.banana.set_nutrition(banana_nutrition)

    def test_set_and_get_nutrition_facts(self):
        self.assertEqual(self.banana.get_nutrition('calories'), 110)
Ejemplo n.º 2
0
 def setUp(self):
     self.banana = FoodItem('banana')
     banana_nutrition = {
         'calories' : 110,
         'total_fat': 0,
         'sat_fat': 0,
         'poly_fat': 0,
         'mono_fat': 0,
         'trans_fat': 0,
         'cholesterol': 0,
         'sodium': 0,
         'potassium': 450,
         'total_carbs': 29,
         'dietary_fiber': 3,
         'sugars': 15,
         'protein': 1,
         'vitamin_a': 2,
         'vitamin_c': 20,
         'calcium': 0,
         'iron': 2
     }
     self.banana.set_nutrition(banana_nutrition)
Ejemplo n.º 3
0
def calc_macros():
    food_dao = DAO()
    name = input("Enter name of food: ")
    if name == 'x':
        return None
    food_by_name = food_dao.get_foods_by_name(name)
    if food_by_name is None:
        print("No foods found")
        return None
    else:
        size = input("Enter amount: ")
        if size == 'x':
            return None
        ratio = float(size) / food_by_name.ss()
        print(f"ratio: {ratio}") # testing
        altered_food = FoodItem()
        altered_food.set_info_from_tuple(food_by_name.get_tuple())
        altered_food.proportionalize(ratio)
        return altered_food
Ejemplo n.º 4
0
 def setUp(self):
     self.food_1 = FoodItem('apple', '50', 'g', '100', '20', '1', '2', '3',
                            '10')
     self.food_2 = FoodItem('oats', '40', 'g', '120', '25', '3', '5', '6',
                            '1')
Ejemplo n.º 5
0
class TestFoodItem(unittest.TestCase):
    def setUp(self):
        self.food_1 = FoodItem('apple', '50', 'g', '100', '20', '1', '2', '3',
                               '10')
        self.food_2 = FoodItem('oats', '40', 'g', '120', '25', '3', '5', '6',
                               '1')

    def test_set_info_from_dict(self):
        new_info = {
            'name': 'banana',
            'ss': '30',
            'unit': 'grams',
            'cal': '120',
            'carb': '25',
            'fat': '0',
            'protein': '2',
            'fiber': '5',
            'sugar': '20'
        }
        self.food_1.set_info_from_dict(new_info)
        self.assertEqual('banana', self.food_1.name)
        self.assertEqual('30', self.food_1.ss)
        self.assertEqual('grams', self.food_1.unit)
        self.assertEqual('120', self.food_1.cal)
        self.assertEqual('25', self.food_1.carb)
        self.assertEqual('0', self.food_1.fat)
        self.assertEqual('2', self.food_1.protein)
        self.assertEqual('5', self.food_1.fiber)
        self.assertEqual('20', self.food_1.sugar)

    def test_proportionalize(self):
        self.food_1.proportionalize(100)

        self.assertEqual('apple', self.food_1.name)
        self.assertEqual('100.0', self.food_1.ss)
        self.assertEqual('g', self.food_1.unit)
        self.assertEqual('200.0', self.food_1.cal)
        self.assertEqual('40.0', self.food_1.carb)
        self.assertEqual('2.0', self.food_1.fat)
        self.assertEqual('4.0', self.food_1.protein)
        self.assertEqual('6.0', self.food_1.fiber)
        self.assertEqual('20.0', self.food_1.sugar)

        self.food_2.proportionalize(125)
        self.assertEqual('oats', self.food_2.name)
        self.assertEqual('125.0', self.food_2.ss)
        self.assertEqual('g', self.food_2.unit)
        self.assertEqual('375.0', self.food_2.cal)
        self.assertEqual('78.1', self.food_2.carb)
        self.assertEqual('9.4', self.food_2.fat)
        self.assertEqual('15.6', self.food_2.protein)
        self.assertEqual('18.8', self.food_2.fiber)
        self.assertEqual('3.1', self.food_2.sugar)

    def test_set_info_from_list(self):
        new_info_list_1 = [
            'apple2', '60', 'grams', '110', '25', '2', '3', '4', '15'
        ]
        self.food_1.set_info_from_list(new_info_list_1)

        self.assertEqual('apple2', self.food_1.name)
        self.assertEqual('60', self.food_1.ss)
        self.assertEqual('grams', self.food_1.unit)
        self.assertEqual('110', self.food_1.cal)
        self.assertEqual('25', self.food_1.carb)
        self.assertEqual('2', self.food_1.fat)
        self.assertEqual('3', self.food_1.protein)
        self.assertEqual('4', self.food_1.fiber)
        self.assertEqual('15', self.food_1.sugar)

        new_info_list_2 = [
            'oats2', '100', 'grams', '200', '40', '15', '6', '2', '9'
        ]
        self.food_2.set_info_from_list(new_info_list_2)
        self.assertEqual('oats2', self.food_2.name)
        self.assertEqual('100', self.food_2.ss)
        self.assertEqual('grams', self.food_2.unit)
        self.assertEqual('200', self.food_2.cal)
        self.assertEqual('40', self.food_2.carb)
        self.assertEqual('15', self.food_2.fat)
        self.assertEqual('6', self.food_2.protein)
        self.assertEqual('2', self.food_2.fiber)
        self.assertEqual('9', self.food_2.sugar)
Ejemplo n.º 6
0
def insert_food(food_info):
    food = FoodItem()
    food.set_info_from_list(food_info)
    food_dao.insert_food(food)
Ejemplo n.º 7
0
from fooditem import FoodItem
from dao import DAO
from macros import calc_macros
import text_user_interface as tui
from meal import Meal


tui.run()

food_dao = DAO()

oats = FoodItem('oats', '40', 'g', '150', '25', '4', '4', '4', '2')
banana = FoodItem('banana', '1', 'banana', '75', '12', '0', '1', '1', '8')
#print(oats)
#print(banana)

#breakfast = Meal()
#breakfast.add_ingredient(oats, 100)
#breakfast.add_ingredient(banana, 0.5)
#print(breakfast)
#breakfast.calc_meal_macros()

breakfast = Meal()
breakfast.add_ingredient(oats, 125)
#print(breakfast)
#print(breakfast.get_ingredients())
#oats.proportionalize(125)