Use Units#Of in tests
This commit is contained in:
parent
7d2f47b1a2
commit
52ed02b34c
@ -83,7 +83,3 @@ func (db *DB) DeleteIngredient(i Ingredient) {
|
||||
panic(fmt.Errorf("tried to delete ingredient with ID (%d) but it doesn't exist", i.ID))
|
||||
}
|
||||
}
|
||||
|
||||
// func (i Ingredient) AddTo(r *Recipe) {
|
||||
|
||||
// }
|
||||
|
@ -43,7 +43,6 @@ type Recipe struct {
|
||||
func (db *DB) SaveRecipe(r *Recipe) {
|
||||
if r.ID == RecipeID(0) {
|
||||
// Do create
|
||||
|
||||
// Create the computed food
|
||||
computed_food := Food{Name: r.Name}
|
||||
db.SaveFood(&computed_food)
|
||||
@ -82,6 +81,9 @@ func (db *DB) SaveRecipe(r *Recipe) {
|
||||
}
|
||||
for i := range r.Ingredients {
|
||||
r.Ingredients[i].InRecipeID = r.ID
|
||||
if r.Ingredients[i].ListOrder == 0 {
|
||||
r.Ingredients[i].ListOrder = int64(i)
|
||||
}
|
||||
db.SaveIngredient(&r.Ingredients[i])
|
||||
}
|
||||
// Update the computed food
|
||||
|
@ -52,8 +52,8 @@ func TestRecipeComputeFood(t *testing.T) {
|
||||
f2 := Food{0, "", 16.5, 15.5, 14.5, 13.5, 12.5, 11.5, 10.5, 9.5, 8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 0, 0}
|
||||
|
||||
recipe := Recipe{Ingredients: []Ingredient{
|
||||
{Quantity: 1, Food: f1},
|
||||
{Quantity: 1, Food: f2},
|
||||
COUNT.Of(f1, 1),
|
||||
COUNT.Of(f2, 1),
|
||||
}}
|
||||
computed_food := recipe.ComputeFood()
|
||||
assert.Equal(computed_food.Cals, float32(17.5))
|
||||
@ -74,8 +74,8 @@ func TestRecipeComputeFood(t *testing.T) {
|
||||
assert.Equal(computed_food.Price, float32(17.5))
|
||||
|
||||
recipe2 := Recipe{Ingredients: []Ingredient{
|
||||
{Quantity: 1.5, Food: f1},
|
||||
{Quantity: 0.5, Food: f2},
|
||||
COUNT.Of(f1, 1.5),
|
||||
COUNT.Of(f2, 0.5),
|
||||
}}
|
||||
computed_food2 := recipe2.ComputeFood()
|
||||
assert.Equal(computed_food2.Cals, float32(9.75))
|
||||
@ -109,9 +109,9 @@ func TestRecipeSaveComputedFood(t *testing.T) {
|
||||
require.Equal(parm.Name, "parmigiano")
|
||||
|
||||
recipe := Recipe{Name: "pasta w/ sauce", Ingredients: []Ingredient{
|
||||
{Quantity: 2, FoodID: pasta.ID, Food: pasta, ListOrder: 0},
|
||||
{Quantity: 2.5, FoodID: tomatoes.ID, Food: tomatoes, ListOrder: 1},
|
||||
{Quantity: 0.5, FoodID: parm.ID, Food: parm, ListOrder: 2},
|
||||
COUNT.Of(pasta, 2),
|
||||
COUNT.Of(tomatoes, 2.5),
|
||||
COUNT.Of(tomatoes, 0.5),
|
||||
}}
|
||||
db.SaveRecipe(&recipe)
|
||||
computed_food := get_food(db, recipe.ComputedFoodID)
|
||||
|
Loading…
x
Reference in New Issue
Block a user