def test_pushNonAceEmpty(self): """Tests that an empty Foundation rejects a non-Ace.""" print "foundation: test_pushNonAceEmpty ", nonAce = Card(Suit.SPADE, 2) nonAce.flip_up() self.pile.push_card(nonAce) self.assertNotIn(nonAce, self.pile, "The empty Foundation pile accepted \ a non-Ace of its suit.")
def append_cards(pile): """ Populates the Tableau pile with alternating Spades and Diamonds built top-down from King to five. """ for i in range(5,14): card = Card(Suit.SPADE, i) if i % 2 == 0 else Card(Suit.DIAMOND, i) card.flip_up() pile.enqueue(card)
def test_pushKingEmpty(self): """Tests that a King can be pushed to an empty Tableau.""" print "tableau: test_pushKingEmpty ", king = Card(Suit.SPADE, Rank.KING) king.flip_up() self.pile.push_card(king) self.assertEqual(len(self.pile), 1, "TestTableauPile.test_pushKingEmpty: A King was \ rejected from an empty Tableau.")
def test_pushValidCard(self): """Tests that push() accepts a valid Card.""" print "foundation: test_pushValidCard ", append_some_cards(self.pile) for i in range(7,14): card = Card(Suit.SPADE, i) card.flip_up() self.pile.push_card(card) self.assertIn(card, self.pile, "The Foundation pile rejected a valid card.")
def test_pushInvalidRankCard(self): """Tests that push() rejects a Card with an invalid rank.""" print "foundation: test_pushInvalidRankCard ", append_some_cards(self.pile) for i in range(8,14): card = Card(Suit.SPADE, i) card.flip_up() self.pile.push_card(card) self.assertNotIn(card, self.pile, "The Foundation pile accepted a card with \ invalid rank.")
def test_pushAceEmpty(self): """ Tests that an empty Foundation pile accepts an Ace of the proper suit. """ print "foundation: test_pushAceEmpty ", aceS = Card(Suit.SPADE, 1) aceS.flip_up() self.pile.push_card(aceS) self.assertIn(aceS, self.pile, "The empty Foundation pile rejected a valid Ace.")
def test_enqueueCard(self): """ Tests that enqueue() does not insert a Card at the bottom of a Foundation pile. """ print "foundation: test_enqueueCard ", for i in range(1,6): card = Card(Suit.SPADE, i) card.flip_up() self.pile.enqueue_card(card) self.assertNotIn(card, self.pile, "A Card was enqueued to a Foundation pile.")
def test_pushInvalidEmpty(self): """ Tests that push_card() on an empty Tableau pile rejects non-Kings. """ print "tableau: test_pushInvalidEmpty ", nonking = Card(Suit.SPADE, 5) nonking.flip_up() self.pile.push_card(nonking) self.assertEqual(len(self.pile), 0, "TestTableauPile.test_pushInvalidEmpty: A non-King \ was pushed to an empty Tableau pile.")
def test_pushInvalidRank(self): """ Tests that a Foundation pile rejects a Card of the improper rank. """ print "tableau: test_pushInvalidRank ", append_cards(self.pile) oldSize = len(self.pile) invalidRankCard = Card(Suit.SPADE, 3) invalidRankCard.flip_up() self.pile.push_card(invalidRankCard) self.assertEqual(len(self.pile), oldSize, "TestTableauPile.test_pushInvalidRank: A Card with \ an invalid rank was pushed to a Tableau pile.")
def test_pushInvalidColor(self): """ Tests that a Foundation pile rejects a Card of the improper color. """ print "tableau: test_pushInvalidColor ", append_cards(self.pile) oldSize = len(self.pile) invalidColorCard = Card(Suit.HEART, 4) invalidColorCard.flip_up() self.pile.push_card(invalidColorCard) self.assertEqual(len(self.pile), oldSize, "TestTableauPile.test_pushInvalidColor: A Card with \ an invalid color was pushed to a Tableau pile.")
def test_pushValidCard(self): """ Tests that a Card of the appropriate rank and suit can be pushed to the pile. """ print "tableau: test_pushValidCard ", append_cards(self.pile) oldSize = len(self.pile) validCard = Card(Suit.SPADE, 4) validCard.flip_up() self.pile.push_card(validCard) self.assertEqual(len(self.pile), oldSize + 1, "TestTableauPile.test_pushValidCard: A valid Card \ was not pushed to the pile.")
def test_pushInvalidSuitCard(self): """Tests that push() rejects a Card with an invalid suit.""" print "foundation: test_pushInvalidSuitCard ", invalidSuit = Card(Suit.DIAMOND, Rank.ACE) invalidSuit.flip_up() self.pile.push_card(invalidSuit) self.assertNotIn(invalidSuit, self.pile, "The Foundation pile accepted a card with \ invalid suit.") invalidSuit = Card(Suit.HEART, Rank.ACE) invalidSuit.flip_up() self.pile.push_card(invalidSuit) self.assertNotIn(invalidSuit, self.pile, "The Foundation pile accepted a card with \ invalid suit.")
def test_pushInvalidSuitPile(self): """ Tests that a Foundation pile rejects a pile that is built properly, but the top card is not of the proper color. """ print "tableau: test_pushInvalidSuitPile ", append_cards(self.pile) oldCards = self.pile invalidPile = Pile() for i in range(1,5): card = Card(Suit.DIAMOND, i) if i % 2 == 0 else Card(Suit.SPADE, i) card.flip_up() invalidPile.enqueue(card) self.pile.push_pile(invalidPile) self.assertEqual(self.pile, oldCards, "TestTableauPile.test_pushInvalidSuitPile: A pile \ whose top Card had an invalid color was pushed onto \ the Tableau.")
def test_pushInvalidAlternatingPile(self): """ Tests that a Foundation pile rejects a pile with valid bottom Card but is not alternating in color. """ print "tableau: test_pushInvalidAlternatingPile ", append_cards(self.pile) oldCards = self.pile invalidPile = Pile() for i in range(1,5): card = Card(Suit.SPADE, i) card.flip_up() invalidPile.enqueue(card) self.pile.push_pile(invalidPile) self.assertEqual(self.pile, oldCards, "TestTableauPile.test_pushInvalidAlternatingPile: \ A pile whose top Card had an invalid rank was pushed\ onto the Tableau.")
def test_pushInvalidBuiltPile(self): """ Tests that a Foundation pile rejects a pile with valid bottom Card but is not built properly. """ print "tableau: test_pushInvalidBuiltPile ", append_cards(self.pile) oldCards = Pile(copy.copy(list(self.pile))) invalidPile = Pile() for i in range(1,5): card = Card(Suit.SPADE, i) if i % 2 == 0 else Card(Suit.DIAMOND, i) card.flip_up() invalidPile.enqueue_card(card) card = Card(Suit.CLUB, 6) card.flip_up() invalidPile.push_card(card) self.pile.push_pile(invalidPile) self.assertEqual(self.pile, oldCards, "An invalid pile was pushed to the Tableau.")
def test_pushValidPile(self): """ Tests that a Foundation pile accepts a properly built pile whose bottom card is the proper color and rank. """ print "tableau: test_pushValidPile ", append_cards(self.pile) self.pile.flip_top() oldCards = Pile(copy.copy(list(self.pile))) validPile = Pile() for i in range(1,5): card = Card(Suit.SPADE, i) if i % 2 == 0 else Card(Suit.HEART, i) card.flip_up() validPile.enqueue(card) newCards = copy.copy(validPile) oldCards.extend(newCards) self.pile.push_pile(validPile) self.assertEqual(self.pile, oldCards, "TestTableauPile.test_pushValidPile: A valid pile \ was rejected by the Tableau pile.")
def append_some_cards(pile): """Appends Spades to the pile bottom-up from Ace to seven.""" for i in range(1,7): card = Card(Suit.SPADE, i) card.flip_up() pile.append(card)