Cards are now cards.
This commit is contained in:
parent
ce78f1b179
commit
7ebea34f12
6
pom.xml
6
pom.xml
@ -27,6 +27,12 @@
|
|||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<version>RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
23
src/main/java/fr/aminelouveaau/cartes/model/Card.java
Normal file
23
src/main/java/fr/aminelouveaau/cartes/model/Card.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package fr.aminelouveaau.cartes.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
public class Card {
|
||||||
|
private final Shape shape;
|
||||||
|
private final Number number;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public Card(@JsonProperty("shape") Shape shape, @JsonProperty("number") Number number) {
|
||||||
|
this.shape = shape;
|
||||||
|
this.number = number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Shape getShape() {
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Number getNumber() {
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
package fr.aminelouveaau.cartes.service;
|
package fr.aminelouveaau.cartes.service;
|
||||||
|
|
||||||
|
import fr.aminelouveaau.cartes.model.Card;
|
||||||
import fr.aminelouveaau.cartes.model.Number;
|
import fr.aminelouveaau.cartes.model.Number;
|
||||||
import fr.aminelouveaau.cartes.model.Shape;
|
import fr.aminelouveaau.cartes.model.Shape;
|
||||||
import javafx.util.Pair;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ public class GameService {
|
|||||||
private List<Shape> shapeOrder;
|
private List<Shape> shapeOrder;
|
||||||
private List<Number> numberOrder;
|
private List<Number> numberOrder;
|
||||||
|
|
||||||
private List<Pair<Shape, Number>> deck = new ArrayList<>();
|
private Stack<Card> deck = new Stack<>();
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
@ -33,14 +33,14 @@ public class GameService {
|
|||||||
return numberOrder;
|
return numberOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Pair<Shape, Number>> getDeck() {
|
public List<Card> getDeck() {
|
||||||
return deck;
|
return deck;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createDeck() {
|
private void createDeck() {
|
||||||
Arrays.stream(Shape.values()).forEach(shape -> {
|
Arrays.stream(Shape.values()).forEach(shape -> {
|
||||||
Arrays.stream(Number.values()).forEach(number -> {
|
Arrays.stream(Number.values()).forEach(number -> {
|
||||||
deck.add(new Pair<>(shape, number));
|
deck.push(new Card(shape, number));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Collections.shuffle(deck);
|
Collections.shuffle(deck);
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package fr.aminelouveaau.cartes;
|
package fr.aminelouveaau.cartes;
|
||||||
|
|
||||||
import fr.aminelouveaau.cartes.model.Number;
|
import fr.aminelouveaau.cartes.model.Card;
|
||||||
import fr.aminelouveaau.cartes.model.Shape;
|
|
||||||
import fr.aminelouveaau.cartes.service.GameService;
|
import fr.aminelouveaau.cartes.service.GameService;
|
||||||
import javafx.util.Pair;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
@ -17,18 +15,19 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
|||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class CartesApplicationTests {
|
class CartesApplicationTests {
|
||||||
|
|
||||||
|
public static final int CARDS_PER_HAND = 10;
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
GameService gameService;
|
GameService gameService;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
ReflectionTestUtils.setField(gameService, "cardHandNumber", 10);
|
ReflectionTestUtils.setField(gameService, "cardHandNumber", CARDS_PER_HAND);
|
||||||
gameService.init();
|
gameService.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDeckGeneration() {
|
void testDeckGeneration() {
|
||||||
List<Pair<Shape, Number>> deck = gameService.getDeck();
|
List<Card> deck = gameService.getDeck();
|
||||||
assertThat(deck.size()).isNotEqualTo(0).withFailMessage("Deck is empty");
|
assertThat(deck.size()).isNotEqualTo(0).withFailMessage("Deck is empty");
|
||||||
assertThat(deck.size()).isEqualTo(4 * 13).withFailMessage("Deck is not complete");
|
assertThat(deck.size()).isEqualTo(4 * 13).withFailMessage("Deck is not complete");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user