Skip to content
Snippets Groups Projects
Commit 62be3839 authored by Sander Rusten Berge's avatar Sander Rusten Berge
Browse files

Added test classes

parent b1d25922
No related branches found
No related tags found
No related merge requests found
package com.example;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
public class testDeckOfCards {
private DeckOfCards deck;
@Before
public void setUp() {
deck = new DeckOfCards();
}
@Test
public void testDealHand() {
List<PlayingCard> hand = deck.dealHand(5);
assertEquals("Dealt hand should contain 5 cards", 5, hand.size());
assertEquals("Deck should have 47 cards remaining after dealing 5 cards", 47, deck.cardsRemaining());
}
@Test(expected = IllegalStateException.class)
public void testDealHandNotEnoughCards() {
// Ensure dealing more cards than available throws IllegalStateException
deck.dealHand(60);
}
@Test
public void testResetDeck() {
deck.dealHand(10); // Deal some cards
deck.resetDeck();
assertEquals("Reset deck should have 52 cards", 52, deck.cardsRemaining());
}
@Test
public void testCardsRemaining() {
assertEquals("Newly created deck should have 52 cards", 52, deck.cardsRemaining());
deck.dealHand(10);
assertEquals("After dealing 10 cards, deck should have 42 cards remaining", 42, deck.cardsRemaining());
deck.resetDeck();
assertEquals("After resetting the deck, it should have 52 cards again", 52, deck.cardsRemaining());
}
}
package com.example;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
public class testHandOfCards {
private HandOfCards hand;
@Before
public void setUp() {
List<PlayingCard> cards = Arrays.asList(
new PlayingCard('S', 1),
new PlayingCard('S', 2),
new PlayingCard('S', 3),
new PlayingCard('S', 4),
new PlayingCard('S', 5)
);
hand = new HandOfCards(cards);
}
@Test
public void testHasFlush() {
assertTrue("Hand should have a flush", hand.hasFlush());
}
@Test
public void testSumOfFaces() {
assertEquals("Sum of face values should be 15", 15, hand.sumOfFaces());
}
@Test
public void testHasCard() {
assertTrue("Hand should have card '2S'", hand.hasCard('S', 2));
assertFalse("Hand should not have card '6S'", hand.hasCard('S', 6));
}
}
package com.example;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class testPlayingCard {
@Test
public void testGetSuit() {
PlayingCard card = new PlayingCard('S', 5);
assertEquals("Suit should be 'S'", 'S', card.getSuit());
}
@Test
public void testGetValue() {
PlayingCard card = new PlayingCard('S', 5);
assertEquals("Value should be 5", 5, card.getValue());
}
@Test
public void testToString() {
PlayingCard card = new PlayingCard('S', 5);
assertEquals("String representation should be 'S5'", "S5", card.toString());
}
}
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment