Exemplo n.º 1
0
def test_generate_mealplan_not_possible(db):
    clear_tables(db)
    common_ingredients = [
        {
            "name": "carrots",
            "units": "g",
            "amount": 20
        },
        {
            "name": "apples",
            "units": "lb",
            "amount": 0.2
        },
        {
            "name": "spaghetti",
            "units": "lb",
            "amount": 1
        },
    ]
    for i, recipe in enumerate([(5.00, 500), (8.00, 750), (3.39, 300),
                                (13.32, 1000)]):
        create_recipe(
            db,
            f"recipe_{i}",
            ingredients=common_ingredients,
            price=recipe[0],
            calories=recipe[1],
        )

    days = 10
    budget = 15 * days
    cals = 2000 * days
    with pytest.raises(ValueError):
        meals = find_meals(db, budget, cals)
Exemplo n.º 2
0
def test_gen_mealplan_over_max(db):
    clear_tables(db)
    max_ingredients = {"carrots": Q_(10, "g")}

    create_recipe(
        db,
        "A",
        [
            {
                "name": "carrots",
                "units": "g",
                "amount": 100
            },
            {
                "name": "apples",
                "units": "bushels",
                "amount": 0.1
            },
        ],
        3.00,
        500,
    )
    create_recipe(db, "B", [{
        "name": "apples",
        "units": "bushels",
        "amount": 0.2
    }], 5.00, 1)

    days = 5
    budget = 10 * days
    cals = 1000 * days
    with pytest.raises(RuntimeError):
        find_meals(db, budget, cals, max_ingredients=max_ingredients)
Exemplo n.º 3
0
def client(db):
    app.config["DATABASE_URL"] = TEST_DATABASE
    app.config["TESTING"] = True

    try:
        sql.create_tables(db)
    except Exception:
        pass

    sql.clear_tables(db)
    with app.test_client() as client:
        yield client
Exemplo n.º 4
0
def test_generate_mealplan_no_constraints(db):
    clear_tables(db)
    common_ingredients = [
        {
            "name": "carrots",
            "units": "g",
            "amount": 20
        },
        {
            "name": "apples",
            "units": "lb",
            "amount": 0.2
        },
        {
            "name": "spaghetti",
            "units": "lb",
            "amount": 1
        },
    ]
    for i, recipe in enumerate([
        (5.00, 900),
        (4.50, 850),
        (9.00, 1300),
        (2.12, 350),
        (0.59, 200),
        (11.29, 1500),
        (7.07, 1000),
        (9.29, 1100),
    ]):
        create_recipe(
            db,
            f"recipe_{i}",
            ingredients=common_ingredients,
            price=recipe[0],
            calories=recipe[1],
        )

    days = 10
    budget = 15 * days
    cals = 2000 * days
    meals = find_meals(db, budget, cals)
    check_plan(db, meals, budget, cals)
Exemplo n.º 5
0
def test_gen_mealplan_minmax_same_item(db):
    clear_tables(db)
    min_ingredients = {"carrots": Q_(20, "g")}
    max_ingredients = {"carrots": Q_(50, "g")}

    create_recipe(
        db,
        "A",
        [
            {
                "name": "carrots",
                "units": "g",
                "amount": 10
            },
            {
                "name": "apples",
                "units": "bushels",
                "amount": 0.1
            },
        ],
        3.00,
        500,
    )
    create_recipe(db, "B", [{
        "name": "apples",
        "units": "bushels",
        "amount": 0.2
    }], 5.00, 1000)
    create_recipe(db, "C", [{
        "name": "cucumbers",
        "units": "lb",
        "amount": 0.5
    }])

    days = 5
    budget = 10 * days
    cals = 1000 * days
    meals = find_meals(db, budget, cals, min_ingredients, max_ingredients)
    check_plan(db, meals, budget, cals, min_ingredients, max_ingredients)
Exemplo n.º 6
0
def test_gen_mealplan_cant_reach_min(db):
    clear_tables(db)
    min_ingredients = {"carrots": Q_(200, "g")}

    create_recipe(
        db,
        "A",
        [
            {
                "name": "carrots",
                "units": "g",
                "amount": 1
            },
            {
                "name": "apples",
                "units": "bushels",
                "amount": 0.1
            },
        ],
        3.00,
        500,
    )
    create_recipe(db, "B", [{
        "name": "apples",
        "units": "bushels",
        "amount": 0.2
    }], 5.00, 1000)
    create_recipe(db, "C", [{
        "name": "cucumbers",
        "units": "lb",
        "amount": 0.5
    }])

    days = 5
    budget = 10 * days
    cals = 1000 * days
    with pytest.raises(RuntimeError):
        find_meals(db, budget, cals, min_ingredients)