1 Commits

Author SHA1 Message Date
bfb5985d9a Merge pull request 'feature: add well' (#1) from feature-well into main
All checks were successful
rock-paper-cissors/pipeline/head This commit looks good
Reviewed-on: #1
2025-11-27 11:21:43 +01:00
6 changed files with 8 additions and 37 deletions

View File

@@ -1,7 +0,0 @@
package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain;
public enum GameResult {
WIN,
LOOSE,
TIE,
}

View File

@@ -6,15 +6,12 @@ public enum Move {
SCISSORS,
WELL;
public GameResult beats(Move other) {
if (this.equals(other))
return GameResult.TIE;
boolean beats = switch (this) {
public boolean beats(Move other) {
return switch (this) {
case ROCK -> other == SCISSORS;
case PAPER -> other == ROCK || other == WELL;
case SCISSORS -> other == PAPER;
case WELL -> other == ROCK || other == SCISSORS;
};
return beats ? GameResult.WIN : GameResult.LOOSE;
}
}

View File

@@ -11,14 +11,12 @@ 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();
GameResult beats = move.beats(cpuPicked);
String result = String.valueOf(beats);
boolean beats = move.beats(cpuPicked);
String result = beats ? WIN : LOOSE;
if (result.equals(WIN)) {
this.statSave.addWin(name);
}

View File

@@ -24,7 +24,8 @@ 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.*;
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,8 +46,7 @@ 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.ROCK, TIE)
Arguments.of(Move.ROCK, Move.PAPER, LOOSE)
);
}
@@ -67,4 +67,5 @@ public class PlayControllerTest {
.andExpect(jsonPath("$.result").value(expectedResult))
.andExpect(jsonPath("$.cpu").value(cpuMove.name()));
}
}

View File

@@ -4,7 +4,6 @@ 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;
@@ -18,9 +17,6 @@ class MoveTest {
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) {
@@ -33,12 +29,6 @@ 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),

View File

@@ -39,12 +39,4 @@ 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());
}
}