Skip to content
Snippets Groups Projects
Commit 5b383606 authored by Torbjørn Antonsen's avatar Torbjørn Antonsen
Browse files

Added test methods for methods in project

parent cfa0dea6
Branches feat/test-class
No related tags found
1 merge request!8Added test methods for methods in project
...@@ -11,10 +11,6 @@ public class HandOfCards { ...@@ -11,10 +11,6 @@ public class HandOfCards {
this.hand = new ArrayList<>(); this.hand = new ArrayList<>();
} }
public int getSize() {
return this.hand.size();
}
public List<PlayingCard> getHand() { public List<PlayingCard> getHand() {
return this.hand; return this.hand;
} }
......
package edu.ntnu.idatt2001;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@Nested
class HandOfCardsTest {
private HandOfCards testHandOfCards;
@BeforeEach
public void setUp() {
this.testHandOfCards = new HandOfCards();
List<PlayingCard> hand = new ArrayList<>();
PlayingCard playingCard;
for (int i = 0; i < 5; i++) {
playingCard = new PlayingCard('C', 1);
hand.add(playingCard);
}
testHandOfCards.setHand(hand);
}
@Test
public void getSumOfFacesTest() {
Assertions.assertNotNull(testHandOfCards.getHand());
Assertions.assertEquals(5, testHandOfCards.getSumOfFaces());
}
@Test
public void getCardsOfHeartsNegativeTest() {
Assertions.assertNotNull(testHandOfCards.getHand());
Assertions.assertEquals(0, testHandOfCards.getCardsOfHearts().size());
}
@Test
public void getCardsOfHeartsPositiveTest() {
List<PlayingCard> hand = new ArrayList<>();
PlayingCard playingCard;
for (int i = 0; i < 5; i++) {
playingCard = new PlayingCard('H', 1);
hand.add(playingCard);
}
testHandOfCards.setHand(hand);
Assertions.assertEquals(5, testHandOfCards.getCardsOfHearts().size());
}
@Test
public void anyQueenOfSpadesNegativeTest() {
Assertions.assertFalse(testHandOfCards.anyQueenOfSpades());
}
@Test
public void anyQueenOfSpadesPositiveTest() {
List<PlayingCard> hand = new ArrayList<>();
PlayingCard playingCard;
for (int i = 0; i < 5; i++) {
playingCard = new PlayingCard('S', 12);
hand.add(playingCard);
}
testHandOfCards.setHand(hand);
Assertions.assertTrue(testHandOfCards.anyQueenOfSpades());
}
@Test
public void isFlushPositiveTest() {
Assertions.assertTrue( testHandOfCards.isFlush());
}
@Test
public void isFlushNegativeTest() {
List<PlayingCard> hand = new ArrayList<>();
PlayingCard playingCard;
for (int i = 0; i < 4; i++) {
playingCard = new PlayingCard('S', 12);
hand.add(playingCard);
}
playingCard = new PlayingCard('D', 12);
hand.add(playingCard);
testHandOfCards.setHand(hand);
Assertions.assertFalse(testHandOfCards.isFlush());
}
}
\ No newline at end of file
package edu.ntnu.idatt2001;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
@Nested
class PlayingCardTest {
private PlayingCard testPlayingCard;
@BeforeEach
public void setUp() {
this.testPlayingCard = new PlayingCard('C', 1);
}
@Test
public void getSuitTest() {
Assertions.assertEquals('C', testPlayingCard.getSuit());
}
@Test
public void getFaceTest() {
Assertions.assertEquals(1, testPlayingCard.getFace());
}
@Test
public void getAsStringTest() {
Assertions.assertEquals("C1", testPlayingCard.getAsString());
}
@Test
public void getImagePathTest() {
Assertions.assertEquals("cardImages/01C.png", testPlayingCard.getImagePath());
}
}
\ No newline at end of file
No preview for this file type
No preview for this file type
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment