12 Commits

Author SHA1 Message Date
07ebc8bf4e test: test sur les ajout de l'égalité 2025-11-27 12:24:29 +01:00
d908378ad9 test: ajout de l'égalité 2025-11-27 12:24:17 +01:00
bba8fd25e4 test: changement des tests suite a l'ajout dedu puit 2025-11-27 11:05:54 +01:00
306cc8a2d8 features: Ajout du puit 2025-11-27 11:04:51 +01:00
9b1af5029f Merge pull request 'update-code' (#6) from update-code into main
All checks were successful
rock-paper-scissors/pipeline/head This commit looks good
Reviewed-on: #6
2025-11-26 17:06:38 +01:00
Maxime Pierront
9865e9dcc2 Sort stats by descending win count in StatBoardReponse constructor.
All checks were successful
rock-paper-scissors/pipeline/head This commit looks good
rock-paper-scissors/pipeline/pr-main This commit looks good
2025-11-26 16:58:06 +01:00
Maxime Pierront
ca34df2af9 Refactor test classes: remove redundant public modifiers & update test values. 2025-11-26 16:57:57 +01:00
b451ad2233 Merge pull request 'add-ci' (#5) from add-ci into main
Some checks failed
rock-paper-scissors/pipeline/head There was a failure building this commit
Reviewed-on: #5
2025-11-23 20:07:11 +01:00
8bf1594329 Merge pull request 'add-ci' (#4) from add-ci into main
Some checks failed
rock-paper-scissors/pipeline/head There was a failure building this commit
Reviewed-on: #4
2025-11-23 01:19:53 +01:00
b8c9b382d8 Merge pull request 'Add Jenkinsfile for CI/CD pipeline setup, including build, test, package, and deployment stages.' (#3) from add-ci into main
Some checks failed
rock-paper-scissors/pipeline/head There was a failure building this commit
Reviewed-on: #3
2025-11-23 00:40:16 +01:00
56206c02bb Merge pull request 'Add Jenkinsfile for CI/CD pipeline setup, including build, test, package, and deployment stages.' (#2) from add-ci into main
Reviewed-on: #2
2025-11-23 00:28:21 +01:00
9405b66593 Merge pull request 'Add Jenkinsfile for CI/CD pipeline setup, including build, test, package, and deployment stages.' (#1) from add-ci into main
Reviewed-on: #1
2025-11-23 00:22:12 +01:00
14 changed files with 89 additions and 56 deletions

View File

@@ -3,13 +3,21 @@ 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 Result beats(Move other) {
if(this.equals(other)){
return Result.EQUAL;
}
boolean result = 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 result ? Result.WIN : Result.LOOSE;
}
}

View File

@@ -0,0 +1,8 @@
package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain;
public enum Result {
WIN,
LOOSE,
EQUAL;
}

View File

@@ -9,17 +9,16 @@ import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatSa
@DomainService
public record RockPaperScissorsPlayer(CpuPick cpuPick, StatSave statSave) implements RockPaperScissorsPlay {
public static final String WIN = "WIN";
public static final String LOOSE = "LOOSE";
@Override
public RoundResult playRound(String name, Move move) {
var cpuPicked = this.cpuPick.pick();
boolean beats = move.beats(cpuPicked);
String result = beats ? WIN : LOOSE;
if (result.equals(WIN)) {
Result beats = move.beats(cpuPicked);
if (beats.equals(Result.WIN)) {
this.statSave.addWin(name);
}
return new RoundResult(result, name, cpuPicked);
return new RoundResult(beats.toString(), name, cpuPicked);
}
}

View File

@@ -2,13 +2,16 @@ package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.web;
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatBoard;
import java.util.Comparator;
import java.util.List;
public record StatBoardReponse(List<Stat> stats) {
public StatBoardReponse(StatBoard statBoard) {
this(statBoard.stats().entrySet().stream()
.map(Stat::fromMap)
.toList());
}
public StatBoardReponse(StatBoard statBoard) {
this(statBoard.stats().entrySet().stream()
.map(Stat::fromMap)
.sorted(Comparator.comparingInt(
stat -> -stat.wins()))
.toList());
}
}

View File

@@ -3,7 +3,7 @@ package fr.iut_fbleau.info.but3.automation.rock_paper_scissors;
import org.junit.jupiter.api.Test;
import org.springframework.modulith.core.ApplicationModules;
public class ModulithStructureTests {
class ModulithStructureTests {
@Test
void verifyModularStructure() {

View File

@@ -4,6 +4,7 @@ import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.ddd.DomainService;
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.ddd.Stub;
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.configuration.PlayConfiguration;
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain.Move;
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain.Result;
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain.RockPaperScissorsPlayer;
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.spi.CpuPick;
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.spi.FakeCpuPicker;
@@ -24,8 +25,6 @@ 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 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;
@@ -45,14 +44,14 @@ 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.SCISSORS, Result.WIN),
Arguments.of(Move.ROCK, Move.PAPER, Result.LOOSE)
);
}
@ParameterizedTest
@MethodSource("scenario")
void shouldReturnWinResult_whenPlayerPlaysRock(Move playerMove, Move cpuMove, String expectedResult) throws Exception {
void shouldReturnWinResult_whenPlayerPlaysRock(Move playerMove, Move cpuMove, Result expectedResult) throws Exception {
FakeCpuConfiguration.cpuPick.setNextMove(cpuMove);
mockMvc.perform(
post(PLAY_ENDPOINT)
@@ -64,7 +63,7 @@ public class PlayControllerTest {
""", playerMove))
.contentType(MediaType.APPLICATION_JSON_VALUE)
).andExpect(status().isOk())
.andExpect(jsonPath("$.result").value(expectedResult))
.andExpect(jsonPath("$.result").value(expectedResult.toString()))
.andExpect(jsonPath("$.cpu").value(cpuMove.name()));
}

View File

@@ -26,7 +26,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
webEnvironment = RANDOM_PORT
)
@Import(FakeCpuConfiguration.class)
public class RockPaperScissorsPlayApplicationTest {
class RockPaperScissorsPlayApplicationTest {
@Autowired
private TestRestTemplate restTemplate;

View File

@@ -4,36 +4,50 @@ 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;
import static org.junit.jupiter.api.Assertions.*;
public class MoveTest {
class MoveTest {
@Test
void should_check_move_size(){
Assertions.assertEquals(3, Move.values().length);
Assertions.assertEquals(4, Move.values().length);
}
@ParameterizedTest(name = "{0} should beat {1}")
@MethodSource("winnable")
void should_win(Move move1, Move move2) {
assertTrue(move1.beats(move2));
assertEquals(Result.WIN ,move1.beats(move2));
}
@ParameterizedTest(name = "{1} should not beat {0}")
@MethodSource("winnable")
void should_loose(Move move1, Move move2) {
assertFalse(move2.beats(move1));
assertEquals(Result.LOOSE ,move2.beats(move1));
}
@ParameterizedTest(name = "{0} should be equal {0}")
@EnumSource(Move.class)
void should_equal(Move move) {
assertEquals(Result.EQUAL,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)
);
}
}

View File

@@ -1,17 +1,16 @@
package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.RockPaperScissorsPlay;
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.spi.FakeCpuPicker;
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatSaver;
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.spi.stub.InMemoryStatRepository;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
public class RockPaperScissorsPlayTest {

View File

@@ -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));
}
}

View File

@@ -14,7 +14,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
@ApplicationModuleTest(
webEnvironment = RANDOM_PORT
)
public class StatApplicationTest {
class StatApplicationTest {
@Autowired
private TestRestTemplate restTemplate;
@@ -27,9 +27,9 @@ public class StatApplicationTest {
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(json.from(response.getBody())).extractingJsonPathArrayValue("@.stats").hasSize(2);
assertThat(json.from(response.getBody())).extractingJsonPathStringValue("@.stats[0].name").isEqualTo("joe");
assertThat(json.from(response.getBody())).extractingJsonPathNumberValue("@.stats[0].wins").isEqualTo(1);
assertThat(json.from(response.getBody())).extractingJsonPathStringValue("@.stats[1].name").isEqualTo("eoj");
assertThat(json.from(response.getBody())).extractingJsonPathNumberValue("@.stats[1].wins").isEqualTo(3);
assertThat(json.from(response.getBody())).extractingJsonPathStringValue("@.stats[0].name").isEqualTo("eoj");
assertThat(json.from(response.getBody())).extractingJsonPathNumberValue("@.stats[0].wins").isEqualTo(3);
assertThat(json.from(response.getBody())).extractingJsonPathStringValue("@.stats[1].name").isEqualTo("joe");
assertThat(json.from(response.getBody())).extractingJsonPathNumberValue("@.stats[1].wins").isEqualTo(1);
}
}

View File

@@ -3,6 +3,7 @@ package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat;
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatBoard;
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatBoardGetter;
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.spi.stub.InMemoryStatRepository;
import java.util.LinkedHashMap;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
@@ -10,19 +11,20 @@ import java.util.HashMap;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class StatBoardGetterTest {
@Test
public void should_get_stat_board() {
HashMap<String, Integer> stats = new HashMap<>();
stats.put("joe", 1);
stats.put("eoj", 5);
InMemoryStatRepository statRepository = new InMemoryStatRepository(stats);
class StatBoardGetterTest {
StatBoardGet statBoardGet = new StatBoardGetter(statRepository);
@Test
void should_get_stat_board() {
HashMap<String, Integer> stats = new LinkedHashMap<>();
stats.put("eoj", 5);
stats.put("joe", 1);
InMemoryStatRepository statRepository = new InMemoryStatRepository(stats);
StatBoard statBoard = statBoardGet.board();
StatBoardGet statBoardGet = new StatBoardGetter(statRepository);
assertNotNull(statBoard);
assertEquals(stats, statBoard.stats());
}
StatBoard statBoard = statBoardGet.board();
assertNotNull(statBoard);
assertEquals(stats, statBoard.stats());
}
}

View File

@@ -20,7 +20,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@WebMvcTest(StatController.class)
@Import(StatConfiguration.class)
public class StatControllerTest {
class StatControllerTest {
private static final String STAT_ENDPOINT = "/stat";
@@ -36,8 +36,8 @@ public class StatControllerTest {
mockMvc.perform(get(STAT_ENDPOINT))
.andExpect(status().isOk())
.andExpect(jsonPath("$.stats").isArray())
.andExpect(jsonPath("$.stats[0].name").value("joe"))
.andExpect(jsonPath("$.stats[0].wins").value(1));
.andExpect(jsonPath("$.stats[0].name").value("eoj"))
.andExpect(jsonPath("$.stats[0].wins").value(3));
}
@TestConfiguration

View File

@@ -10,7 +10,7 @@ import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class StatSaverTest {
class StatSaverTest {
@ParameterizedTest(name = "name = {0}, initial = {1}, expected = {2}")
@CsvSource({"joe,0,1", "eoj,2,3"})
void should_save(String name, int initial, int expected) {