Compare commits
3 Commits
update-doc
...
feature/ad
| Author | SHA1 | Date | |
|---|---|---|---|
| 22bf1361ee | |||
| a9de7a9448 | |||
| 216cb51c0d |
@@ -7,8 +7,6 @@ Se rendre sur : https://grond.iut-fbleau.fr/pierront/rock-paper-scissors
|
||||
|
||||
Faire un fork
|
||||
|
||||
`/!\ ATTENTION NE PRENDRE QUE LA BRANCHE MAIN /!\`
|
||||
|
||||
## Créer la VM pour jenkins
|
||||
### Créer la règle pare-feu pour accéder aux ports 8080 et 8081
|
||||
Aller dans la section Pare-Feu
|
||||
@@ -119,7 +117,7 @@ Vous devriez voir la page d'accueil de Jenkins
|
||||
---
|
||||
|
||||
## Création d'un pipeline
|
||||
* Aller sur l'accueil Jenkins -> New Item
|
||||
* Aller dans la section Manage Jenkins -> New Item
|
||||
* Nommer le projet : rock-paper-scissors
|
||||
* Choisir le type de projet : Multibranch Pipeline
|
||||
* Cliquer sur OK
|
||||
@@ -128,6 +126,7 @@ Vous devriez voir la page d'accueil de Jenkins
|
||||
* utiliser le jeton gitea-token
|
||||
* owner : _<votre nom d'utilisateur gitea>_
|
||||
* Choisir le projet : rock-paper-scissors
|
||||
* Choisir le provider : Git
|
||||
* Choisir le repository : https://grond.iut-fbleau.fr/pierront/rock-paper-scissors.git
|
||||
* Cliquer sur Save
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain;
|
||||
|
||||
public enum GameResult {
|
||||
WIN,
|
||||
LOOSE,
|
||||
TIE,
|
||||
}
|
||||
@@ -3,13 +3,18 @@ package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain;
|
||||
public enum Move {
|
||||
ROCK,
|
||||
PAPER,
|
||||
SCISSORS;
|
||||
SCISSORS,
|
||||
WELL;
|
||||
|
||||
public boolean beats(Move other) {
|
||||
return switch (this) {
|
||||
public GameResult beats(Move other) {
|
||||
if (this.equals(other))
|
||||
return GameResult.TIE;
|
||||
boolean beats = switch (this) {
|
||||
case ROCK -> other == SCISSORS;
|
||||
case PAPER -> other == ROCK;
|
||||
case PAPER -> other == ROCK || other == WELL;
|
||||
case SCISSORS -> other == PAPER;
|
||||
case WELL -> other == ROCK || other == SCISSORS;
|
||||
};
|
||||
return beats ? GameResult.WIN : GameResult.LOOSE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,14 @@ public record RockPaperScissorsPlayer(CpuPick cpuPick, StatSave statSave) implem
|
||||
|
||||
public static final String WIN = "WIN";
|
||||
public static final String LOOSE = "LOOSE";
|
||||
public static final String TIE = "TIE";
|
||||
|
||||
@Override
|
||||
public RoundResult playRound(String name, Move move) {
|
||||
var cpuPicked = this.cpuPick.pick();
|
||||
boolean beats = move.beats(cpuPicked);
|
||||
String result = beats ? WIN : LOOSE;
|
||||
GameResult beats = move.beats(cpuPicked);
|
||||
String result = String.valueOf(beats);
|
||||
|
||||
if (result.equals(WIN)) {
|
||||
this.statSave.addWin(name);
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain.RockPaperScissorsPlayer.LOOSE;
|
||||
import static fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain.RockPaperScissorsPlayer.WIN;
|
||||
import static fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain.RockPaperScissorsPlayer.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
@@ -46,7 +45,8 @@ public class PlayControllerTest {
|
||||
public static Stream<Arguments> scenario() {
|
||||
return Stream.of(
|
||||
Arguments.of(Move.ROCK, Move.SCISSORS, WIN),
|
||||
Arguments.of(Move.ROCK, Move.PAPER, LOOSE)
|
||||
Arguments.of(Move.ROCK, Move.PAPER, LOOSE),
|
||||
Arguments.of(Move.ROCK,Move.ROCK, TIE)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -67,5 +67,4 @@ public class PlayControllerTest {
|
||||
.andExpect(jsonPath("$.result").value(expectedResult))
|
||||
.andExpect(jsonPath("$.cpu").value(cpuMove.name()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
@@ -14,9 +15,12 @@ class MoveTest {
|
||||
|
||||
@Test
|
||||
void should_check_move_size(){
|
||||
Assertions.assertEquals(3, Move.values().length);
|
||||
Assertions.assertEquals(4, Move.values().length);
|
||||
}
|
||||
|
||||
private void assertTrue(GameResult beats) {}
|
||||
private void assertFalse(GameResult beats) {}
|
||||
|
||||
@ParameterizedTest(name = "{0} should beat {1}")
|
||||
@MethodSource("winnable")
|
||||
void should_win(Move move1, Move move2) {
|
||||
@@ -29,11 +33,20 @@ class MoveTest {
|
||||
assertFalse(move2.beats(move1));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{1} should tie against {0}")
|
||||
@EnumSource(Move.class)
|
||||
void should_tie(Move move) {
|
||||
assertFalse(move.beats(move));
|
||||
}
|
||||
|
||||
static Stream<Arguments> winnable(){
|
||||
return Stream.of(
|
||||
Arguments.of(Move.ROCK,Move.SCISSORS),
|
||||
Arguments.of(Move.PAPER,Move.ROCK),
|
||||
Arguments.of(Move.SCISSORS,Move.PAPER)
|
||||
Arguments.of(Move.PAPER,Move.WELL),
|
||||
Arguments.of(Move.SCISSORS,Move.PAPER),
|
||||
Arguments.of(Move.WELL,Move.ROCK),
|
||||
Arguments.of(Move.WELL,Move.SCISSORS)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,4 +39,12 @@ public class RockPaperScissorsPlayTest {
|
||||
assertEquals(Move.ROCK, roundResult.cpuChoice());
|
||||
verify(statSaver, times(0)).addWin("joe");
|
||||
}
|
||||
|
||||
void should_tie_a_game(){
|
||||
cpuPick.setNextMove(Move.ROCK);
|
||||
RoundResult roundResult = play.playRound("joe", Move.ROCK);
|
||||
assertEquals("TIE", roundResult.result());
|
||||
assertEquals("joe", roundResult.opponent());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,9 +20,10 @@ class RandomCpuPickerTest {
|
||||
obtainedMoves.add(picker.pick());
|
||||
}
|
||||
|
||||
assertEquals(3, obtainedMoves.size());
|
||||
assertEquals(4, obtainedMoves.size());
|
||||
assertTrue(obtainedMoves.contains(Move.ROCK));
|
||||
assertTrue(obtainedMoves.contains(Move.PAPER));
|
||||
assertTrue(obtainedMoves.contains(Move.SCISSORS));
|
||||
assertTrue(obtainedMoves.contains(Move.WELL));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user