tested all units conversion and made every unit type a field
This commit is contained in:
parent
fef20ec876
commit
6794efa3a6
1 changed files with 60 additions and 37 deletions
|
|
@ -8,65 +8,88 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class RecipeIngredientTest {
|
public class RecipeIngredientTest {
|
||||||
|
|
||||||
private Recipe recipe;
|
private RecipeIngredient gram;
|
||||||
private Ingredient ingredient;
|
private RecipeIngredient kilogram;
|
||||||
private RecipeIngredient recipeIngredient;
|
private RecipeIngredient milliliter;
|
||||||
|
private RecipeIngredient liter;
|
||||||
|
private RecipeIngredient teaspoon;
|
||||||
|
private RecipeIngredient tablespoon;
|
||||||
|
private RecipeIngredient cup;
|
||||||
|
private RecipeIngredient piece;
|
||||||
|
private RecipeIngredient pinch;
|
||||||
|
private RecipeIngredient handful;
|
||||||
|
private RecipeIngredient to_taste;
|
||||||
|
private RecipeIngredient invalid;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup(){
|
void setup(){
|
||||||
recipe = new Recipe();
|
Recipe recipe = new Recipe();
|
||||||
ingredient = new Ingredient();
|
Ingredient ingredient = new Ingredient();
|
||||||
|
gram = new RecipeIngredient(recipe,ingredient,1,"GRAM");
|
||||||
|
kilogram = new RecipeIngredient(recipe,ingredient,1,"KILOGRAM");
|
||||||
|
|
||||||
|
milliliter = new RecipeIngredient(recipe,ingredient,1,"MILLILITER");
|
||||||
|
liter = new RecipeIngredient(recipe,ingredient,1,"LITER");
|
||||||
|
teaspoon = new RecipeIngredient(recipe,ingredient,1,"TEASPOON");
|
||||||
|
tablespoon = new RecipeIngredient(recipe,ingredient,1,"TABLESPOON");
|
||||||
|
cup = new RecipeIngredient(recipe,ingredient,1,"CUP");
|
||||||
|
piece = new RecipeIngredient(recipe,ingredient,1,"PIECE");
|
||||||
|
pinch = new RecipeIngredient(recipe,ingredient,1,"PINCH");
|
||||||
|
handful = new RecipeIngredient(recipe,ingredient,1,"HANDFUL");
|
||||||
|
to_taste = new RecipeIngredient(recipe,ingredient,1,"TO_TASTE");
|
||||||
|
|
||||||
|
invalid = new RecipeIngredient(recipe,ingredient,1,"INVALID");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getFormalUnitTest(){
|
void getFormalUnitTest(){
|
||||||
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"GRAM");
|
assertEquals(Unit.GRAM, gram.getUnit());
|
||||||
assertEquals(Unit.GRAM, recipeIngredient.getUnit());
|
assertEquals(Unit.KILOGRAM, kilogram.getUnit());
|
||||||
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"KILOGRAM");
|
assertEquals(Unit.MILLILITER, milliliter.getUnit());
|
||||||
assertEquals(Unit.KILOGRAM, recipeIngredient.getUnit());
|
assertEquals(Unit.LITER, liter.getUnit());
|
||||||
|
assertEquals(Unit.TEASPOON, teaspoon.getUnit());
|
||||||
|
assertEquals(Unit.TABLESPOON, tablespoon.getUnit());
|
||||||
|
assertEquals(Unit.CUP, cup.getUnit());
|
||||||
|
|
||||||
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"MILLILITER");
|
assertEquals(Unit.PIECE, piece.getUnit());
|
||||||
assertEquals(Unit.MILLILITER, recipeIngredient.getUnit());
|
|
||||||
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"LITER");
|
|
||||||
assertEquals(Unit.LITER, recipeIngredient.getUnit());
|
|
||||||
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"TEASPOON");
|
|
||||||
assertEquals(Unit.TEASPOON, recipeIngredient.getUnit());
|
|
||||||
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"TABLESPOON");
|
|
||||||
assertEquals(Unit.TABLESPOON, recipeIngredient.getUnit());
|
|
||||||
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"CUP");
|
|
||||||
assertEquals(Unit.CUP, recipeIngredient.getUnit());
|
|
||||||
|
|
||||||
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"PIECE");
|
|
||||||
assertEquals(Unit.PIECE, recipeIngredient.getUnit());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getInformalUnitTest(){
|
void getInformalUnitTest(){
|
||||||
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"PINCH");
|
assertEquals(Unit.PINCH, pinch.getUnit());
|
||||||
assertEquals(Unit.PINCH, recipeIngredient.getUnit());
|
assertEquals(Unit.HANDFUL, handful.getUnit());
|
||||||
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"HANDFUL");
|
assertEquals(Unit.TO_TASTE, to_taste.getUnit());
|
||||||
assertEquals(Unit.HANDFUL, recipeIngredient.getUnit());
|
|
||||||
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"TO_TASTE");
|
|
||||||
assertEquals(Unit.TO_TASTE, recipeIngredient.getUnit());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getUnknownUnitTest(){
|
void getUnknownUnitTest(){
|
||||||
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"RANDOM");
|
assertNull(invalid.getUnit());
|
||||||
assertNull(recipeIngredient.getUnit());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void convertToBaseUnit(){
|
void convertFormalToBaseUnit(){
|
||||||
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"KILOGRAM");
|
assertEquals(1000, kilogram.amountInBaseUnit());
|
||||||
assertEquals(1000, recipeIngredient.amountInBaseUnit());
|
|
||||||
|
|
||||||
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"PINCH");
|
assertEquals(1,milliliter.amountInBaseUnit());
|
||||||
assertEquals(0,recipeIngredient.amountInBaseUnit());
|
assertEquals(1000.0,liter.amountInBaseUnit());
|
||||||
|
assertEquals(15.0,tablespoon.amountInBaseUnit());
|
||||||
|
assertEquals(5,teaspoon.amountInBaseUnit());
|
||||||
|
assertEquals(240.0,cup.amountInBaseUnit());
|
||||||
|
|
||||||
recipeIngredient = new RecipeIngredient(recipe,ingredient,1,"RANDOM");
|
assertEquals(1.0,piece.amountInBaseUnit());
|
||||||
assertEquals(0,recipeIngredient.amountInBaseUnit());
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void convertInformalToBaseUnit(){
|
||||||
|
assertEquals(0,pinch.amountInBaseUnit());
|
||||||
|
assertEquals(0,handful.amountInBaseUnit());
|
||||||
|
assertEquals(0,to_taste.amountInBaseUnit());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void convertUnknownToBaseUnit(){
|
||||||
|
assertEquals(0,invalid.amountInBaseUnit());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue