Question
this need to fill in the CardShoe, and pass the foloowing three testing method this is the CardShoeTest: import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import
this need to fill in the CardShoe, and pass the foloowing three testing method
this is the CardShoeTest:
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.Rule; import org.junit.Test; import org.junit.rules.Timeout;
import edu.buffalo.correctness.Scorable;
/* * Homework test cases
* (C) 2018 by Matthew Hertz
* Posting this file to a website without the explicit written permission of the author is a violation of their * copyright. */ @Scorable(problem = "Homework07Problem1") public class CardShoeTest { @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
@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
@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
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); } }
this is the list generator:
// Method descriptor #6 ()V // Stack: 1, Locals: 1 public ListGenerator(); 0 aload_0 [this] 1 invokespecial java.lang.Object() [8] 4 return Line numbers: [pc: 0, line: 13] Local variable table: [pc: 0, pc: 5] local: this index: 0 type: edu.buffalo.cse116.ListGenerator // Method descriptor #15 ()Ljava/util/List; // Signature: ()Ljava/util/List
this is the playing card class:
public class PlayingCard { public enum Suits { CLUBS, DIAMONDS, HEARTS, SPADES;
@Override public String toString() { return name().substring(0, 1); } }
public enum Ranks { TWO("2"), THREE("3"), FOUR("4"), FIVE("5"), SIX("6"), SEVEN("7"), EIGHT("8"), NINE("9"), TEN("T"), JACK("J"), QUEEN("Q"), KING("K"), ACE("A"); private String display;
private Ranks(String s) { display = s; }
@Override public String toString() { return display; } }
private Suits suit; private Ranks value;
public PlayingCard(Suits s, Ranks r) { suit = s; value = r; }
public Suits getSuit() { return suit; }
public Ranks getValue() { return value; }
@Override public String toString() { return value.toString() + suit.toString(); }
public static PlayingCard[] generate(int numDecks) { int length = numDecks * Suits.values().length * Ranks.values().length; PlayingCard[] retVal = new PlayingCard[length]; int idx = 0; for (int i = 0; i Problem #1-Card Decks Download this file that represents the holder used when playing card games. You will also need to download the JAR file which contains the support classes for your class and JUnit test cases used to grade your solution. As is appropriate, Cardace stores the playing cards in a List. You will need to complete two methods for the cazdShae Class: Thea method by implementing the following algorithm: love the tirat halt ot card inta firstia This ay or may not be done in one ine of code oe rnning eeuents in carts into seconatir&This way or may not be don in one line of code in fi* Ret at the tart of firsad. add it to ar Reave thent at the start of secona and add it to carts th- eleaent Recve th 1eant at the start of sndaand add It tc card Endl cut DeckO does the last step of shuffling cutting the deck. This should move the first cuticcati o 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. You can see the tests and check most of your solution using the CardoeTest class in the JAR file. The test cases that check that sutis correctly implemented are only on AutoLab, so you will want to test this code on your own Problem #1-Card Decks Download this file that represents the holder used when playing card games. You will also need to download the JAR file which contains the support classes for your class and JUnit test cases used to grade your solution. As is appropriate, Cardace stores the playing cards in a List. You will need to complete two methods for the cazdShae Class: Thea method by implementing the following algorithm: love the tirat halt ot card inta firstia This ay or may not be done in one ine of code oe rnning eeuents in carts into seconatir&This way or may not be don in one line of code in fi* Ret at the tart of firsad. add it to ar Reave thent at the start of secona and add it to carts th- eleaent Recve th 1eant at the start of sndaand add It tc card Endl cut DeckO does the last step of shuffling cutting the deck. This should move the first cuticcati o 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. You can see the tests and check most of your solution using the CardoeTest class in the JAR file. The test cases that check that sutis correctly implemented are only on AutoLab, so you will want to test this code on your own
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