Advertisement
jdalbey

Aces High Student Unit Tests

Oct 8th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 7.85 KB | None | 0 0
  1.  
  2. import java.util.*;
  3. /**
  4.  * The test class StudentUnitTests.
  5.  *
  6.  * @author various
  7.  * @version 0.1
  8.  */
  9. public class StudentUnitTests extends junit.framework.TestCase
  10. {
  11.     public void testCanMove()
  12.     {
  13.         AcesHighFunctional a = new AcesHighFunctional();
  14.         a.createDeckFromString("4H2H3H5HAH6H7H8HTH9HJHQHKHAS2S3S" + //actually used
  15.             "4S5S6S7S8S9STSJSQSKSAC2C3C4C5C6C7C8C9CTCJCQCKCAD2D3D4D5D6D7D8D9DTDJDQDKD"); //I don't care
  16.  
  17.         /*now need to test every pile when empty*/
  18.         a.initPiles();
  19.         //none empty
  20.         a.dealFour();
  21.         assertEquals(a.canMove(0), -1);
  22.  
  23.         //pile 0
  24.         a.removeTop(0);
  25.         assertEquals(a.canMove(1), 0);
  26.  
  27.         //pile 2
  28.         a.dealFour();
  29.         a.removeTop(2);
  30.         a.removeTop(2);
  31.         assertEquals(a.canMove(1), 2);
  32.  
  33.         //pile 1
  34.         a.dealFour();
  35.         a.removeTop(1);
  36.         a.removeTop(1);
  37.         a.removeTop(1);
  38.         assertEquals(a.canMove(3), 1);
  39.  
  40.         //pile 3
  41.         a.dealFour();
  42.         a.removeTop(3);
  43.         a.removeTop(3);
  44.         a.removeTop(3);
  45.         a.removeTop(3);
  46.         assertEquals(a.canMove(2), 3);
  47.     }
  48.  
  49.     /**
  50.      * Lab 3
  51.      * The test method for AcesHighFunctioanlTest testing the isEmpty() method.
  52.      *
  53.      * @author Austin Robarts
  54.      */
  55.  
  56.     public void testIsEmpty()
  57.     {
  58.         int cardCount = 52;
  59.         AcesHighFunctional game = new AcesHighFunctional();
  60.  
  61.         game.createRandomDeck();
  62.         assertFalse("Failed to verify deck is not empty", game.isEmpty());
  63.  
  64.         while (cardCount > 0)
  65.         {
  66.             game.dealCard();
  67.             cardCount--;
  68.         }
  69.  
  70.         assertTrue("Failed to verify deck is empty", game.isEmpty());
  71.  
  72.     }
  73.    
  74.     public void testLessThan()
  75.     {
  76.         int high1 = 12;
  77.         int high2 = 25;
  78.         int high3 = 38;
  79.         int high4 = 51;
  80.  
  81.         AcesHighFunctional game = new AcesHighFunctional();
  82.  
  83.         for (int low = 0; low < high1; low++)
  84.         {
  85.             assertTrue(game.lessThan(low, high1));
  86.             assertFalse(game.lessThan(high1, low));
  87.             assertFalse(game.lessThan(low, high2));
  88.             assertFalse(game.lessThan(low, high3));
  89.             assertFalse(game.lessThan(low, high4));
  90.         }
  91.         for (int low = 13; low < high2; low++)
  92.         {
  93.             assertTrue(game.lessThan(low, high2));
  94.             assertFalse(game.lessThan(high2, low));
  95.             assertFalse(game.lessThan(low, high1));
  96.             assertFalse(game.lessThan(low, high3));
  97.             assertFalse(game.lessThan(low, high4));
  98.         }
  99.         for (int low = 26; low < high3; low++)
  100.         {
  101.             assertTrue(game.lessThan(low, high3));
  102.             assertFalse(game.lessThan(high3, low));
  103.             assertFalse(game.lessThan(low, high1));
  104.             assertFalse(game.lessThan(low, high2));
  105.             assertFalse(game.lessThan(low, high4));
  106.         }
  107.         for (int low = 39; low < high4; low++)
  108.         {
  109.             assertTrue(game.lessThan(low, high4));
  110.             assertFalse(game.lessThan(high4, low));
  111.             assertFalse(game.lessThan(low, high1));
  112.             assertFalse(game.lessThan(low, high2));
  113.             assertFalse(game.lessThan(low, high3));
  114.         }
  115.     }
  116.  
  117.     /**
  118.      * Tests the canDiscard() method
  119.      */
  120.     protected void TestCanDiscard()
  121.     {
  122.         AcesHighFunctional game = new AcesHighFunctional();
  123.         game.createDeckFromString("JDACAD5H");
  124.         game.dealFour();
  125.         assertTrue(game.canDiscard(1));
  126.     }
  127.  
  128.  
  129.     /**
  130.      * The test class isEmptyTest.
  131.      *
  132.      * @author Kevin Pham
  133.      * @author Myra Lukens
  134.      * @author Fina Beauchamp
  135.      */
  136.  
  137.     /**
  138.      * Default constructor for test class isEmptyTest
  139.      */
  140.     public void isEmptyTest()
  141.     {
  142.         AcesHighFunctional ahf;    
  143.         ahf = new AcesHighFunctional();
  144.         ahf.createRandomDeck();
  145.         assertFalse(ahf.isEmpty());
  146.         for(int idx = 0; idx < 13; idx++)
  147.         {
  148.             ahf.dealCard();
  149.         }
  150.         assertTrue(ahf.isEmpty());
  151.     }
  152.     /**
  153.      * The test class DealCardTest.
  154.      *
  155.      * @author  Jacob Boyles
  156.      * @version 10/5/15
  157.      */
  158.  
  159.     /**
  160.      * The test makes sure that deal card can deal out all the cards in the deck.
  161.      * The deck needs to be ordered from 0 -> 51.
  162.      */
  163.     public void testDealCard()
  164.     {
  165.         AcesHighFunctional game;
  166.         game = new AcesHighFunctional();
  167.         game.createDeckFromString("4C3C2C");
  168.         assertEquals(0, game.dealCard());
  169.         assertEquals(1, game.dealCard());
  170.         assertEquals(2, game.dealCard());
  171.     }
  172.  
  173.     /**
  174.      * The test class AcesHighTest.
  175.      *
  176.      * @author  Jason Krein, Steven Thon, Jonathan Molina
  177.      */
  178.     /**
  179.      * JUnit test for CanDiscard
  180.      */
  181.     public void testCanDiscard()
  182.     {
  183.         AcesHighFunctional testDiscard = new AcesHighFunctional();
  184.         //Creates a custom deck where pile 4 is the only one that  can be discarded
  185.         testDiscard.createDeckFromString("8S2HJSKD");
  186.         testDiscard.initPiles();
  187.         testDiscard.dealFour();
  188.         assertFalse(testDiscard.canDiscard(0));
  189.         assertFalse(testDiscard.canDiscard(1));
  190.         assertFalse(testDiscard.canDiscard(2));
  191.         assertTrue(testDiscard.canDiscard(3));
  192.     }
  193.  
  194.     /**
  195.      * Tests the dealCard method of AcesHighFunctional.
  196.      */
  197.     public void testDealCard2()
  198.     {
  199.         AcesHighFunctional acesHigh = new AcesHighFunctional();
  200.  
  201.         acesHigh.initPiles();
  202.         acesHigh.createDeckFromString("2C");
  203.         assertTrue(acesHigh.getCard(acesHigh.dealCard()).equals("2C"));
  204.     }  
  205.  
  206.     /**
  207.      * Tests whether the Aces High deck is empty or not.
  208.      *
  209.      */
  210.     public void testisEmpty2()
  211.     {
  212.         AcesHighFunctional ahs = new AcesHighFunctional();
  213.         ahs.createRandomDeck();
  214.         assertFalse(ahs.isEmpty());
  215.  
  216.         //Deal all the cards in the deck,
  217.         //until deck is empty
  218.         for(int idx = 0; idx < 52; idx++)
  219.         {
  220.             ahs.dealCard();
  221.         }
  222.         assertTrue(ahs.isEmpty());
  223.     }
  224.  
  225.     private static final int SizeOfDeck= 52;
  226.     private static final int NumberOfCards =4;
  227.  
  228.     public void testIsEmpty3()
  229.     {
  230.         AcesHighFunctional game = new AcesHighFunctional();
  231.         game.createRandomDeck();
  232.         assertFalse(game.isEmpty());
  233.         for(int index = 0; index < SizeOfDeck; index++)
  234.         {
  235.             game.dealCard();
  236.         }
  237.         assertTrue(game.isEmpty());
  238.  
  239.         game.createDeckFromString("2H3H4H5H");
  240.  
  241.         for(int index = 0; index < NumberOfCards; index++)
  242.         {
  243.             game.dealCard();
  244.         }
  245.         assertTrue(game.isEmpty());
  246.     }
  247.  
  248.     /**
  249.      * Tests the canDiscard function
  250.      * @Test
  251.      */
  252.     public void testCanDiscard3()
  253.     {
  254.         AcesHighFunctional game = new AcesHighFunctional();
  255.         game.createDeckFromString("ACASAHAD");
  256.         game.initPiles();
  257.         game.dealFour();
  258.  
  259.         assertFalse(game.canDiscard(1));
  260.  
  261.         game = new AcesHighFunctional();
  262.         game.createDeckFromString("AC2C3C4C");
  263.         game.initPiles();
  264.         game.dealFour();
  265.         assertTrue("can discard failed",game.canDiscard(2));
  266.     }
  267.  
  268.     public void testlessThan()
  269.     {
  270.         AcesHighFunctional tester = new AcesHighFunctional();
  271.  
  272.         //basic tests
  273.         assertTrue(tester.lessThan(0, 1));
  274.         assertFalse(tester.lessThan(1, 0));
  275.         assertFalse(tester.lessThan(1, 1));
  276.  
  277.         //basic tests in a different suit
  278.         assertTrue(tester.lessThan(13, 14));
  279.         assertFalse(tester.lessThan(14, 13));
  280.         assertFalse(tester.lessThan(13, 13));
  281.  
  282.         //7H is not less than 2D
  283.         assertFalse(tester.lessThan(6, 13));
  284.  
  285.         //2H is not less than 2D
  286.         assertFalse(tester.lessThan(0, 13));
  287.     }
  288.  
  289.    
  290. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement