mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-02-01 07:39:35 +01:00
lagde flere tester i PlayerDeckTest
This commit is contained in:
parent
f2a29a2b08
commit
42726b5e78
@ -29,12 +29,12 @@ public abstract class Deck<T> implements IDeck<T> {
|
|||||||
Random randomNumber = new Random();
|
Random randomNumber = new Random();
|
||||||
|
|
||||||
for (int i = cardDeck.size() - 1; i > 0; i--) {
|
for (int i = cardDeck.size() - 1; i > 0; i--) {
|
||||||
int index = randomNumber.nextInt(i);
|
int randomIndex = randomNumber.nextInt(i);
|
||||||
|
|
||||||
T CardIndex = cardDeck.get(index);
|
T CardRandomIndex = cardDeck.get(randomIndex);
|
||||||
cardDeck.add(index, cardDeck.get(i));
|
cardDeck.add(randomIndex, cardDeck.get(i));
|
||||||
cardDeck.remove(index+1);
|
cardDeck.remove(randomIndex+1);
|
||||||
cardDeck.add(i, CardIndex);
|
cardDeck.add(i, CardRandomIndex);
|
||||||
cardDeck.remove(i+1);
|
cardDeck.remove(i+1);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -77,7 +77,8 @@ public abstract class Deck<T> implements IDeck<T> {
|
|||||||
@Override
|
@Override
|
||||||
public void emptyInto(IDeck<T> other) {
|
public void emptyInto(IDeck<T> other) {
|
||||||
Deck<T> otherDeck = (Deck) other;
|
Deck<T> otherDeck = (Deck) other;
|
||||||
for (int i=0; i<otherDeck.size();i++){
|
int size = otherDeck.size();
|
||||||
|
for (int i=0; i<size;i++){
|
||||||
otherDeck.draw(this);
|
otherDeck.draw(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,11 +108,7 @@ public abstract class Deck<T> implements IDeck<T> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<T> getCards() {
|
public List<T> getCards() {
|
||||||
ArrayList<T> returnDeck = new ArrayList();
|
return cardDeck;
|
||||||
for (int i=0;i<cardDeck.size();i++){
|
|
||||||
returnDeck.add(cardDeck.get(i));
|
|
||||||
}
|
|
||||||
return returnDeck;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,12 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class PlayerDeck<ProgrammingCard> extends Deck<ProgrammingCard> {
|
public class PlayerDeck<ProgrammingCard> extends Deck<ProgrammingCard> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initalizes the PlayerDeck with a list of cards
|
||||||
|
* @param cardlist list of programing cards
|
||||||
|
*/
|
||||||
public PlayerDeck(ArrayList<ProgrammingCard> cardlist) {
|
public PlayerDeck(ArrayList<ProgrammingCard> cardlist) {
|
||||||
super(cardlist);
|
super(cardlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,12 @@ public class TestPlayerDeck {
|
|||||||
testDeck2 = new PlayerDeck(cardlist2);
|
testDeck2 = new PlayerDeck(cardlist2);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
|
public void testSize(){
|
||||||
|
assertEquals(3,testDeck.size());
|
||||||
|
testDeck.emptyInto(testDeck2);
|
||||||
|
assertEquals(0,testDeck.size());
|
||||||
|
}
|
||||||
|
@Test
|
||||||
public void testDrawCard(){
|
public void testDrawCard(){
|
||||||
assertEquals(3,testDeck.size());
|
assertEquals(3,testDeck.size());
|
||||||
assertEquals(3,testDeck2.size());
|
assertEquals(3,testDeck2.size());
|
||||||
@ -37,6 +43,67 @@ public class TestPlayerDeck {
|
|||||||
assertEquals(4,testDeck.size());
|
assertEquals(4,testDeck.size());
|
||||||
assertEquals(2,testDeck2.size());
|
assertEquals(2,testDeck2.size());
|
||||||
}
|
}
|
||||||
|
@Test
|
||||||
|
public void testDrawMultipulCards(){
|
||||||
|
assertEquals(3,testDeck.size());
|
||||||
|
assertEquals(3,testDeck2.size());
|
||||||
|
testDeck.draw(testDeck2, 3);
|
||||||
|
assertEquals(6,testDeck.size());
|
||||||
|
assertEquals(0,testDeck2.size());
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testEmptyInto(){
|
||||||
|
assertEquals(3,testDeck.size());
|
||||||
|
assertEquals(3,testDeck2.size());
|
||||||
|
testDeck.emptyInto(testDeck2);
|
||||||
|
assertEquals(0,testDeck.size());
|
||||||
|
assertEquals(6,testDeck2.size());
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testIsEmpty(){
|
||||||
|
assertEquals(false,testDeck.isEmpty());
|
||||||
|
testDeck.emptyInto(testDeck2);
|
||||||
|
assertEquals(true,testDeck.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCards(){
|
||||||
|
testDeck2.emptyInto(testDeck);
|
||||||
|
assertEquals(programmingCard1,testDeck.getCards().get(0));
|
||||||
|
assertEquals(programmingCard3,testDeck.getCards().get(2));
|
||||||
|
assertEquals(programmingCard6,testDeck.getCards().get(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testshuffle(){
|
||||||
|
ProgrammingCard card1 =(ProgrammingCard) testDeck.getCards().get(0);
|
||||||
|
int noe = card1.getValue();
|
||||||
|
ProgrammingCard card2 =(ProgrammingCard) testDeck.getCards().get(1);
|
||||||
|
int noe2 = card2.getValue();
|
||||||
|
ProgrammingCard card3 =(ProgrammingCard) testDeck.getCards().get(2);
|
||||||
|
int noe3 = card3.getValue();
|
||||||
|
|
||||||
|
System.out.println(noe);
|
||||||
|
System.out.println(noe2);
|
||||||
|
System.out.println(noe3);
|
||||||
|
|
||||||
|
testDeck.shuffle();
|
||||||
|
|
||||||
|
ProgrammingCard scard1 =(ProgrammingCard) testDeck.getCards().get(0);
|
||||||
|
int snoe = scard1.getValue();
|
||||||
|
ProgrammingCard scard2 =(ProgrammingCard) testDeck.getCards().get(1);
|
||||||
|
int snoe2 = scard2.getValue();
|
||||||
|
ProgrammingCard scard3 =(ProgrammingCard) 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