Package games.war.behaviors

Source Code of games.war.behaviors.TestCheating

package games.war.behaviors;

import static org.junit.Assert.*;

import java.util.ArrayList;

import game.Card;
import games.war.PlayerController;
import hand.Hand;

import org.junit.Test;

/**
* Makes sure the Cheating behavior works as it should
* @author chris
*
*/
public class TestCheating
{
    /**
     * Makes sure the correct card is chosen normally
     */
    @Test
    public void testCheating()
    {
        Card cd = new Card(7, 's');
        PlayerController.previousCard = cd;
       
        Cheating cheat = new Cheating();
        Hand hand = new Hand(10);
        //System.out.println(hand);
        ArrayList<Card> cards = new ArrayList<Card>();
        cards.add(new Card(6, 'c'));
        cards.add(new Card(5, 'c'));
        cards.add(new Card(10, 'c'));
        cards.add(new Card(8, 'c'));
        cards.add(new Card(1, 'c'));
        cards.add(new Card(3, 'c'));
        cards.add(new Card(7, 'c'));
        hand.addCards(cards);
       
        assertEquals(cards.get(3), cheat.getNextCard(hand));
    }
   
    /**
     * Makes sure the correct card is chosen if the last card was null
     */
    @Test
    public void testCheatingPrevCardNull()
    {
        PlayerController.previousCard = null;
       
        Cheating cheat = new Cheating();
        Hand hand = new Hand(10);
        //System.out.println(hand);
        ArrayList<Card> cards = new ArrayList<Card>();
        cards.add(new Card(6, 'c'));
        cards.add(new Card(5, 'c'));
        cards.add(new Card(10, 'c'));
        cards.add(new Card(8, 'c'));
        cards.add(new Card(1, 'c'));
        cards.add(new Card(3, 'c'));
        cards.add(new Card(2, 'c'));
        hand.addCards(cards);
       
        assertEquals(cards.get(0), cheat.getNextCard(hand));
    }
   
    /**
     * Makes sure the correct card is chosen if the last card can't be beaten
     */
    @Test
    public void testCheatingEqualValue()
    {
        Card cd = new Card(10, 's');
        PlayerController.previousCard = cd;
       
        Cheating cheat = new Cheating();
        Hand hand = new Hand(10);
        //System.out.println(hand);
        ArrayList<Card> cards = new ArrayList<Card>();
        cards.add(new Card(6, 'c'));
        cards.add(new Card(5, 'c'));
        cards.add(new Card(10, 'c'));
        cards.add(new Card(8, 'c'));
        cards.add(new Card(1, 'c'));
        cards.add(new Card(3, 'c'));
        cards.add(new Card(2, 'c'));
        hand.addCards(cards);
       
        assertEquals(cards.get(2), cheat.getNextCard(hand));
    }
   
    /**
     * Makes sure the correct card is chosen when the opponent will win
     */
    @Test
    public void testCheatingOppnentWins()
    {
        Card cd = new Card(12, 's');
        PlayerController.previousCard = cd;
       
        Cheating cheat = new Cheating();
        Hand hand = new Hand(10);
        //System.out.println(hand);
        ArrayList<Card> cards = new ArrayList<Card>();
        cards.add(new Card(6, 'c'));
        cards.add(new Card(5, 'c'));
        cards.add(new Card(10, 'c'));
        cards.add(new Card(8, 'c'));
        cards.add(new Card(1, 'c'));
        cards.add(new Card(3, 'c'));
        cards.add(new Card(2, 'c'));
        hand.addCards(cards);
       
        assertEquals(cards.get(0), cheat.getNextCard(hand));
    }

}
TOP

Related Classes of games.war.behaviors.TestCheating

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.