Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Each deck is given a list of cards from the professor's test harness. I'm having trouble with a drawAll method:
- drawAll documentation:
- [QUOTE]Removes all Cards from this Deck and returns them as a new Deck. If this deck is empty, then this method returns an empty new Deck.[/QUOTE]
- I puzzled through it with a friend, and the closest we got was
- [QUOTE]public Deck drawAll() {
- Deck newDeck = new DeckImp();
- if (self.isEmpty() == false) {
- for(i=0; i<self.size; i++) {
- newDeck.add(self[i]);
- }
- self.removeAll();
- }
- return newDeck;
- }[/QUOTE]
- Which didn't work. So the professor gave me some hints.
- 1. Construct a new empty deck
- 2. Pass elements from the list the professor created into the new deck
- 3. Call clear() to remove cards from the first deck, not removeAll()
- As far as two goes, he first said to use a loop to get and remove each item, then said sublists would be easier (I don't think we've ever gone over sublists, so it's fun research time).
- Specific test that is failing:
- public void testDeck9() {
- final List<Card> cardList = new ArrayList<>();
- final Card c1 = new Card(Suit.SPADE, Rank.TWO);
- final Card c2 = new Card(Suit.SPADE, Rank.THREE);
- final Card c3 = new Card(Suit.SPADE, Rank.SIX);
- final Card c4 = new Card(Suit.SPADE, Rank.SEVEN);
- final Card c5 = new Card(Suit.SPADE, Rank.KING);
- cardList.add(c1);
- cardList.add(c2);
- cardList.add(c3);
- cardList.add(c4);
- cardList.add(c5);
- Deck deck1 = factory.createDeck(cardList);
- Deck deck2 = deck1.drawAll(); //this is failing
- assert deck1.size() == 0;
- assert deck2.size() == 5;
- assert deck2.peekTop().equals(c1);
- assert deck2.peekBottom().equals(c5);
- System.out.println("testDeck9 success.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement