Package games.war

Source Code of games.war.TestWarPlayer

package games.war;

import static org.junit.Assert.*;

import java.util.ArrayList;

import game.Card;
import game.Deck;
import games.war.behaviors.CheatingBehavior;
import games.war.behaviors.NotCheating;
import hand.HandBehaviour;
import hand.WarHand;

import org.junit.Before;
import org.junit.Test;

/**
* Makes sure WarPlayer Functions as it should.
* @author Chris Hersh
*
*/
public class TestWarPlayer
{

    /**
     * Destroys the deck so the tests don't
     * cause an ArrayOutOfBounds exception
     */
    @Before
    public void destroyDeck()
    {
        Deck.getInstance().reset();
    }
   
    /**
     * Makes sure WarPlayer is initialized correctly
     * Most functionality is handled by the Player class
     */
    @Test
    public void testInit()
    {
        CheatingBehavior cheat = new NotCheating();
        HandBehaviour hand = new WarHand();
        WarPlayer player = new WarPlayer(hand, cheat);
       
        assertEquals(cheat, player.howToCheat);
    }
   
    /**
     * Makes sure that the cheat() method
     * does not return null
     */
    @Test
    public void testCheat()
    {
        CheatingBehavior cheat = new NotCheating();
        HandBehaviour hand = new WarHand();
        WarPlayer player = new WarPlayer(hand, cheat);
        assertTrue(player.cheat() != null);
    }
   
    /**
     * Makes sure the card returned by the takeTurn()
     * method is not null
     */
    @Test
    public void testTakeTurn()
    {
        CheatingBehavior cheat = new NotCheating();
        HandBehaviour hand = new WarHand();
        WarPlayer player = new WarPlayer(hand, cheat);
        assertTrue(player.takeTurn() != null);
    }
   
    /**
     * Makes sure the three cards returned from the war()
     * method are not null.
     */
    @Test
    public void testWar()
    {
        CheatingBehavior cheat = new NotCheating();
        HandBehaviour hand = new WarHand();
        WarPlayer player = new WarPlayer(hand, cheat);
        Card array[] = player.war();
       
        assertTrue(array[0] != null);
        assertTrue(array[1] != null);
        assertTrue(array[2] != null);
    }
   
    /**
     * Makes sure the war method works with a small hand
     */
    @Test
    public void testWarSmallHand()
    {
        CheatingBehavior cheat = new NotCheating();
        HandBehaviour hand = new WarHand();
        WarPlayer player = new WarPlayer(hand, cheat);
        ArrayList<Card> cards = new ArrayList<Card>();
       
        Card c1 = new Card(6, 'c');
        Card c2 = new Card(5, 'c');
        Card c3 = new Card(10, 'c');
        cards.add(c1);
        cards.add(c2);
        cards.add(c3);

        player.clearHand();
        player.addCardsToHand(cards);
        Card array[] = player.war();
       
        assertEquals(c1, array[0]);
        assertEquals(c2, array[1]);
        assertEquals(null, array[2]);
       
    }
   
    /**
     * Makes sure cards can be added to the hand
     */
    @Test
    public void testAddCardsToHand()
    {
        CheatingBehavior cheat = new NotCheating();
        HandBehaviour hand = new WarHand();
        WarPlayer player = new WarPlayer(hand, cheat);
        ArrayList<Card> cards = new ArrayList<Card>();
       
        Card c1 = new Card(6, 'c');
        Card c2 = new Card(5, 'c');
        Card c3 = new Card(10, 'c');
        cards.add(c1);
        cards.add(c2);
        cards.add(c3);

        player.clearHand();
        player.addCardsToHand(cards);
       
        for(int i = 0; i < player.getHand().getSize(); i++)
        {
            assertTrue(cards.contains(player.getHand().getCard(i)));
        }
    }
   
    /**
     * Makes sure hands can be cleared
     */
    @Test
    public void testClearHand()
    {
        CheatingBehavior cheat = new NotCheating();
        HandBehaviour hand = new WarHand();
        WarPlayer player = new WarPlayer(hand, cheat);
        assertEquals(26, player.getHandSize());
        player.clearHand();
        assertEquals(0, player.getHandSize());
    }

}


TOP

Related Classes of games.war.TestWarPlayer

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.