Commit c5fd52a4 authored by Antoine Hazebrouck's avatar Antoine Hazebrouck

classement fini

parent 8b9de534
Pipeline #2881 canceled with stages
...@@ -31,6 +31,13 @@ ...@@ -31,6 +31,13 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.26.0</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package imt; package imt;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
...@@ -42,4 +43,17 @@ public class Concours { ...@@ -42,4 +43,17 @@ public class Concours {
} }
} }
} }
public List<Proposition> classement() {
return getPropositions().stream().sorted((left, right) -> {
if (left.getNote().isEmpty()) {
return +1;
} else if (right.getNote().isEmpty()) {
return -1;
} else {
return left.getNote().get().compareTo(right.getNote().get());
}
})
.toList();
}
} }
...@@ -4,7 +4,9 @@ import imt.ingredients.Consigne; ...@@ -4,7 +4,9 @@ import imt.ingredients.Consigne;
import imt.ingredients.Ingredient; import imt.ingredients.Ingredient;
import imt.ingredients.Legume; import imt.ingredients.Legume;
import imt.ingredients.ViandePoisson; import imt.ingredients.ViandePoisson;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode
public class Plat { public class Plat {
private int idPlat; private int idPlat;
private String nomPlat; private String nomPlat;
......
...@@ -7,29 +7,43 @@ import java.util.Set; ...@@ -7,29 +7,43 @@ import java.util.Set;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import imt.ingredients.Ingredient;
public class ConcoursTest { public class ConcoursTest {
Jury jury1 = new Jury(1, "nom1", "prenom1", "06", Genre.HOMME); public static Jury jury1 = new Jury(1, "nom1", "prenom1", "06", Genre.HOMME);
Jury jury2 = new Jury(2, "nom2", "prenom2", "06", Genre.HOMME); public static Jury jury2 = new Jury(2, "nom2", "prenom2", "06", Genre.HOMME);
Jury jury3 = new Jury(3, "nom3", "prenom3", "06", Genre.HOMME); public static Jury jury3 = new Jury(3, "nom3", "prenom3", "06", Genre.HOMME);
Chef chef1 = new Chef(1, "chef1", "prenomchef1", "07", Genre.HOMME, 2, Specialite.PATISSIER, public static Chef chef1 = new Chef(1, "chef1", "prenomchef1", "07", Genre.HOMME, 2, Specialite.PATISSIER,
Set.of(new Plat("plat1"))); Set.of(new Plat(1, "plat1", new Ingredient[] {})));
Chef chef2 = new Chef(2, "chef2", "prenomchef2", "07", Genre.HOMME, 2, Specialite.PATISSIER, public static Chef chef2 = new Chef(2, "chef2", "prenomchef2", "07", Genre.HOMME, 2, Specialite.PATISSIER,
Set.of(new Plat("plat2"))); Set.of(new Plat(2, "plat2", new Ingredient[] {})));
Chef chef3 = new Chef(3, "chef3", "prenomchef3", "07", Genre.HOMME, 2, Specialite.PATISSIER, public static Chef chef3 = new Chef(3, "chef3", "prenomchef3", "07", Genre.HOMME, 2, Specialite.PATISSIER,
Set.of(new Plat("plat3"))); Set.of(new Plat(3, "plat3", new Ingredient[] {})));
Chef chef4 = new Chef(4, "chef4", "prenomchef4", "07", Genre.HOMME, 2, Specialite.PATISSIER, public static Chef chef4 = new Chef(4, "chef4", "prenomchef4", "07", Genre.HOMME, 2, Specialite.PATISSIER,
Set.of(new Plat("plat4"))); Set.of(new Plat(4, "plat4", new Ingredient[] {})));
Chef chef5 = new Chef(5, "chef5", "prenomchef5", "07", Genre.HOMME, 2, Specialite.PATISSIER, public static Chef chef5 = new Chef(5, "chef5", "prenomchef5", "07", Genre.HOMME, 2, Specialite.PATISSIER,
Set.of(new Plat("plat5"))); Set.of(new Plat(5, "plat5", new Ingredient[] {})));
public static Proposition proposition1 = new Proposition(new Plat(1, "plat1", new Ingredient[] {}), chef1);
public static Proposition proposition2 = new Proposition(new Plat(2, "plat2", new Ingredient[] {}), chef2);
public static Proposition proposition3 = new Proposition(new Plat(3, "plat3", new Ingredient[] {}), chef3);
public static Proposition proposition4 = new Proposition(new Plat(4, "plat4", new Ingredient[] {}), chef4);
public static Proposition proposition5 = new Proposition(new Plat(5, "plat5", new Ingredient[] {}), chef5);
public static Set<Proposition> propositions = Set.of(
proposition1,
proposition2,
proposition3,
proposition4,
proposition5);
@Test @Test
void concours_trois_jurys_cinq_chefs() { void concours_trois_jurys_cinq_chefs() {
var propositions = Set.of( var propositions = Set.of(
new Proposition(new Plat("plat1"), chef1), proposition1,
new Proposition(new Plat("plat2"), chef2), proposition2,
new Proposition(new Plat("plat3"), chef3), proposition3,
new Proposition(new Plat("plat4"), chef4)); proposition4);
assertThrows(IllegalArgumentException.class, () -> new Concours(jury1, jury2, jury3, propositions)); assertThrows(IllegalArgumentException.class, () -> new Concours(jury1, jury2, jury3, propositions));
} }
...@@ -37,30 +51,18 @@ public class ConcoursTest { ...@@ -37,30 +51,18 @@ public class ConcoursTest {
@Test @Test
void les_chefs_proposent_un_plat_qu_ils_savent_faire() { void les_chefs_proposent_un_plat_qu_ils_savent_faire() {
var propositions = Set.of( var propositions = Set.of(
new Proposition(new Plat("plat1"), chef1), proposition1,
new Proposition(new Plat("plat2"), chef2), proposition2,
new Proposition(new Plat("plat3"), chef3), proposition3,
new Proposition(new Plat("plat4"), chef4), proposition4,
new Proposition(new Plat("je sais pas faire donc exception"), chef5)); new Proposition(new Plat(99, "je sais pas faire donc exception", new Ingredient[]{}), chef5));
assertThrows(IllegalArgumentException.class, () -> new Concours(jury1, jury2, jury3, propositions)); assertThrows(IllegalArgumentException.class, () -> new Concours(jury1, jury2, jury3, propositions));
} }
@Test @Test
void fin_du_concours() { void fin_du_concours() {
Proposition proposition1 = new Proposition(new Plat("plat1"), chef1); Concours concours = new Concours(jury1, jury2, jury3, propositions);
Proposition proposition2 = new Proposition(new Plat("plat2"), chef2);
Proposition proposition3 = new Proposition(new Plat("plat3"), chef3);
Proposition proposition4 = new Proposition(new Plat("plat4"), chef4);
Proposition proposition5 = new Proposition(new Plat("plat5"), chef5);
Concours concours = new Concours(jury1, jury2, jury3, Set.of(
proposition1,
proposition2,
proposition3,
proposition4,
proposition5
));
assertEquals(false, concours.estTermine()); assertEquals(false, concours.estTermine());
......
package imt; package imt;
import static imt.ConcoursTest.jury1;
import static imt.ConcoursTest.jury2;
import static imt.ConcoursTest.jury3;
import static imt.ConcoursTest.proposition1;
import static imt.ConcoursTest.proposition2;
import static imt.ConcoursTest.proposition3;
import static imt.ConcoursTest.proposition4;
import static imt.ConcoursTest.proposition5;
import static imt.ConcoursTest.propositions;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class FileConcoursTest { public class FileConcoursTest {
@Test @Test
void fileDeConcours() { void fileDeConcours_passage_au_suivant() {
Concours concours1 = new Concours(jury1, jury2, jury3, propositions);
}
@Test
void fileDeConcours_classement_actuel() {
Concours concours1 = new Concours(jury1, jury2, jury3, propositions);
List<Proposition> expected = new ArrayList<>();
expected.add(proposition1);
expected.add(proposition2);
expected.add(proposition3);
expected.add(proposition4);
expected.add(proposition5);
proposition1.setNote(Optional.of(1));
proposition2.setNote(Optional.of(2));
proposition3.setNote(Optional.of(3));
proposition4.setNote(Optional.of(4));
// proposition5.setNote(Optional.of(100));
assertThat(concours1.classement()).isEqualTo(expected);
System.out.println(concours1.classement());
} }
} }
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