diff --git a/commons/src/test/java/commons/FormalIngredientTest.java b/commons/src/test/java/commons/FormalIngredientTest.java new file mode 100644 index 0000000..deeeb46 --- /dev/null +++ b/commons/src/test/java/commons/FormalIngredientTest.java @@ -0,0 +1,58 @@ +package commons; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class FormalIngredientTest { + + @Test + void normaliseGramsToTest(){ + Ingredient ingredient = new Ingredient("Bread", 1, 2, 3); + FormalIngredient toKg = new FormalIngredient(ingredient,1_000,"g"); + FormalIngredient toTonne = new FormalIngredient(ingredient,1_000_000,"g"); + + + assertEquals(toKg.normalisedUnit(),"1.0kg"); + assertEquals(toTonne.normalisedUnit(),"1.0t"); + } + + @Test + void normaliseMillilitresToLitresTest(){ + Ingredient ingredient = new Ingredient("Bread", 1, 2, 3); + FormalIngredient toKg = new FormalIngredient(ingredient,1_000,"ml"); + + assertEquals(toKg.normalisedUnit(),"1.0l"); + } + + @Test + void normaliseOunceToPoundTest(){ + Ingredient ingredient = new Ingredient("Bread", 1, 2, 3); + FormalIngredient toPound = new FormalIngredient(ingredient,16,"oz"); + + assertEquals(toPound.normalisedUnit(),"1.0lb"); + } + + @Test + void normaliseTablespoonToTest(){ + Ingredient ingredient = new Ingredient("Bread", 1, 2, 3); + FormalIngredient toCup = new FormalIngredient(ingredient,16,"tbsp"); + FormalIngredient toPound = new FormalIngredient(ingredient,32,"tbsp"); + FormalIngredient toOunce = new FormalIngredient(ingredient,2,"tbsp"); + + assertEquals(toCup.normalisedUnit(),"1.0cup(s)"); + assertEquals(toPound.normalisedUnit(),"1.0lb"); + assertEquals(toOunce.normalisedUnit(),"1.0oz"); + } + + + @Test + void noNormaliseTest(){ + Ingredient ingredient = new Ingredient("Bread", 1, 2, 3); + FormalIngredient informal = new FormalIngredient(ingredient,10,""); + FormalIngredient toSmall = new FormalIngredient(ingredient,10,"g"); + + assertEquals(informal.normalisedUnit(),"10.0"); + assertEquals(toSmall.normalisedUnit(),"10.0g"); + } +} \ No newline at end of file