mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-02-07 18:49:34 +01:00
Legger til funksjonalitet for å kikke på det første eller siste kortet i en kortstokk
This commit is contained in:
parent
1c1bbc6a79
commit
7a5b4fccd2
@ -77,5 +77,15 @@ public abstract class Deck<T> implements IDeck<T> {
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T peekTop() {
|
||||
return cardList.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T peekBottom() {
|
||||
return cardList.get(size()-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,9 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Describes a deck
|
||||
*
|
||||
* Any card stored in the deck is assumed to be immutable. If it's not, the integrity of the deck cannot be
|
||||
* guaranteed.
|
||||
*/
|
||||
public interface IDeck <T> {
|
||||
|
||||
@ -43,11 +46,22 @@ public interface IDeck <T> {
|
||||
*/
|
||||
int size();
|
||||
|
||||
/**
|
||||
* Takes a peek at the card currently at the top of the deck
|
||||
* @return The card at the top of the deck
|
||||
*/
|
||||
T peekTop();
|
||||
|
||||
/**
|
||||
* Takes a peek at the card currently at the bottom of the deck
|
||||
* @return The card at the bottom of the deck
|
||||
*/
|
||||
T peekBottom();
|
||||
|
||||
/**
|
||||
* Gets a list of all cards in this deck
|
||||
*
|
||||
* The list should have the correct order according to the actual order within the deck. As an ICardWithoutSuit is
|
||||
* immutable, the object reference can be returned directly.
|
||||
* The list should have the correct order according to the actual order within the deck.
|
||||
*
|
||||
* @return A list of all cards in this deck
|
||||
*/
|
||||
|
@ -113,4 +113,14 @@ public class ProgrammingCardDeckTest {
|
||||
assertTrue(fullDeck.getCards().contains(card));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void peekTop() {
|
||||
assertEquals(programmingCard1, testDeck.peekTop());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void peekBottom() {
|
||||
assertEquals(programmingCard3, testDeck.peekBottom());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user