def test_rank_suit_from_idx(self): rank, suit = RANKS[10], SUITS[3] rank_0, suit_0 = Card.rank_suit_from_idx(int(np.argwhere(Card(rank, suit).state == True))) self.assertEqual(rank, rank_0) self.assertEqual(suit, suit_0) rank, suit = RANKS[4], SUITS[3] rank_0, suit_0 = Card.rank_suit_from_idx(int(np.argwhere(Card(rank, suit).state == True))) self.assertEqual(rank, rank_0) self.assertEqual(suit, suit_0) rank, suit = RANKS[7], SUITS[3] rank_0, suit_0 = Card.rank_suit_from_idx(int(np.argwhere(Card(rank, suit).state == True))) self.assertEqual(rank, rank_0) self.assertEqual(suit, suit_0) rank, suit = RANKS[7], SUITS[2] rank_0, suit_0 = Card.rank_suit_from_idx(int(np.argwhere(Card(rank, suit).state == True))) self.assertEqual(rank, rank_0) self.assertEqual(suit, suit_0) rank, suit = RANKS[7], SUITS[1] rank_0, suit_0 = Card.rank_suit_from_idx(int(np.argwhere(Card(rank, suit).state == True))) self.assertEqual(rank, rank_0) self.assertEqual(suit, suit_0)
def is_not_a_sequence(self): self.assertFalse( is_sequence( cards=[ Card(RANKS[4], SUITS[0]), Card(RANKS[4], SUITS[1]), Card(RANKS[4], SUITS[2]), Card(RANKS[10], SUITS[3]) ] ))
def is_a_sequence(self): self.assertTrue( is_sequence( cards=[ Card(RANKS[4], SUITS[0]), Card(RANKS[5], SUITS[1]), Card(RANKS[6], SUITS[2]), Card(RANKS[7], SUITS[3]) ] ))
def test_stack_to_idx(self): hand = Stack( cards=[ Card(RANKS[4], SUITS[0]), Card(RANKS[4], SUITS[1]), Card(RANKS[4], SUITS[2]), Card(RANKS[10], SUITS[3]) ] ) assert stack_to_idx(hand) == ((5, 5, 5, 11), (1, 2, 3, 4))
def test_evaluate_cards(self): hand = Stack( cards=[ Card(RANKS[0], SUITS[0]), Card(RANKS[2], SUITS[0]), Card(RANKS[3], SUITS[0]), Card(RANKS[5], SUITS[0]) ] ) # For a regular hand, if all cards in hand are of the same suit, then you # get the points. If the starter is also of the same suit you get an # extra point self.assertEqual(evaluate_cards(hand, starter=Card(RANKS[7], SUITS[0])), 9) self.assertEqual(evaluate_cards(hand, starter=Card(RANKS[7], SUITS[1])), 8) # Crib hand needs to have all same suit including the starter, otherwise # you don't get the points for the same suit self.assertEqual(evaluate_cards(hand, starter=Card(RANKS[7], SUITS[0]), is_crib=True), 9) self.assertEqual(evaluate_cards(hand, starter=Card(RANKS[7], SUITS[1]), is_crib=True), 4) hand = Stack(cards=[Card(RANKS[i], SUITS[0]) for i in range(5)]) self.assertEqual(evaluate_cards(hand), 12) hand = Stack(cards=[Card(RANKS[i], SUITS[0]) for i in range(4)]) starter = Card(RANKS[4], SUITS[0]) self.assertEqual(evaluate_cards(hand, starter), 12) hand = Stack(cards=[Card(RANKS[i], SUITS[0]) for i in range(4)]) starter = Card(RANKS[5], SUITS[0]) self.assertEqual(evaluate_cards(hand, starter), 11) hand = Stack(cards=[Card(RANKS[i], SUITS[0]) for i in [1, 1, 2, 3, 4]]) self.assertEqual(evaluate_cards(hand), 15) hand = Stack(cards=[Card(RANKS[i], SUITS[0]) for i in [1, 1, 1, 2, 3]]) self.assertEqual(evaluate_cards(hand), 20) hand = Stack(cards=[Card(RANKS[i], SUITS[0]) for i in [1, 3, 5, 7]]) starter = Card(RANKS[9], SUITS[0]) self.assertEqual(evaluate_cards(hand, starter), 5) hand = Stack(cards=[Card(RANKS[i], SUITS[0]) for i in [1, 3, 5, 7]]) starter = Card(RANKS[9], SUITS[1]) self.assertEqual(evaluate_cards(hand, starter), 4) hand = Stack(cards=[Card(RANKS[i], SUITS[0]) for i in [1, 3, 5, 10]]) self.assertEqual(evaluate_cards(hand, starter=Card(RANKS[-1], SUITS[0])), 6) # Best possible hand hand = Stack( cards=[ Card(RANKS[4], SUITS[0]), Card(RANKS[4], SUITS[1]), Card(RANKS[4], SUITS[2]), Card(RANKS[10], SUITS[3]) ] ) self.assertEqual(evaluate_cards(hand, starter=Card(RANKS[4], SUITS[3])), 29) hand = Stack( cards=[ Card(RANKS[8], SUITS[3]), Card(RANKS[7], SUITS[1]), Card(RANKS[6], SUITS[1]), Card(RANKS[12], SUITS[3]) ] ) self.assertEqual( evaluate_cards(hand, starter=Card(RANKS[3], SUITS[0])), 5 )
def test_card_to_idx(self): self.assertEqual(card_to_idx(Card(RANKS[0], SUITS[2])), (1, 3))
def test_evaluate_play(self): table = Stack( cards=[ Card(RANKS[7], SUITS[1]), Card(RANKS[6], SUITS[1]) ] ) self.assertEqual( evaluate_table(table), 2 ) table = Stack( cards=[ Card(RANKS[8], SUITS[3]), Card(RANKS[8], SUITS[2]), Card(RANKS[8], SUITS[1]), Card(RANKS[8], SUITS[0]) ] ) self.assertEqual( evaluate_table(table), 12 ) table = Stack( cards=[ Card(RANKS[7], SUITS[3]), Card(RANKS[7], SUITS[2]), Card(RANKS[7], SUITS[1]) ] ) self.assertEqual( evaluate_table(table), 6 ) table = Stack( cards=[ Card(RANKS[6], SUITS[3]), Card(RANKS[6], SUITS[2]) ] ) self.assertEqual( evaluate_table(table), 2 ) table = Stack( cards=[ Card(RANKS[10], SUITS[3]), Card(RANKS[4], SUITS[3]), Card(RANKS[7], SUITS[3]), Card(RANKS[7], SUITS[2]), Card(RANKS[7], SUITS[1]) ] ) self.assertEqual( evaluate_table(table), 6 ) table = Stack( cards=[ Card(RANKS[10], SUITS[3]), Card(RANKS[4], SUITS[3]), Card(RANKS[6], SUITS[3]), Card(RANKS[6], SUITS[2]) ] ) self.assertEqual( evaluate_table(table), 2 ) # Run tests table = Stack( cards=[ Card(RANKS[8], SUITS[3]), Card(RANKS[6], SUITS[3]), Card(RANKS[4], SUITS[3]), Card(RANKS[5], SUITS[3]), Card(RANKS[7], SUITS[2]) ] ) self.assertEqual( evaluate_table(table), 5 ) table = Stack( cards=[ Card(RANKS[8], SUITS[3]), Card(RANKS[6], SUITS[3]), Card(RANKS[4], SUITS[3]), Card(RANKS[5], SUITS[3]) ] ) self.assertEqual( evaluate_table(table), 3 )