Every card is unique.
This commit is contained in:
parent
1e29bd41e9
commit
1a20205bfc
@ -48,6 +48,7 @@ public class GameService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void createDeck() {
|
public void createDeck() {
|
||||||
|
deck = new Stack<>();
|
||||||
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.push(new Card(shape, number));
|
deck.push(new Card(shape, number));
|
||||||
@ -72,6 +73,7 @@ public class GameService {
|
|||||||
for (int i = 0; i < this.cardHandNumber; i++) {
|
for (int i = 0; i < this.cardHandNumber; i++) {
|
||||||
hand.add(this.deck.pop());
|
hand.add(this.deck.pop());
|
||||||
}
|
}
|
||||||
|
logger.info("Hand : " + hand);
|
||||||
return hand;
|
return hand;
|
||||||
} else {
|
} else {
|
||||||
throw new HttpClientErrorException(HttpStatus.TOO_MANY_REQUESTS);
|
throw new HttpClientErrorException(HttpStatus.TOO_MANY_REQUESTS);
|
||||||
|
@ -11,6 +11,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
|||||||
import org.springframework.web.client.HttpClientErrorException;
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||||
|
|
||||||
@ -47,15 +48,23 @@ class CartesApplicationTests {
|
|||||||
|
|
||||||
@Test()
|
@Test()
|
||||||
void testExceptionTooManyPlayers() {
|
void testExceptionTooManyPlayers() {
|
||||||
int maxNumberOfPlayers = (int) Math.floor(DECK_SIZE / CARDS_PER_HAND);
|
for (int i = 0; i < getMaxNumberOfPlayers(); i++) {
|
||||||
for (int i = 0; i < maxNumberOfPlayers; i++) {
|
|
||||||
gameService.cardHand();
|
gameService.cardHand();
|
||||||
}
|
}
|
||||||
Assertions.assertThrows(HttpClientErrorException.class, () -> gameService.cardHand());
|
Assertions.assertThrows(HttpClientErrorException.class, () -> gameService.cardHand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getMaxNumberOfPlayers() {
|
||||||
|
int maxNumberOfPlayers = (int) Math.floor(DECK_SIZE / CARDS_PER_HAND);
|
||||||
|
return maxNumberOfPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void contextLoads() {
|
void isAllUniqueCards() {
|
||||||
|
for (int i = 0; i < getMaxNumberOfPlayers(); i++) {
|
||||||
|
List<Card> hand = gameService.cardHand().stream().distinct().collect(Collectors.toList());
|
||||||
|
assertThat(hand.size()).isEqualTo(CARDS_PER_HAND);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user