ConvertToBaseUnit test + code fix
This commit is contained in:
parent
87f8a883d5
commit
4a902ead20
2 changed files with 11 additions and 3 deletions
|
|
@ -69,7 +69,7 @@ public class RecipeIngredient {
|
||||||
|
|
||||||
public double amountInBaseUnit() {
|
public double amountInBaseUnit() {
|
||||||
Unit unit = getUnit();
|
Unit unit = getUnit();
|
||||||
if (unit == null || unit.isFormal() || unit.conversionFactor <= 0) {
|
if (unit == null || !unit.isFormal() || unit.conversionFactor <= 0) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
return amount * unit.conversionFactor;
|
return amount * unit.conversionFactor;
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,11 @@ public class RecipeIngredientTest {
|
||||||
private Recipe recipe;
|
private Recipe recipe;
|
||||||
private Ingredient ingredient;
|
private Ingredient ingredient;
|
||||||
private RecipeIngredient recipeIngredient;
|
private RecipeIngredient recipeIngredient;
|
||||||
private RecipeIngredient testIngredient;
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup(){
|
void setup(){
|
||||||
recipe = new Recipe();
|
recipe = new Recipe();
|
||||||
ingredient = new Ingredient();
|
ingredient = new Ingredient();
|
||||||
testIngredient = new RecipeIngredient(recipe,ingredient,1,"KILOGRAM");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -59,6 +57,16 @@ public class RecipeIngredientTest {
|
||||||
assertNull(recipeIngredient.getUnit());
|
assertNull(recipeIngredient.getUnit());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void convertToBaseUnit(){
|
||||||
|
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"KILOGRAM");
|
||||||
|
assertEquals(1000, recipeIngredient.amountInBaseUnit());
|
||||||
|
|
||||||
|
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"PINCH");
|
||||||
|
assertEquals(0,recipeIngredient.amountInBaseUnit());
|
||||||
|
|
||||||
|
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"RANDOM");
|
||||||
|
assertEquals(0,recipeIngredient.amountInBaseUnit());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue