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>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<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;
|
||||
|
||||
import fr.aminelouveaau.cartes.model.Card;
|
||||
import fr.aminelouveaau.cartes.model.Number;
|
||||
import fr.aminelouveaau.cartes.model.Shape;
|
||||
import javafx.util.Pair;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -17,7 +17,7 @@ public class GameService {
|
||||
private List<Shape> shapeOrder;
|
||||
private List<Number> numberOrder;
|
||||
|
||||
private List<Pair<Shape, Number>> deck = new ArrayList<>();
|
||||
private Stack<Card> deck = new Stack<>();
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
@ -33,14 +33,14 @@ public class GameService {
|
||||
return numberOrder;
|
||||
}
|
||||
|
||||
public List<Pair<Shape, Number>> getDeck() {
|
||||
public List<Card> getDeck() {
|
||||
return deck;
|
||||
}
|
||||
|
||||
private void createDeck() {
|
||||
Arrays.stream(Shape.values()).forEach(shape -> {
|
||||
Arrays.stream(Number.values()).forEach(number -> {
|
||||
deck.add(new Pair<>(shape, number));
|
||||
deck.push(new Card(shape, number));
|
||||
});
|
||||
});
|
||||
Collections.shuffle(deck);
|
||||
|
@ -1,9 +1,7 @@
|
||||
package fr.aminelouveaau.cartes;
|
||||
|
||||
import fr.aminelouveaau.cartes.model.Number;
|
||||
import fr.aminelouveaau.cartes.model.Shape;
|
||||
import fr.aminelouveaau.cartes.model.Card;
|
||||
import fr.aminelouveaau.cartes.service.GameService;
|
||||
import javafx.util.Pair;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
@ -17,18 +15,19 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
@SpringBootTest
|
||||
class CartesApplicationTests {
|
||||
|
||||
public static final int CARDS_PER_HAND = 10;
|
||||
@InjectMocks
|
||||
GameService gameService;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
ReflectionTestUtils.setField(gameService, "cardHandNumber", 10);
|
||||
ReflectionTestUtils.setField(gameService, "cardHandNumber", CARDS_PER_HAND);
|
||||
gameService.init();
|
||||
}
|
||||
|
||||
@Test
|
||||
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()).isEqualTo(4 * 13).withFailMessage("Deck is not complete");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user