Skip to content
Snippets Groups Projects
Commit 02fd45a2 authored by Jedrzej Frankowski-Wodzikowska's avatar Jedrzej Frankowski-Wodzikowska
Browse files

Added Streams and Test Classes to the application

parent 66655985
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,8 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
......
import no.ntnu.idatg2001.PlayingCard;
public class CardGameApplication {
public static void main(String[] args) {
}
}
......@@ -4,13 +4,13 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.stream.IntStream;
public class DeckOfCards {
private final char[] suits = {'C', 'D', 'S', 'H'};
private PlayingCard[] deck;
private int cardsUsed;
private ArrayList<PlayingCard> hand;
public DeckOfCards() {
deck = new PlayingCard[52];
......@@ -23,54 +23,13 @@ public class DeckOfCards {
cardsUsed=0;
}
public List<PlayingCard> dealHand(int numberOfCardsUsed) {
ArrayList<PlayingCard> hand = new ArrayList<>();
public List<PlayingCard> dealHand(int cardsUsed) {
Random random = new Random();
for(int i = 0; i == numberOfCardsUsed; i++){
for(int i = 0; i == cardsUsed; i++){
int randInt = random.nextInt();
hand.add(deck[randInt]);
}
return hand;
}
public int sumOfHand() {
ArrayList<PlayingCard> hand = new ArrayList<>();
int sum = 0;
for(PlayingCard playingCard: hand) {
}
return sum;
}
public List<PlayingCard> getCardsOfHearts() {
ArrayList<PlayingCard> hand = new ArrayList<>();
ArrayList<PlayingCard> cardsOfSuit = new ArrayList<PlayingCard>();
for(PlayingCard playingCard: hand) {
if(playingCard.getSuit() == 'H') {
hand.add(playingCard);
}
}
return cardsOfSuit;
}
public boolean checkQueenOfSpades() {
ArrayList<PlayingCard> hand = new ArrayList<>();
boolean checkQueenOfSpades = false;
for(PlayingCard playingCard: hand) {
if()
}
}
public boolean checkFlush() {
ArrayList<PlayingCard> hand = new ArrayList<>();
boolean checkFlush = false;
for(PlayingCard playingCard: hand) {
playingCard.getSuit();
}
return checkFlush;
}
}
\ No newline at end of file
package no.ntnu.idatg2001;
import java.util.ArrayList;
import java.util.List;
public class HandOfCards {
private ArrayList<PlayingCard> cards;
public HandOfCards(ArrayList cards) {
this.cards = cards;
}
public int getHandSize() {
return cards.size();
}
public int sumOfCards() {
return cards.stream().map(playingCard -> playingCard.getFace()).reduce(0, (total, face) -> total + face);
}
public String getCardsOfHeart() {
return cards.stream()
.filter(playingCard -> playingCard.getSuit()=='H')
.map(playingCard -> playingCard.getAsString())
.reduce("No Hearts", (total, string) -> string);
}
public boolean checkQueenOfSpades() {
return cards.stream().anyMatch(playingCard -> playingCard.getAsString().equals("S12"));
}
public boolean checkForFlush() {
return cards.stream().allMatch(playingCard -> playingCard.getSuit()=='S');
}
}
package no.ntnu.idatg2001;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class DeckOfCardsTest {
@BeforeEach
void setUp() {
}
@Test
void testDealHand() {
}
}
\ No newline at end of file
package no.ntnu.idatg2001;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.*;
class HandOfCardsTest {
HandOfCards handOfCards;
ArrayList<PlayingCard> cards = new ArrayList<>();
@BeforeEach
void setUp() {
this.handOfCards = new HandOfCards(cards);
PlayingCard playingCard = new PlayingCard('H', 8);
cards.add(playingCard);
PlayingCard playingCard1 = new PlayingCard('S', 12);
cards.add(playingCard1);
}
@Test
void testSumOfCards() {
assertEquals(20, handOfCards.sumOfCards());
}
@Test
void testGetCardsOfHeart() {
assertEquals("H8", handOfCards.getCardsOfHeart());
}
@Test
void testCheckQueenOfSpades() {
assertEquals(true, handOfCards.checkQueenOfSpades());
}
}
\ No newline at end of file
package no.ntnu.idatg2001;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class PlayingCardTest {
PlayingCard playingCard;
@BeforeEach
void setUp() {this.playingCard = new PlayingCard('S', 10);}
@Test
void testGetSuit() {
assertEquals('S', playingCard.getSuit());
}
@Test
void testGetFace() {
assertEquals(10, playingCard.getFace());
}
@Test
void testGetAsString() {
assertEquals("S10", playingCard.getAsString());
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment