Package game

Source Code of game.TestPlayer

package game;
import static org.junit.Assert.*;
import games.gofish.GoFish;
import hand.BlackJackHand;
import hand.GoFishHand;
import hand.HandBehaviour;
import hand.MemoryHand;
import hand.WarHand;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* Test all the functionality of player.
* @author TJ Renninger
*
*/
public class TestPlayer
{
  private Player player;
 
  @Before
  /**
   * Creates a new player for each test.
   */
  public void setUp()
  {
    player = new Player();
    Deck.getInstance().reset();
  }
 
  @Test
  /**
   * Test to make sure a default player can be created.
   */
  public void testInitilization()
  {
    assertNotNull(player.getHand());
    assertTrue(player.getHandBehaviour() instanceof BlackJackHand);
  }
 
  @Test
  /**
   * Test to make sure the right amount of cards are drawn
   * for each behaviour.
   */
  public void testDrawing()
  {
    HandBehaviour behaviours[] = {
        new BlackJackHand(), new MemoryHand(), new WarHand(), new GoFishHand()};
    int startSizes[] = {0, 0, 26, 7};
    for (int i = 0; i < behaviours.length; i++)
    {
      player = new Player(behaviours[i]);
      player.draw();
      assertEquals(startSizes[i], player.getHand().getSize());
    }
  }
 
  @Test
  /**
   * Test drawing only one card after each test.
   */
  public void testOneDrawAfterFisrtDraw()
  {
    player.draw();
    int currSize = player.getHand().getSize();
    player.draw();
    assertEquals(currSize + 1, player.getHand().getSize());
  }
}
TOP

Related Classes of game.TestPlayer

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.