Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /**
- * The test class StudentUnitTests.
- *
- * @author various
- * @version 0.1
- */
- public class StudentUnitTests extends junit.framework.TestCase
- {
- public void testCanMove()
- {
- AcesHighFunctional a = new AcesHighFunctional();
- a.createDeckFromString("4H2H3H5HAH6H7H8HTH9HJHQHKHAS2S3S" + //actually used
- "4S5S6S7S8S9STSJSQSKSAC2C3C4C5C6C7C8C9CTCJCQCKCAD2D3D4D5D6D7D8D9DTDJDQDKD"); //I don't care
- /*now need to test every pile when empty*/
- a.initPiles();
- //none empty
- a.dealFour();
- assertEquals(a.canMove(0), -1);
- //pile 0
- a.removeTop(0);
- assertEquals(a.canMove(1), 0);
- //pile 2
- a.dealFour();
- a.removeTop(2);
- a.removeTop(2);
- assertEquals(a.canMove(1), 2);
- //pile 1
- a.dealFour();
- a.removeTop(1);
- a.removeTop(1);
- a.removeTop(1);
- assertEquals(a.canMove(3), 1);
- //pile 3
- a.dealFour();
- a.removeTop(3);
- a.removeTop(3);
- a.removeTop(3);
- a.removeTop(3);
- assertEquals(a.canMove(2), 3);
- }
- /**
- * Lab 3
- * The test method for AcesHighFunctioanlTest testing the isEmpty() method.
- *
- * @author Austin Robarts
- */
- public void testIsEmpty()
- {
- int cardCount = 52;
- AcesHighFunctional game = new AcesHighFunctional();
- game.createRandomDeck();
- assertFalse("Failed to verify deck is not empty", game.isEmpty());
- while (cardCount > 0)
- {
- game.dealCard();
- cardCount--;
- }
- assertTrue("Failed to verify deck is empty", game.isEmpty());
- }
- public void testLessThan()
- {
- int high1 = 12;
- int high2 = 25;
- int high3 = 38;
- int high4 = 51;
- AcesHighFunctional game = new AcesHighFunctional();
- for (int low = 0; low < high1; low++)
- {
- assertTrue(game.lessThan(low, high1));
- assertFalse(game.lessThan(high1, low));
- assertFalse(game.lessThan(low, high2));
- assertFalse(game.lessThan(low, high3));
- assertFalse(game.lessThan(low, high4));
- }
- for (int low = 13; low < high2; low++)
- {
- assertTrue(game.lessThan(low, high2));
- assertFalse(game.lessThan(high2, low));
- assertFalse(game.lessThan(low, high1));
- assertFalse(game.lessThan(low, high3));
- assertFalse(game.lessThan(low, high4));
- }
- for (int low = 26; low < high3; low++)
- {
- assertTrue(game.lessThan(low, high3));
- assertFalse(game.lessThan(high3, low));
- assertFalse(game.lessThan(low, high1));
- assertFalse(game.lessThan(low, high2));
- assertFalse(game.lessThan(low, high4));
- }
- for (int low = 39; low < high4; low++)
- {
- assertTrue(game.lessThan(low, high4));
- assertFalse(game.lessThan(high4, low));
- assertFalse(game.lessThan(low, high1));
- assertFalse(game.lessThan(low, high2));
- assertFalse(game.lessThan(low, high3));
- }
- }
- /**
- * Tests the canDiscard() method
- */
- protected void TestCanDiscard()
- {
- AcesHighFunctional game = new AcesHighFunctional();
- game.createDeckFromString("JDACAD5H");
- game.dealFour();
- assertTrue(game.canDiscard(1));
- }
- /**
- * The test class isEmptyTest.
- *
- * @author Kevin Pham
- * @author Myra Lukens
- * @author Fina Beauchamp
- */
- /**
- * Default constructor for test class isEmptyTest
- */
- public void isEmptyTest()
- {
- AcesHighFunctional ahf;
- ahf = new AcesHighFunctional();
- ahf.createRandomDeck();
- assertFalse(ahf.isEmpty());
- for(int idx = 0; idx < 13; idx++)
- {
- ahf.dealCard();
- }
- assertTrue(ahf.isEmpty());
- }
- /**
- * The test class DealCardTest.
- *
- * @author Jacob Boyles
- * @version 10/5/15
- */
- /**
- * The test makes sure that deal card can deal out all the cards in the deck.
- * The deck needs to be ordered from 0 -> 51.
- */
- public void testDealCard()
- {
- AcesHighFunctional game;
- game = new AcesHighFunctional();
- game.createDeckFromString("4C3C2C");
- assertEquals(0, game.dealCard());
- assertEquals(1, game.dealCard());
- assertEquals(2, game.dealCard());
- }
- /**
- * The test class AcesHighTest.
- *
- * @author Jason Krein, Steven Thon, Jonathan Molina
- */
- /**
- * JUnit test for CanDiscard
- */
- public void testCanDiscard()
- {
- AcesHighFunctional testDiscard = new AcesHighFunctional();
- //Creates a custom deck where pile 4 is the only one that can be discarded
- testDiscard.createDeckFromString("8S2HJSKD");
- testDiscard.initPiles();
- testDiscard.dealFour();
- assertFalse(testDiscard.canDiscard(0));
- assertFalse(testDiscard.canDiscard(1));
- assertFalse(testDiscard.canDiscard(2));
- assertTrue(testDiscard.canDiscard(3));
- }
- /**
- * Tests the dealCard method of AcesHighFunctional.
- */
- public void testDealCard2()
- {
- AcesHighFunctional acesHigh = new AcesHighFunctional();
- acesHigh.initPiles();
- acesHigh.createDeckFromString("2C");
- assertTrue(acesHigh.getCard(acesHigh.dealCard()).equals("2C"));
- }
- /**
- * Tests whether the Aces High deck is empty or not.
- *
- */
- public void testisEmpty2()
- {
- AcesHighFunctional ahs = new AcesHighFunctional();
- ahs.createRandomDeck();
- assertFalse(ahs.isEmpty());
- //Deal all the cards in the deck,
- //until deck is empty
- for(int idx = 0; idx < 52; idx++)
- {
- ahs.dealCard();
- }
- assertTrue(ahs.isEmpty());
- }
- private static final int SizeOfDeck= 52;
- private static final int NumberOfCards =4;
- public void testIsEmpty3()
- {
- AcesHighFunctional game = new AcesHighFunctional();
- game.createRandomDeck();
- assertFalse(game.isEmpty());
- for(int index = 0; index < SizeOfDeck; index++)
- {
- game.dealCard();
- }
- assertTrue(game.isEmpty());
- game.createDeckFromString("2H3H4H5H");
- for(int index = 0; index < NumberOfCards; index++)
- {
- game.dealCard();
- }
- assertTrue(game.isEmpty());
- }
- /**
- * Tests the canDiscard function
- * @Test
- */
- public void testCanDiscard3()
- {
- AcesHighFunctional game = new AcesHighFunctional();
- game.createDeckFromString("ACASAHAD");
- game.initPiles();
- game.dealFour();
- assertFalse(game.canDiscard(1));
- game = new AcesHighFunctional();
- game.createDeckFromString("AC2C3C4C");
- game.initPiles();
- game.dealFour();
- assertTrue("can discard failed",game.canDiscard(2));
- }
- public void testlessThan()
- {
- AcesHighFunctional tester = new AcesHighFunctional();
- //basic tests
- assertTrue(tester.lessThan(0, 1));
- assertFalse(tester.lessThan(1, 0));
- assertFalse(tester.lessThan(1, 1));
- //basic tests in a different suit
- assertTrue(tester.lessThan(13, 14));
- assertFalse(tester.lessThan(14, 13));
- assertFalse(tester.lessThan(13, 13));
- //7H is not less than 2D
- assertFalse(tester.lessThan(6, 13));
- //2H is not less than 2D
- assertFalse(tester.lessThan(0, 13));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement