Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_cards_from_ranks(self):
deck = init_54_deck()
player = Player(0)
player.hand = deck
test_ranks = ['A', '2', '3']
chosen_cards, remained_cards = get_cards_from_ranks(player, test_ranks)
self.assertEqual(len(chosen_cards), 12)
for card in chosen_cards:
flag = True
if card.rank in test_ranks:
flag = False
self.assertFalse(flag)
self.assertEqual(len(remained_cards), len(deck) - 12)
self.assertEqual(len(chosen_cards), 12)
def test_take_out_cards(self):
cards = init_54_deck()
remove_cards = [Card('S', 'A'), Card('BJ', '')]
res = take_out_cards(cards, remove_cards)
flag = False
for card in res:
if card.get_index() == 'SA' or card.get_index == 'BJ':
flag = True
self.assertFalse(flag)
self.assertEqual(len(cards), len(init_54_deck()) - 2)
def test_is_in_cards(self):
deck54 = init_54_deck()
deck_standard = init_standard_deck()
deck54_plus_BJ = init_54_deck()
deck54_plus_BJ.append(Card('BJ', ''))
self.assertTrue(is_in_cards(deck54, deck_standard))
self.assertTrue(is_in_cards(deck54, [Card('BJ', ''), Card('RJ', '')]))
self.assertFalse(is_in_cards(deck54, [Card('BJ', ''), Card('BJ', '')]))
self.assertFalse(is_in_cards(deck54, [Card('BJ', ''), Card('BJ', ''), Card('D', '3')]))
self.assertTrue(is_in_cards(deck54_plus_BJ, [Card('BJ', ''), Card('BJ', ''), Card('D', '3')]))
def test_take_out_cards(self):
cards = init_54_deck()
remove_cards = [Card('S', 'A'), Card('BJ', '')]
res = take_out_cards(cards, remove_cards)
flag = False
for card in res:
if card.get_index() == 'SA' or card.get_index == 'BJ':
flag = True
self.assertFalse(flag)
self.assertEqual(len(cards), len(init_54_deck()) - 2)
def test_is_in_cards(self):
deck54 = init_54_deck()
deck_standard = init_standard_deck()
deck54_plus_BJ = init_54_deck()
deck54_plus_BJ.append(Card('BJ', ''))
self.assertTrue(is_in_cards(deck54, deck_standard))
self.assertTrue(is_in_cards(deck54, [Card('BJ', ''), Card('RJ', '')]))
self.assertFalse(is_in_cards(deck54, [Card('BJ', ''), Card('BJ', '')]))
self.assertFalse(is_in_cards(deck54, [Card('BJ', ''), Card('BJ', ''), Card('D', '3')]))
self.assertTrue(is_in_cards(deck54_plus_BJ, [Card('BJ', ''), Card('BJ', ''), Card('D', '3')]))
def test_get_random_cards(self):
hand = init_54_deck()
num = 10
chosen_cards, remained_cards = get_random_cards(hand, num)
self.assertEqual(len(chosen_cards), num)
self.assertEqual(len(remained_cards), len(hand) - num)
with self.assertRaises(AssertionError):
get_random_cards(hand, 1000)
with self.assertRaises(AssertionError):
get_random_cards(hand, -1)
def test_init_54_deck(self):
self.assertEqual(len(init_54_deck()), 54)
def __init__(self):
'''Give dealer the deck
Notes:
1. deck with 54 cards including black joker and red joker
'''
super().__init__()
self.deck = init_54_deck()
self.deck.sort(key=functools.cmp_to_key(doudizhu_sort_card))
self.landlord = None