Package hand

Source Code of hand.TestHand

package hand;
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Arrays;

import game.Card;
import game.Deck;

import org.junit.Before;
import org.junit.Test;
/**
* Test all functionality for hand
* @author TJ Renninger
*
*/
public class TestHand
{

  private Hand hand;
 
  /**
   * Create a new hand before each test
   */
  @Before
  public void setUp()
  {
    hand = new Hand(10);
    Deck.getInstance().reset();
  }
 
  /**
   * Test to make sure a hand can be made and it knows is starting size and current size
   */
  @Test
  public void testInitialization()
  {
    assertEquals(10, hand.getStartSize());
    assertEquals(0, hand.getSize());
  }
 
  @Test
  /**
   * Test to make sure a hand with a max size can be made
   */
  public void testHandWithAMaxSize()
  {
    hand = new Hand(0, 50);
    hand.getMaxSize();
  }
 
  /**
   * Test drawing a full hand all at one
   */
  @Test
  public void testDrawingFullHand()
  {
    hand.drawHand();
    assertEquals(10, hand.getSize());
  }
 
  /**
   * Test drawing cards one at a time
   */
  @Test
  public void testDrawingSingleCards()
  {
    hand.drawCard();
    assertEquals(1, hand.getSize());
    hand.drawCard();
    assertEquals(2, hand.getSize());
    hand.drawCard();
    assertEquals(3, hand.getSize());
  }
 
  /**
   * Test to make sure a specific card can be added
   */
  @Test
  public void testAddSpecificCard()
  {
    hand.addCard(new Card(10, 'h'));
    assertEquals(10, hand.getCard(0).getValue());
    assertEquals('h', hand.getCard(0).getSuit());
  }
 
  /**
   * Test to make sure a card can be removed as long as it is within bounds
   */
  @Test
  public void testRemoveCard()
  {
    hand.drawHand();
    hand.removeCard(12);
    assertEquals(10, hand.getSize());
    hand.removeCard(3);
    assertEquals(9, hand.getSize());
  }
 
   /**
   * Test to make sure a hand can be cleared
   */
  @Test
  public void testClearHand()
  {
    hand.drawHand();
    assertEquals(10, hand.getSize());
    hand.clear();
    assertEquals(0, hand.getSize());
  }
 
  @Test
  /**
   * Test to make sure you cannot get a card out from an invalid index
   */
  public void testGettingCardFromInvalidIndex()
  {
    hand.drawHand();
    assertNull(hand.getCard(100));
  }
 
  @Test
  /**
   * Test adding multiple cards
   */
  public void testAddingMultipleCards()
  {
    hand.drawHand();
    ArrayList<Card> list = new ArrayList<Card>();
    list.addAll(Arrays.asList(new Card[] {new Card(9, 'd'), new Card(10, 'h')}));
    hand.addCards(list);
    assertTrue(hand.contains(new Card(9, 'd')));
    assertTrue(hand.contains(new Card(10, 'h')));
  }
 
  @Test
  /**
   * Test the toString
   */
  public void testToString()
  {
    hand.drawHand();
    assertEquals("0c 1c 2c 3c 4c 5c 6c 7c 8c 9c ", hand.toString());
  }
}

  
TOP

Related Classes of hand.TestHand

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.