Question
Junit test provided and this wont take you more than 15 mins. As is appropriate,CardShoe stores the playing cards in a List. You will need
Junit test provided and this wont take you more than 15 mins.
As is appropriate,CardShoe stores the playing cards in a List. You will need to complete two methods for the CardShoe class:
dealCard() should remove the first card (e.g., card at index 0) from cards. The method should return the card that was removed from cards.
cutDeck() does the last step of shuffling -- cutting the deck. This should move the first cutLocation number of cards ("first" meaning at the lowest index) from cards and add them to the back of the List. Make certain that you add cards in the same (relative) order that they were originally stored.
------------
package edu.buffalo.cse116; import java.util.List; public class CardShoe { private Listcards; public CardShoe(List originalList) { cards = originalList; } public List cutDeck(int cutLocation) { } public PlayingCard dealCard() { } }
-----------------
test file
package edu.buffalo.cse116;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail;
import java.lang.reflect.Field; import java.util.List;
import org.junit.Before; import org.junit.Test;
public class CardShoeTest { // NOTE: Make students write these tests, also. private Field cards; private CardShoe testee; private List
@Before public final void checkFieldsUnchanged() { Class> shoe = CardShoe.class; Field[] fields = shoe.getDeclaredFields(); assertEquals("You should not add any fields to the CardShoe class. This class's field count:", 1, fields.length); try { cards = shoe.getDeclaredField("cards"); assertEquals("The cards field should be of type List", List.class, cards.getType()); cards.setAccessible(true); } catch (Exception e) { fail("Your CardShoe class should still define a field named \"cards\""); } listGen = new ListGenerator(); testeeDecks = listGen.createNewList(); PlayingCard[] decks = PlayingCard.generate(1); for (PlayingCard p : decks) { testeeDecks.add(p); } testee = new CardShoe(testeeDecks); testeeTooDecks = listGen.createNewList(); PlayingCard[] decksToo = PlayingCard.generate(4); for (PlayingCard p : decksToo) { testeeTooDecks.add(p); } testeeToo = new CardShoe(testeeTooDecks); }
@Test public final void testOneDeckCutAtTwelve() throws Exception { String[] oneCut = { "AC", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "TD", "JD", "QD", "KD", "AD", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "TH", "JH", "QH", "KH", "AH", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "TS", "JS", "QS", "KS", "AS", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "TC", "JC", "QC", "KC" }; testee.cutDeck(12); Object newCards = cards.get(testee); assertSame("cutDeck(12) should not allocate a new List for the cards field.", testeeDecks, newCards); assertEquals("cutDeck(12) should not change the number of elements in cards when called with a complete deck of 52 cards", 52, testeeDecks.size()); for (int i = 0; i < oneCut.length; i++ ) { assertEquals("cutDeck(12) did not correctly cut a complete deck of 52 cards. At index " + i + " expected " + oneCut[i] + " but was " + testeeDecks.get(i).toString(), oneCut[i], testeeDecks.get(i).toString()); } }
@Test public final void testOneDeckCutAtFourty() throws Exception { String[] oneCut = { "3S", "4S", "5S", "6S", "7S", "8S", "9S", "TS", "JS", "QS", "KS", "AS", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "TC", "JC", "QC", "KC", "AC", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "TD", "JD", "QD", "KD", "AD", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "TH", "JH", "QH", "KH", "AH", "2S" }; testee.cutDeck(40); Object newCards = cards.get(testee); assertSame("cutDeck(40) should not allocate a new List for the cards field.", testeeDecks, newCards); assertEquals("cutDeck(40) should not change the number of elements in cards when called with a complete deck of 52 cards", 52, testeeDecks.size()); for (int i = 0; i < oneCut.length; i++ ) { assertEquals("cutDeck(40) did not correctly cut a complete deck of 52 cards. At index " + i + " expected " + oneCut[i] + " but was " + testeeDecks.get(i).toString(), oneCut[i], testeeDecks.get(i).toString()); } }
@Test public final void testMultiDeckCutAtOneThirtyThree() throws Exception { String[] oneCut = { "5H", "6H", "7H", "8H", "9H", "TH", "JH", "QH", "KH", "AH", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "TS", "JS", "QS", "KS", "AS", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "TC", "JC", "QC", "KC", "AC", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "TD", "JD", "QD", "KD", "AD", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "TH", "JH", "QH", "KH", "AH", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "TS", "JS", "QS", "KS", "AS", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "TC", "JC", "QC", "KC", "AC", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "TD", "JD", "QD", "KD", "AD", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "TH", "JH", "QH", "KH", "AH", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "TS", "JS", "QS", "KS", "AS", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "TC", "JC", "QC", "KC", "AC", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "TD", "JD", "QD", "KD", "AD", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "TH", "JH", "QH", "KH", "AH", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "TS", "JS", "QS", "KS", "AS", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "TC", "JC", "QC", "KC", "AC", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "TD", "JD", "QD", "KD", "AD", "2H", "3H", "4H" }; testeeToo.cutDeck(133); Object newCards = cards.get(testee); assertSame("cutDeck(133) should not allocate a new List for the cards field when cards had 208 elements.", testeeDecks, newCards); assertEquals("cutDeck(133) should not change the number of elements in cards when called with a 4 complete decks (so the size of cards was 208)", 208, testeeTooDecks.size()); for (int i = 0; i < oneCut.length; i++ ) { assertEquals("cutDeck(133) did not correctly cut when cards had 208 cards. At index " + i + " expected " + oneCut[i] + " but was " + testeeTooDecks.get(i).toString(), oneCut[i], testeeTooDecks.get(i).toString()); } }
@Test public final void testDealCard() throws Exception { PlayingCard answer = testeeDecks.get(0); PlayingCard[] original = new PlayingCard[51]; for (int i = 0; i < original.length; i++ ) { original[i] = testeeDecks.get(i + 1); } PlayingCard p = testee.dealCard(); Object newCards = cards.get(testee); assertSame("deal() should not allocate a new List for the cards field.", testeeDecks, newCards); assertEquals("deal() should remove one card from the List. Expected size of 51, but cards size was actually " + testeeDecks.size(), 51, testeeDecks.size()); assertSame("deal() should return the actual PlayingCard instance that had been at the start of the List. Expected: " + answer + " but was " + p, answer, p); for (int i = 0; i < original.length; i++ ) { assertSame("deal() rearranged or replaced cards after the card that was dealt. List element at index " + i + " was expecting " + original[i] + "but was " + testeeDecks.get(i), original[i], testeeDecks.get(i)); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started