Exemplo n.º 1
0
def test_add_subtract_2():
    ## add then subtract one food, then add and subtract another food
    type_list = ['elements', 'vitamins', 'energy', 'sugars', 'amino_acids',
                     'other', 'composition']
    food_one = pm.get_food("Kale, scotch, raw")
    food_two = pm.get_food("Kale, raw")
    meal_one = pm.Meal(type_list)
    meal_one.add(food_one)
    meal_one.subtract(food_one)
    meal_one.add(food_two)
    meal_one.subtract(food_two)
    
    errors = {}
    for _type in type_list:
        for subtype in food_one.__dict__[_type]:
            print 'type, subtype:', _type, subtype
            if meal_one.__dict__[_type][subtype] != 0:
                errors[_type+'__'+subtype] = meal_one.__dict__[_type][subtype]
    return errors
Exemplo n.º 2
0
def test_add_subtract_3():
    ## add two foods, then subtract both (recreates a known problem showing up in
    ## the GUI layer) **** Problem found, rounding error, now any number close
    ## enough to zero afrer subtraction is rounded to zero
    type_list = ['elements', 'vitamins', 'energy', 'sugars', 'amino_acids',
                     'other', 'composition']
    food_one = pm.get_food("Kale, scotch, raw")
    food_two = pm.get_food("Kale, raw")
    meal_one = pm.Meal(type_list)
    meal_one.add(food_one)
    meal_one.add(food_two)
    meal_one.subtract(food_one)
    meal_one.subtract(food_two)
    
    errors = {}
    for _type in type_list:
        for subtype in food_one.__dict__[_type]:
            if meal_one.__dict__[_type][subtype] != 0 and\
               meal_one.__dict__[_type][subtype] != None:
                errors[_type+'__'+subtype] = meal_one.__dict__[_type][subtype]
    return errors
Exemplo n.º 3
0
    def OnAddToMeal(self, event):
        """ Adds foods from the search results box to the current meal listbox
            and current meal object
            """
        to_add_indexes = self.search_listbox.GetSelections()
        to_add_strings = self.search_listbox.GetStrings()
        names = [to_add_strings[i] for i in to_add_indexes]
        for food_name in names:
            new_food = perfmeal.get_food(food_name)
            self.current_meal.add(new_food)
        self.current_meal_listbox.Set(self.current_meal.get_servings_and_foods())

        self.reset_nutr_grid()
Exemplo n.º 4
0
    def OnAddToMeal(self, event):
        """ Adds foods from the search results box to the current meal listbox
            and current meal object
            """
        to_add_indexes = self.search_listbox.GetSelections()
        to_add_strings = self.search_listbox.GetStrings()
        names = [to_add_strings[i] for i in to_add_indexes]
        for food_name in names:
            new_food = perfmeal.get_food(food_name)
            self.current_meal.add(new_food)
        self.current_meal_listbox.Set(
            self.current_meal.get_servings_and_foods())

        self.reset_nutr_grid()