ConvertToBaseUnit test + code fix

This commit is contained in:
Mei Chang van der Werff 2025-12-18 00:54:44 +01:00
commit 4a902ead20
2 changed files with 11 additions and 3 deletions

View file

@ -69,7 +69,7 @@ public class RecipeIngredient {
public double amountInBaseUnit() {
Unit unit = getUnit();
if (unit == null || unit.isFormal() || unit.conversionFactor <= 0) {
if (unit == null || !unit.isFormal() || unit.conversionFactor <= 0) {
return 0.0;
}
return amount * unit.conversionFactor;

View file

@ -11,13 +11,11 @@ public class RecipeIngredientTest {
private Recipe recipe;
private Ingredient ingredient;
private RecipeIngredient recipeIngredient;
private RecipeIngredient testIngredient;
@BeforeEach
void setup(){
recipe = new Recipe();
ingredient = new Ingredient();
testIngredient = new RecipeIngredient(recipe,ingredient,1,"KILOGRAM");
}
@ -59,6 +57,16 @@ public class RecipeIngredientTest {
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());
}
}