def testHasLegalMoves(self): dummy = self.dummyPrompt() deck = p.Deck() # Create a hand with only illegal moves: deck.hand.append(deck.Card('H', '2')) deck.hand.append(deck.Card('H', '3')) deck.hand.append(deck.Card('H', '4')) deck.hand.append(deck.Card('S', '5')) deck.hand.append(deck.Card('S', '6')) deck.hand.append(deck.Card('S', '7')) deck.hand.append(deck.Card('D', '9')) deck.hand.append(deck.Card('D', '10')) deck.hand.append(deck.Card('D', 'J')) deck.hand.append(deck.Card('C', 'Q')) self.assertFalse(deck.hasLegalMoves()) # Create a legal suit move: deck.hand[5] = deck.Card('H', 'A') deck.hand[8] = deck.Card('H', 'K') self.assertTrue(deck.hasLegalMoves()) # Create a legal rank move: deck.hand[8] = deck.Card('S', 'A') self.assertTrue(deck.hasLegalMoves())
def test_convertToTuple(self): testy = pondukapall.Deck() self.assertEqual(testy.convertToTuple("DK"), ('D', 'K')) self.assertEqual(testy.convertToTuple("S3"), ('S', '3')) self.assertEqual(testy.convertToTuple("HA"), ('H', 'A')) self.assertEqual(testy.convertToTuple("C8"), ('C', '8')) self.assertEqual(testy.convertToTuple("D10"), ('D', '10'))
def testRemove(self): # This function does not return a value, dummy = self.dummyPrompt() deck = p.Deck() # Create a hand with an illegal move: deck.hand.append(deck.Card('H', '2')) deck.hand.append(deck.Card('H', '3')) deck.hand.append(deck.Card('H', '4')) deck.hand.append(deck.Card('S', '5')) try: deck.remove('1,2', dummy) except: self.assertTrue(len(deck.hand) == 4) # Create a legal suit move: deck.hand[3] = deck.Card('H', '5') deck.remove('1,2', dummy) self.assertTrue(len(deck.hand) == 2) # Create a legal rank move: deck.hand.append(deck.Card('S', 'A')) deck.hand.append(deck.Card('S', '2')) deck.remove('0:4', dummy) self.assertTrue(len(deck.hand) == 0)
def test_convertToString(self): testy = pondukapall.Deck() self.assertEqual(testy.convertToString(('H', 'J')), "HJ") self.assertEqual(testy.convertToString(('S', 'A')), "SA") self.assertEqual(testy.convertToString(('D', 7)), "D7") self.assertEqual(testy.convertToString(('C', 2)), "C2") self.assertEqual(testy.convertToString(('H', 10)), "H10")
def testCardComparison(self): deck = p.Deck() ah1 = deck.Card('H', 'A') ah2 = deck.Card('H', 'A') self.assertTrue(ah1 == ah2) as1 = deck.Card('S', 'A') self.assertFalse(ah1 == as1)
def test_draw(self): testy = pondukapall.Deck() testy.cards = [('H', 'J'), ('S', 'A'), ('D', 7), ('C', 2), ('H', 10)] self.assertEqual(testy.draw(), ('H', 10)) self.assertEqual(testy.draw(), ('C', 2)) self.assertEqual(testy.draw(), ('D', 7)) self.assertEqual(testy.draw(), ('S', 'A')) self.assertEqual(testy.draw(), ('H', 'J'))
def test_getRank(self): testy = pondukapall.Deck() testy.cards = [('H', 'J'), ('S', 'A'), ('D', 7), ('C', 2), ('H', 10)] self.assertEqual(testy.getRank(0), 'J') self.assertEqual(testy.getRank(1), 'A') self.assertEqual(testy.getRank(2), 7) self.assertEqual(testy.getRank(3), 2) self.assertEqual(testy.getRank(4), 10)
def testDraw(self): dummy = self.dummyPrompt() deck = p.Deck() c1 = len(deck.cards) h1 = len(deck.hand) deck.draw(dummy) c2 = len(deck.cards) + 1 h2 = len(deck.hand) - 1 self.assertTrue(c1 == c2 and h1 == h2)
def testIsEmpty(self): deck = p.Deck() # Here we use an index in the range of len(deck.cards) # because we're popping from deck.cards in each iteration # (=> deck.cards is mutable for the duration of the loop) for i in range(len(deck.cards)): self.assertFalse(deck.isEmpty()) deck.cards.pop() self.assertTrue(deck.isEmpty())
def testCardUnique(self): deck = p.Deck() for c in deck.cards: deck.cards.sort(key=lambda c: c.suit, reverse=True) deck.suits.sort() for s in deck.suits: for f in deck.ranks: d = [d for d in deck.cards if d == deck.Card(s, f)] # Check whether there's exactly one card of each type self.assertTrue(len(d) == 1) deck.cards.remove(d[0]) # Check whether there are any cards that were not popped # from the list in the for-loop. self.assertTrue(len(deck.cards) == 0)
def testDeckSize(self): deck = p.Deck() deckSize = len(deck.suits) * len(deck.ranks) self.assertEqual(len(deck.cards), deckSize)
def test_count(self): testy = pondukapall.Deck() testy.cards = [('H', 'J'), ('S', 'A'), ('D', 7), ('C', 2), ('H', 10)] self.assertEqual(testy.count(), 5)