lagde flere tester i PlayerDeckTest

This commit is contained in:
Petter Tobias Madsen 2020-03-03 15:25:39 +01:00
parent f2a29a2b08
commit 42726b5e78
3 changed files with 80 additions and 11 deletions

View File

@ -29,12 +29,12 @@ public abstract class Deck<T> implements IDeck<T> {
Random randomNumber = new Random();
for (int i = cardDeck.size() - 1; i > 0; i--) {
int index = randomNumber.nextInt(i);
int randomIndex = randomNumber.nextInt(i);
T CardIndex = cardDeck.get(index);
cardDeck.add(index, cardDeck.get(i));
cardDeck.remove(index+1);
cardDeck.add(i, CardIndex);
T CardRandomIndex = cardDeck.get(randomIndex);
cardDeck.add(randomIndex, cardDeck.get(i));
cardDeck.remove(randomIndex+1);
cardDeck.add(i, CardRandomIndex);
cardDeck.remove(i+1);
}
@ -77,7 +77,8 @@ public abstract class Deck<T> implements IDeck<T> {
@Override
public void emptyInto(IDeck<T> 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);
}
@ -107,11 +108,7 @@ public abstract class Deck<T> implements IDeck<T> {
*/
@Override
public List<T> getCards() {
ArrayList<T> returnDeck = new ArrayList();
for (int i=0;i<cardDeck.size();i++){
returnDeck.add(cardDeck.get(i));
}
return returnDeck;
return cardDeck;
}

View File

@ -4,7 +4,12 @@ import java.util.ArrayList;
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) {
super(cardlist);
}
}

View File

@ -30,6 +30,12 @@ public class TestPlayerDeck {
testDeck2 = new PlayerDeck(cardlist2);
}
@Test
public void testSize(){
assertEquals(3,testDeck.size());
testDeck.emptyInto(testDeck2);
assertEquals(0,testDeck.size());
}
@Test
public void testDrawCard(){
assertEquals(3,testDeck.size());
assertEquals(3,testDeck2.size());
@ -37,6 +43,67 @@ public class TestPlayerDeck {
assertEquals(4,testDeck.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);
}
}