Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tok-chef
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Antoine HAZEBROUCK
tok-chef
Commits
159fe3fa
Commit
159fe3fa
authored
Sep 13, 2024
by
Antoine Hazebrouck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug immutable Proposition
parent
15f0bad4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
132 additions
and
64 deletions
+132
-64
Concours.java
src/main/java/imt/concours/Concours.java
+13
-6
FileConcours.java
src/main/java/imt/concours/FileConcours.java
+21
-0
Proposition.java
src/main/java/imt/concours/Proposition.java
+9
-3
ConcoursTest.java
src/test/java/imt/concours/ConcoursTest.java
+47
-43
FileConcoursTest.java
src/test/java/imt/concours/FileConcoursTest.java
+42
-12
No files found.
src/main/java/imt/concours/Concours.java
View file @
159fe3fa
...
@@ -3,16 +3,20 @@ package imt.concours;
...
@@ -3,16 +3,20 @@ package imt.concours;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
imt.personnes.Jury
;
import
imt.personnes.Jury
;
import
lombok.AccessLevel
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.Setter
;
@Data
@Data
public
class
Concours
{
public
class
Concours
{
private
final
Jury
jury1
;
private
final
Jury
jury1
;
private
final
Jury
jury2
;
private
final
Jury
jury2
;
private
final
Jury
jury3
;
private
final
Jury
jury3
;
private
final
Set
<
Proposition
>
propositions
;
// minimun 5
@Setter
(
value
=
AccessLevel
.
NONE
)
private
Set
<
Proposition
>
propositions
;
// minimun 5
public
Concours
(
Jury
jury1
,
Jury
jury2
,
Jury
jury3
,
Set
<
Proposition
>
propositions
)
{
public
Concours
(
Jury
jury1
,
Jury
jury2
,
Jury
jury3
,
Set
<
Proposition
>
propositions
)
{
this
.
jury1
=
jury1
;
this
.
jury1
=
jury1
;
...
@@ -38,11 +42,14 @@ public class Concours {
...
@@ -38,11 +42,14 @@ public class Concours {
}
}
public
void
noter
(
Proposition
proposition
,
int
note
)
{
public
void
noter
(
Proposition
proposition
,
int
note
)
{
for
(
Proposition
propositionLoop
:
propositions
)
{
propositions
=
propositions
.
stream
()
.
map
(
propositionLoop
->
{
if
(
propositionLoop
.
equals
(
proposition
))
{
if
(
propositionLoop
.
equals
(
proposition
))
{
propositionLoop
.
setNote
(
Optional
.
of
(
note
));
return
propositionLoop
.
withNote
(
Optional
.
of
(
note
));
// .setNote(Optional.of(note));
}
}
}
return
propositionLoop
;
})
.
collect
(
Collectors
.
toSet
());
}
}
public
List
<
Proposition
>
classement
()
{
public
List
<
Proposition
>
classement
()
{
...
...
src/main/java/imt/concours/FileConcours.java
View file @
159fe3fa
package
imt
.
concours
;
package
imt
.
concours
;
import
java.util.ArrayList
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Queue
;
import
java.util.Queue
;
...
@@ -9,9 +10,11 @@ import imt.personnes.Chef;
...
@@ -9,9 +10,11 @@ import imt.personnes.Chef;
public
class
FileConcours
{
public
class
FileConcours
{
private
final
Queue
<
Concours
>
concours
;
private
final
Queue
<
Concours
>
concours
;
private
final
List
<
Concours
>
concoursTermines
;
public
FileConcours
(
Concours
...
concours
)
{
public
FileConcours
(
Concours
...
concours
)
{
this
.
concours
=
new
LinkedList
<
Concours
>(
Stream
.
of
(
concours
).
toList
());
this
.
concours
=
new
LinkedList
<
Concours
>(
Stream
.
of
(
concours
).
toList
());
this
.
concoursTermines
=
new
ArrayList
<>();
}
}
public
List
<
Concours
>
concoursAuquelParticipe
(
Chef
chef
)
{
public
List
<
Concours
>
concoursAuquelParticipe
(
Chef
chef
)
{
...
@@ -20,4 +23,22 @@ public class FileConcours {
...
@@ -20,4 +23,22 @@ public class FileConcours {
.
contains
(
chef
))
.
contains
(
chef
))
.
toList
();
.
toList
();
}
}
public
Concours
concoursActuel
()
{
return
concours
.
peek
();
}
// true is ca a marché, false si le concours actuel est pas bien fini
public
boolean
passerAuConcoursSuivant
()
{
if
(
concoursActuel
().
estTermine
())
{
concoursTermines
.
add
(
concours
.
poll
());
return
true
;
}
else
{
return
false
;
}
}
public
List
<
Concours
>
concoursTermines
()
{
return
concoursTermines
;
}
}
}
src/main/java/imt/concours/Proposition.java
View file @
159fe3fa
...
@@ -5,16 +5,22 @@ import java.util.Optional;
...
@@ -5,16 +5,22 @@ import java.util.Optional;
import
imt.ingredients.Plat
;
import
imt.ingredients.Plat
;
import
imt.personnes.Chef
;
import
imt.personnes.Chef
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.With
;
@Data
@Data
public
class
Proposition
{
public
class
Proposition
{
private
final
Plat
platPropose
;
private
final
Plat
platPropose
;
private
final
Chef
chef
;
private
final
Chef
chef
;
private
Optional
<
Integer
>
note
;
@With
private
final
Optional
<
Integer
>
note
;
p
ublic
Proposition
(
Plat
platPropose
,
Chef
chef
)
{
p
rivate
Proposition
(
Plat
platPropose
,
Chef
chef
,
Optional
<
Integer
>
note
)
{
this
.
platPropose
=
platPropose
;
this
.
platPropose
=
platPropose
;
this
.
chef
=
chef
;
this
.
chef
=
chef
;
this
.
note
=
Optional
.
empty
();
this
.
note
=
note
;
}
public
Proposition
(
Plat
platPropose
,
Chef
chef
)
{
this
(
platPropose
,
chef
,
Optional
.
empty
());
}
}
}
}
src/test/java/imt/concours/ConcoursTest.java
View file @
159fe3fa
...
@@ -19,11 +19,11 @@ import imt.personnes.Jury;
...
@@ -19,11 +19,11 @@ import imt.personnes.Jury;
import
imt.personnes.Specialite
;
import
imt.personnes.Specialite
;
public
class
ConcoursTest
{
public
class
ConcoursTest
{
public
static
Jury
jury
1
=
new
Jury
(
1
,
"nom1"
,
"prenom1"
,
"06"
,
Genre
.
HOMME
);
public
static
Jury
JURY_
1
=
new
Jury
(
1
,
"nom1"
,
"prenom1"
,
"06"
,
Genre
.
HOMME
);
public
static
Jury
jury
2
=
new
Jury
(
2
,
"nom2"
,
"prenom2"
,
"06"
,
Genre
.
HOMME
);
public
static
Jury
JURY_
2
=
new
Jury
(
2
,
"nom2"
,
"prenom2"
,
"06"
,
Genre
.
HOMME
);
public
static
Jury
jury
3
=
new
Jury
(
3
,
"nom3"
,
"prenom3"
,
"06"
,
Genre
.
HOMME
);
public
static
Jury
JURY_
3
=
new
Jury
(
3
,
"nom3"
,
"prenom3"
,
"06"
,
Genre
.
HOMME
);
public
static
Chef
chef
1
=
new
Chef
(
1
,
"chef1"
,
"prenomchef1"
,
"07"
,
Genre
.
HOMME
,
2
,
Specialite
.
PATISSIER
,
public
static
Chef
CHEF_
1
=
new
Chef
(
1
,
"chef1"
,
"prenomchef1"
,
"07"
,
Genre
.
HOMME
,
2
,
Specialite
.
PATISSIER
,
Set
.
of
(
new
Plat
(
1
,
"plat1"
,
new
Ingredient
[]
{})));
Set
.
of
(
new
Plat
(
1
,
"plat1"
,
new
Ingredient
[]
{})));
public
static
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
(
2
,
"plat2"
,
new
Ingredient
[]
{})));
Set
.
of
(
new
Plat
(
2
,
"plat2"
,
new
Ingredient
[]
{})));
...
@@ -34,75 +34,79 @@ public class ConcoursTest {
...
@@ -34,75 +34,79 @@ public class ConcoursTest {
public
static
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
(
5
,
"plat5"
,
new
Ingredient
[]
{})));
Set
.
of
(
new
Plat
(
5
,
"plat5"
,
new
Ingredient
[]
{})));
public
static
Proposition
proposition1
=
new
Proposition
(
new
Plat
(
1
,
"plat1"
,
new
Ingredient
[]
{}),
chef
1
);
public
static
Proposition
PROPOSITION_1
=
new
Proposition
(
new
Plat
(
1
,
"plat1"
,
new
Ingredient
[]
{}),
CHEF_
1
);
public
static
Proposition
proposition
2
=
new
Proposition
(
new
Plat
(
2
,
"plat2"
,
new
Ingredient
[]
{}),
chef2
);
public
static
Proposition
PROPOSITION_
2
=
new
Proposition
(
new
Plat
(
2
,
"plat2"
,
new
Ingredient
[]
{}),
chef2
);
public
static
Proposition
proposition
3
=
new
Proposition
(
new
Plat
(
3
,
"plat3"
,
new
Ingredient
[]
{}),
chef3
);
public
static
Proposition
PROPOSITION_
3
=
new
Proposition
(
new
Plat
(
3
,
"plat3"
,
new
Ingredient
[]
{}),
chef3
);
public
static
Proposition
proposition
4
=
new
Proposition
(
new
Plat
(
4
,
"plat4"
,
new
Ingredient
[]
{}),
chef4
);
public
static
Proposition
PROPOSITION_
4
=
new
Proposition
(
new
Plat
(
4
,
"plat4"
,
new
Ingredient
[]
{}),
chef4
);
public
static
Proposition
proposition
5
=
new
Proposition
(
new
Plat
(
5
,
"plat5"
,
new
Ingredient
[]
{}),
chef5
);
public
static
Proposition
PROPOSITION_
5
=
new
Proposition
(
new
Plat
(
5
,
"plat5"
,
new
Ingredient
[]
{}),
chef5
);
public
static
Set
<
Proposition
>
propositions
=
Set
.
of
(
public
static
Set
<
Proposition
>
PROPOSITIONS
=
Set
.
of
(
proposition
1
,
PROPOSITION_
1
,
proposition
2
,
PROPOSITION_
2
,
proposition
3
,
PROPOSITION_
3
,
proposition
4
,
PROPOSITION_
4
,
proposition
5
);
PROPOSITION_
5
);
@Test
@Test
void
concours_trois_jurys_cinq_chefs
()
{
void
concours_trois_jurys_cinq_chefs
()
{
var
propositions
=
Set
.
of
(
var
propositions
=
Set
.
of
(
proposition
1
,
PROPOSITION_
1
,
proposition
2
,
PROPOSITION_
2
,
proposition
3
,
PROPOSITION_
3
,
proposition
4
);
PROPOSITION_
4
);
assertThrows
(
IllegalArgumentException
.
class
,
()
->
new
Concours
(
jury1
,
jury2
,
jury
3
,
propositions
));
assertThrows
(
IllegalArgumentException
.
class
,
()
->
new
Concours
(
JURY_1
,
JURY_2
,
JURY_
3
,
propositions
));
}
}
@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
(
proposition
1
,
PROPOSITION_
1
,
proposition
2
,
PROPOSITION_
2
,
proposition
3
,
PROPOSITION_
3
,
proposition
4
,
PROPOSITION_
4
,
new
Proposition
(
new
Plat
(
99
,
"je sais pas faire donc exception"
,
new
Ingredient
[]{}),
chef5
));
new
Proposition
(
new
Plat
(
99
,
"je sais pas faire donc exception"
,
new
Ingredient
[]{}),
chef5
));
assertThrows
(
IllegalArgumentException
.
class
,
()
->
new
Concours
(
jury1
,
jury2
,
jury
3
,
propositions
));
assertThrows
(
IllegalArgumentException
.
class
,
()
->
new
Concours
(
JURY_1
,
JURY_2
,
JURY_
3
,
propositions
));
}
}
@Test
@Test
void
fin_du_concours
()
{
void
fin_du_concours
()
{
Concours
concours
=
new
Concours
(
jury1
,
jury2
,
jury3
,
propositions
);
Concours
concours
=
new
Concours
(
JURY_1
,
JURY_2
,
JURY_3
,
PROPOSITIONS
);
assertEquals
(
false
,
concours
.
estTermine
());
assertEquals
(
false
,
concours
.
estTermine
());
concours
.
noter
(
proposition
1
,
10
);
concours
.
noter
(
PROPOSITION_
1
,
10
);
concours
.
noter
(
proposition
2
,
3
);
concours
.
noter
(
PROPOSITION_
2
,
3
);
concours
.
noter
(
proposition
3
,
8
);
concours
.
noter
(
PROPOSITION_
3
,
8
);
concours
.
noter
(
proposition
4
,
9
);
concours
.
noter
(
PROPOSITION_
4
,
9
);
concours
.
noter
(
proposition
5
,
18
);
concours
.
noter
(
PROPOSITION_
5
,
18
);
assertEquals
(
true
,
concours
.
estTermine
());
assertEquals
(
true
,
concours
.
estTermine
());
}
}
@Test
@Test
void
classement_actuel
()
{
void
classement_actuel
()
{
Concours
concours1
=
new
Concours
(
jury1
,
jury2
,
jury3
,
propositions
);
Proposition
proposition1
=
PROPOSITION_1
.
withNote
(
Optional
.
of
(
4
));
Proposition
proposition2
=
PROPOSITION_2
.
withNote
(
Optional
.
of
(
3
));
Proposition
proposition3
=
PROPOSITION_3
.
withNote
(
Optional
.
of
(
2
));
Proposition
proposition4
=
PROPOSITION_4
.
withNote
(
Optional
.
of
(
1
));
Proposition
proposition5
=
PROPOSITION_5
;
Concours
concours1
=
new
Concours
(
JURY_1
,
JURY_2
,
JURY_3
,
Set
.
of
(
proposition1
,
proposition2
,
proposition3
,
proposition4
,
proposition5
));
List
<
Proposition
>
expected
=
new
ArrayList
<>();
List
<
Proposition
>
expected
=
new
ArrayList
<>();
expected
.
add
(
proposition1
);
expected
.
add
(
proposition2
);
expected
.
add
(
proposition3
);
expected
.
add
(
proposition4
);
expected
.
add
(
proposition4
);
expected
.
add
(
proposition3
);
expected
.
add
(
proposition2
);
expected
.
add
(
proposition1
);
expected
.
add
(
proposition5
);
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
);
assertThat
(
concours1
.
classement
()).
isEqualTo
(
expected
);
System
.
out
.
println
(
concours1
.
classement
());
}
}
}
}
src/test/java/imt/concours/FileConcoursTest.java
View file @
159fe3fa
package
imt
.
concours
;
package
imt
.
concours
;
import
static
imt
.
concours
.
ConcoursTest
.
chef
1
;
import
static
imt
.
concours
.
ConcoursTest
.
CHEF_
1
;
import
static
imt
.
concours
.
ConcoursTest
.
jury
1
;
import
static
imt
.
concours
.
ConcoursTest
.
JURY_
1
;
import
static
imt
.
concours
.
ConcoursTest
.
jury
2
;
import
static
imt
.
concours
.
ConcoursTest
.
JURY_
2
;
import
static
imt
.
concours
.
ConcoursTest
.
jury
3
;
import
static
imt
.
concours
.
ConcoursTest
.
JURY_
3
;
import
static
imt
.
concours
.
ConcoursTest
.
proposition1
;
import
static
imt
.
concours
.
ConcoursTest
.
PROPOSITIONS
;
import
static
imt
.
concours
.
ConcoursTest
.
propositions
;
import
static
imt
.
concours
.
ConcoursTest
.
*
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
java.util.HashSet
;
import
java.util.HashSet
;
...
@@ -23,18 +23,48 @@ import imt.personnes.Specialite;
...
@@ -23,18 +23,48 @@ import imt.personnes.Specialite;
public
class
FileConcoursTest
{
public
class
FileConcoursTest
{
@Test
@Test
void
fileDeConcours_tout_les_concours_du_chef
()
{
void
fileDeConcours_tout_les_concours_du_chef
()
{
Set
<
Proposition
>
propositionsSansTelChef
=
new
HashSet
<>(
propositions
);
Set
<
Proposition
>
propositionsSansTelChef
=
new
HashSet
<>(
PROPOSITIONS
);
propositionsSansTelChef
.
remove
(
proposition
1
);
propositionsSansTelChef
.
remove
(
PROPOSITION_
1
);
propositionsSansTelChef
.
add
(
propositionsSansTelChef
.
add
(
new
Proposition
(
new
Plat
(
99
,
"plat99"
,
new
Ingredient
[]
{}),
new
Chef
(
99
,
"nom99"
,
"prenom99"
,
"QSD"
,
new
Proposition
(
new
Plat
(
99
,
"plat99"
,
new
Ingredient
[]
{}),
new
Chef
(
99
,
"nom99"
,
"prenom99"
,
"QSD"
,
Genre
.
HOMME
,
4
,
Specialite
.
CUISINIER
,
Set
.
of
(
new
Plat
(
99
,
"plat99"
,
new
Ingredient
[]
{})))));
Genre
.
HOMME
,
4
,
Specialite
.
CUISINIER
,
Set
.
of
(
new
Plat
(
99
,
"plat99"
,
new
Ingredient
[]
{})))));
Concours
concours1
=
new
Concours
(
jury1
,
jury2
,
jury3
,
propositions
);
Concours
concours1
=
new
Concours
(
JURY_1
,
JURY_2
,
JURY_3
,
PROPOSITIONS
);
Concours
concours2
=
new
Concours
(
jury1
,
jury2
,
jury
3
,
propositionsSansTelChef
);
Concours
concours2
=
new
Concours
(
JURY_1
,
JURY_2
,
JURY_
3
,
propositionsSansTelChef
);
Concours
concours3
=
new
Concours
(
jury1
,
jury2
,
jury3
,
new
HashSet
<>(
propositions
));
Concours
concours3
=
new
Concours
(
JURY_1
,
JURY_2
,
JURY_3
,
new
HashSet
<>(
PROPOSITIONS
));
FileConcours
fileConcours
=
new
FileConcours
(
concours1
,
concours2
,
concours3
);
FileConcours
fileConcours
=
new
FileConcours
(
concours1
,
concours2
,
concours3
);
assertThat
(
fileConcours
.
concoursAuquelParticipe
(
chef1
)).
isEqualTo
(
List
.
of
(
concours1
,
concours3
));
assertThat
(
fileConcours
.
concoursAuquelParticipe
(
CHEF_1
)).
isEqualTo
(
List
.
of
(
concours1
,
concours3
));
}
@Test
void
concours_termines
()
{
Concours
concours1
=
new
Concours
(
JURY_1
,
JURY_2
,
JURY_3
,
PROPOSITIONS
);
Concours
concours2
=
new
Concours
(
JURY_1
,
JURY_2
,
JURY_3
,
PROPOSITIONS
);
Concours
concours3
=
new
Concours
(
JURY_1
,
JURY_2
,
JURY_3
,
PROPOSITIONS
);
FileConcours
fileConcours
=
new
FileConcours
(
concours1
,
concours2
,
concours3
);
assertThat
(
fileConcours
.
passerAuConcoursSuivant
()).
isFalse
();
forcer_la_fin_du_concours
(
concours1
);
assertThat
(
fileConcours
.
passerAuConcoursSuivant
()).
isTrue
();
assertThat
(
fileConcours
.
concoursTermines
()).
isEqualTo
(
List
.
of
(
concours1
));
}
void
forcer_la_fin_du_concours
(
Concours
concours
)
{
assertThat
(
concours
.
estTermine
()).
isFalse
();
concours
.
noter
(
PROPOSITION_1
,
10
);
concours
.
noter
(
PROPOSITION_2
,
20
);
concours
.
noter
(
PROPOSITION_3
,
30
);
concours
.
noter
(
PROPOSITION_4
,
40
);
concours
.
noter
(
PROPOSITION_5
,
50
);
assertThat
(
concours
.
estTermine
()).
isTrue
();
}
@Test
void
concours_auquel_un_chef_a_participe
()
{
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment