Ejemplo n.º 1
0
def test_serv():
    assert Ingredient("a",
                      _serv=None,
                      _cpfc=Cpfc(100, Pfc(0, 0, 0, is_perc=False)),
                      _price=100).serv() == 100
    assert Ingredient("a",
                      _serv=100,
                      _cpfc=Cpfc(100, Pfc(0, 0, 0, is_perc=False)),
                      _price=100).serv() == 100
    assert Ingredient("a",
                      _serv=50,
                      _cpfc=Cpfc(100, Pfc(0, 0, 0, is_perc=False)),
                      _price=100).serv() == 50
Ejemplo n.º 2
0
def test_unperc():
    p, f, c = 3, 4, 5
    cals = 4.1 * p + 9.29 * f + 4.1 * c
    pfc_perc = Cpfc(cals, Pfc(p, f, c)).pfc.perc()
    assert Cpfc(cals, pfc_perc).unperc() == Cpfc(cals, Pfc(p, f, c))
Ejemplo n.º 3
0
def test_scale():
    assert Pfc(1, 1, 1) * 2 == Pfc(2, 2, 2)
Ejemplo n.º 4
0
def test_perc():
    assert Pfc(100, 200, 300, is_perc=False).perc() == Pfc(1 / 6,
                                                           2 / 6,
                                                           3 / 6,
                                                           is_perc=True)
Ejemplo n.º 5
0
def test___mul__():
    assert Pfc(1, 2, 3) * 2 == Pfc(2, 4, 6)
Ejemplo n.º 6
0
def test_sum():
    assert Pfc(0.93, 0.24, 9.58).sum() == 10.75
Ejemplo n.º 7
0
def test___abs__():
    assert abs(Pfc(-1, -2, -3)) == Pfc(1, 2, 3)
    assert abs(Pfc(-1, 0, 1)) == Pfc(1, 0, 1)
Ejemplo n.º 8
0
def test_cpfc_zero():
    dish = Dish(ingredients=[])
    assert dish.cpfc() == Cpfc(cals=0, pfc=Pfc(prot=0, fats=0, carb=0))
Ejemplo n.º 9
0
def test___neg__():
    assert -Pfc(1, 2, 3) == Pfc(-1, -2, -3)
    assert -Pfc(-1, -2, -3) == Pfc(1, 2, 3)
    assert Pfc(0, 0, 0) == -Pfc(0, 0, 0)
Ejemplo n.º 10
0
 def cpfc(self) -> Cpfc:
     if len(self.ingredients) == 0:
         return Cpfc(0, Pfc(0, 0, 0))
     else:
         return sum((_.cpfc() for _ in self.ingredients),
                    start=Cpfc(0, Pfc(0, 0, 0)))
Ejemplo n.º 11
0
def test__score_kpfc_non_perc():
    assert Matcher(ingredients, Cpfc(10, Pfc(20, 30,
                                             50)))._score_kpfc(_dish) == 0
Ejemplo n.º 12
0
from Dish import Dish
from data.Cpfc import Cpfc, Pfc
from data.Matcher import Matcher
from data.ingredients import ingredients, _

_target = Cpfc(10, Pfc(0.2, 0.3, 0.5, is_perc=True))
_dish = Dish(
    [_(title="apple", serv=50, cals=10, prot=2, fats=3, carb=5, price=0)] * 2)
_matcher = Matcher(ingredients, _target)


def test__score_kpfc():
    assert _matcher._score_kpfc(_dish) == 0


def test__score_kpfc_non_perc():
    assert Matcher(ingredients, Cpfc(10, Pfc(20, 30,
                                             50)))._score_kpfc(_dish) == 0


def test__random_dish():
    from random import seed
    seed(1)
    _matcher._random_dish()


def test_find():
    _matcher.find()


def test__score_ingredients():
Ejemplo n.º 13
0
def test_report():
    _target = Cpfc(1800, Pfc(0.35, 0.16, 0.49, is_perc=True))
    from data.ingredients import _
    _meal = Dish(
        [_("carrot", serv=50, cals=2, prot=4, fats=8, carb=16, price=0)])
    report_meal(_meal)
Ejemplo n.º 14
0
from Dish import Dish
from Reporter import report_cpfc, report_meal
from data.Cpfc import Cpfc, Pfc

_expected = Cpfc(1000, Pfc(200, 300, 500))
_actual = Cpfc(100, Pfc(20, 30, 50))


def test_report_cpfc():
    # @formatter:off
    assert report_cpfc(_expected, _actual) == [
        ["", "Aim", "Real", "% Aim", "% Real"],
        ["Calories", "1000", "100", "", ""],
        ["Protein", "200", "20", "20%", "20%"],
        ["Fats", "300", "30", "30%", "30%"],
        ["Carb", "500", "50", "50%", "50%"],
    ]
    # @formatter:on


def test_report():
    _target = Cpfc(1800, Pfc(0.35, 0.16, 0.49, is_perc=True))
    from data.ingredients import _
    _meal = Dish(
        [_("carrot", serv=50, cals=2, prot=4, fats=8, carb=16, price=0)])
    report_meal(_meal)
Ejemplo n.º 15
0
def test___add__():
    assert Pfc(1, 2, 3) + Pfc(2, 3, 4) == Pfc(3, 5, 7)
Ejemplo n.º 16
0
def test___sub__():
    assert Pfc(1, 2, 3) - Pfc(2, 3, 4) == Pfc(-1, -1, -1)
Ejemplo n.º 17
0
def _(title: str, serv: Optional[float], cals: float, prot: float, fats: float,
      carb: float, price: float):
    return Ingredient(title, serv, Cpfc(cals, Pfc(prot, fats, carb)), price)
Ejemplo n.º 18
0
def test_cpfc_one():
    dish = Dish(
        [_("carrot", serv=50, cals=2, prot=4, fats=8, carb=16, price=1)])
    expected = Cpfc(cals=1, pfc=Pfc(prot=2, fats=4, carb=8))
    assert dish.cpfc() == expected