Commit 15f0bad4 authored by Antoine Hazebrouck's avatar Antoine Hazebrouck

plats par calories

parent 3dd8e673
package imt;
import imt.ingredients.Consigne;
import imt.ingredients.Ingredient;
import imt.ingredients.Legume;
import imt.ingredients.Plat;
import imt.ingredients.ViandePoisson;
public class Application {
public static void main(String[] args) {
// var chef = new Chef(1, "Caca", "Pipi", "DQSQFQSF", Genre.HOMME, 3, Specialite.CUISINIER);
// var padawan = new Padawan(1, "Hazebrouck", "Antoine", "06 51 73 08 05", Genre.HOMME, chef);
// System.out.println(padawan);
Ingredient ingredient1 = new Legume(1,"Oignons",120,false);
Ingredient ingredient2 = new Legume(2,"Patate",120,false);
Ingredient ingredient3 = new ViandePoisson(3,"Poulet",120,12);
Consigne[] consignes = Consigne.values();
Ingredient[] ingredients = {ingredient1, ingredient2, ingredient3};
for (int i=0; i<=2; i++){
ingredients[i].setConsignes(consignes);
}
System.out.println(ingredient1);
Plat plat = new Plat(1,"Oignon Poulet patate", ingredients);
System.out.println(plat);
}
}
......@@ -54,4 +54,10 @@ public class Plat {
.allMatch(ingredient -> ingredient.isBio());
}
public int getCalories() {
return Stream.of(ingredients)
.mapToInt(ingredient -> ingredient.getCalories())
.sum();
}
}
package imt.personnes;
import java.util.List;
import java.util.Set;
import imt.ingredients.Plat;
......@@ -22,4 +23,11 @@ public class Chef extends Person {
this.specialite = specialite;
this.plats = plats;
}
public List<Plat> getPlatsParCalories() {
return plats.stream()
.sorted((left, right) -> {
return Integer.valueOf(left.getCalories()).compareTo(Integer.valueOf(right.getCalories()));
}).toList();
}
}
......@@ -22,4 +22,13 @@ public class PlatTest {
assertThat(platNonBio.isBio()).isFalse();
}
@Test
void calories_d_un_plat() {
Plat platBio = new Plat(1, "plat1", new Ingredient[] {
STEAK, OIGNON
});
assertThat(platBio.getCalories()).isEqualTo(STEAK.getCalories() + OIGNON.getCalories());
}
}
package imt.personnes;
import static imt.ingredients.IngredientTest.AUTRE;
import static imt.ingredients.IngredientTest.OIGNON;
import static imt.ingredients.IngredientTest.STEAK;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.Test;
import imt.ingredients.Ingredient;
import imt.ingredients.Legume;
import imt.ingredients.Plat;
public class ChefTest {
// @Test
// void plat_connus_d_un_chef_par_calories() {
// Plat plat1 = new Plat(1, "plat1", new Ingredient[] {
// new Legume(1, "poivron", 10, true);
// });
// }
@Test
void plat_connus_d_un_chef_par_calories() {
Plat plat1 = new Plat(1, "plat1", new Ingredient[] {
OIGNON, STEAK
});
Plat plat2 = new Plat(2, "plat2", new Ingredient[] {
OIGNON, AUTRE
});
Plat plat3 = new Plat(3, "plat3", new Ingredient[] {
STEAK, AUTRE
});
Chef chef = new Chef(1, "mister", "toto", "06 .", Genre.HOMME, 2, Specialite.CUISINIER, Set.of(plat1, plat2, plat3));
assertThat(chef.getPlatsParCalories()).isEqualTo(List.of(
plat1,
plat3,
plat2
));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment