mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-02-01 07:39:35 +01:00
Fikser en del småfeil i Deck, ProgrammingCardDeck og tester
This commit is contained in:
parent
9f7ebb59b1
commit
315cbb2590
@ -8,13 +8,13 @@ import java.util.Random;
|
|||||||
* This class represents a deck of cards
|
* This class represents a deck of cards
|
||||||
*/
|
*/
|
||||||
public abstract class Deck<T> implements IDeck<T> {
|
public abstract class Deck<T> implements IDeck<T> {
|
||||||
private final ArrayList<T> cardList;
|
private final List<T> cardList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the deck with cards
|
* Initializes the deck with cards
|
||||||
* @param cardList list of cards
|
* @param cardList list of cards
|
||||||
*/
|
*/
|
||||||
public Deck (ArrayList<T> cardList) {
|
public Deck (List<T> cardList) {
|
||||||
this.cardList = new ArrayList<>(cardList);
|
this.cardList = new ArrayList<>(cardList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,5 +68,14 @@ public abstract class Deck<T> implements IDeck<T> {
|
|||||||
public List<T> getCards() {
|
public List<T> getCards() {
|
||||||
return new ArrayList<>(cardList);
|
return new ArrayList<>(cardList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for (T card : cardList) {
|
||||||
|
builder.append(card.toString()).append("\n");
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package inf112.fiasko.roborally.objects;
|
package inf112.fiasko.roborally.objects;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a deck containing programming cards
|
* This class represents a deck containing programming cards
|
||||||
@ -11,7 +11,7 @@ public class ProgrammingCardDeck extends Deck<ProgrammingCard> {
|
|||||||
* Initializes the PlayerDeck with a list of cards
|
* Initializes the PlayerDeck with a list of cards
|
||||||
* @param cardList list of programing cards
|
* @param cardList list of programing cards
|
||||||
*/
|
*/
|
||||||
public ProgrammingCardDeck(ArrayList<ProgrammingCard> cardList) {
|
public ProgrammingCardDeck(List<ProgrammingCard> cardList) {
|
||||||
super(cardList);
|
super(cardList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
package inf112.fiasko.roborally.objects;
|
package inf112.fiasko.roborally.objects;
|
||||||
|
|
||||||
import inf112.fiasko.roborally.element_properties.Action;
|
import inf112.fiasko.roborally.element_properties.Action;
|
||||||
|
import inf112.fiasko.roborally.utility.DeckLoaderUtil;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class TestProgrammingCardDeck {
|
public class ProgrammingCardDeckTest {
|
||||||
|
private ProgrammingCardDeck fullDeck;
|
||||||
private final ProgrammingCard programmingCard1 = new ProgrammingCard(5, Action.MOVE_1);
|
private final ProgrammingCard programmingCard1 = new ProgrammingCard(5, Action.MOVE_1);
|
||||||
private final ProgrammingCard programmingCard2 = new ProgrammingCard(6, Action.MOVE_2);
|
private final ProgrammingCard programmingCard2 = new ProgrammingCard(6, Action.MOVE_2);
|
||||||
private final ProgrammingCard programmingCard3 = new ProgrammingCard(7, Action.MOVE_3);
|
private final ProgrammingCard programmingCard3 = new ProgrammingCard(7, Action.MOVE_3);
|
||||||
@ -22,6 +25,11 @@ public class TestProgrammingCardDeck {
|
|||||||
private ProgrammingCardDeck testDeck2;
|
private ProgrammingCardDeck testDeck2;
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
try {
|
||||||
|
fullDeck = DeckLoaderUtil.loadProgrammingCardsDeck();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
cardlist.add(programmingCard1);
|
cardlist.add(programmingCard1);
|
||||||
cardlist.add(programmingCard2);
|
cardlist.add(programmingCard2);
|
||||||
cardlist.add(programmingCard3);
|
cardlist.add(programmingCard3);
|
||||||
@ -46,7 +54,7 @@ public class TestProgrammingCardDeck {
|
|||||||
assertEquals(2,testDeck2.size());
|
assertEquals(2,testDeck2.size());
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testDrawMultipulCards(){
|
public void testDrawMultipleCards() {
|
||||||
assertEquals(3, testDeck.size());
|
assertEquals(3, testDeck.size());
|
||||||
assertEquals(3, testDeck2.size());
|
assertEquals(3, testDeck2.size());
|
||||||
testDeck.draw(testDeck2, 3);
|
testDeck.draw(testDeck2, 3);
|
||||||
@ -77,29 +85,9 @@ public class TestProgrammingCardDeck {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testshuffle(){
|
public void testShuffle() {
|
||||||
ProgrammingCard card1 = testDeck.getCards().get(0);
|
System.out.print(fullDeck.toString());
|
||||||
int noe = card1.getValue();
|
fullDeck.shuffle();
|
||||||
ProgrammingCard card2 = testDeck.getCards().get(1);
|
System.out.print(fullDeck.toString());
|
||||||
int noe2 = card2.getValue();
|
|
||||||
ProgrammingCard card3 = testDeck.getCards().get(2);
|
|
||||||
int noe3 = card3.getValue();
|
|
||||||
|
|
||||||
System.out.println(noe);
|
|
||||||
System.out.println(noe2);
|
|
||||||
System.out.println(noe3);
|
|
||||||
|
|
||||||
testDeck.shuffle();
|
|
||||||
|
|
||||||
ProgrammingCard scard1 = testDeck.getCards().get(0);
|
|
||||||
int snoe = scard1.getValue();
|
|
||||||
ProgrammingCard scard2 = testDeck.getCards().get(1);
|
|
||||||
int snoe2 = scard2.getValue();
|
|
||||||
ProgrammingCard scard3 = testDeck.getCards().get(2);
|
|
||||||
int snoe3 = scard3.getValue();
|
|
||||||
|
|
||||||
System.out.println(snoe);
|
|
||||||
System.out.println(snoe2);
|
|
||||||
System.out.println(snoe3);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user