def test_get_winner(self): trick_history = [ Play(Player(1), Card(value='K', suit=SPADES)), Play(Player(2), Card(value='10', suit=CLUBS)), Play(Player(3), Card(value='9', suit=SPADES)), Play(Player(3), Card(value='Q', suit=SPADES)), ] self.assertEqual(trick_history[0].player, get_winner(trick_history, HEARTS))
def test_get_lead_suit(self): trump_caller = Player('George') dealer = Player('Jack') card_picked_up = Card(value='9', suit=DIAMONDS) rh = RoundHistory(trump_caller, dealer, card_picked_up) aj = Player('AJ') play = Play(aj, Card(value='10', suit=CLUBS)) rh.add_play(play) play2 = Play(trump_caller, Card(value='Q', suit=HEARTS)) rh.add_play(play2) self.assertEqual(rh.get_lead_suit(), CLUBS)
def test_follows_suit(self): p = Player('Sam') p.deal_hand( Hand([ Card(value='Q', suit=SPADES), Card(value='9', suit=DIAMONDS), Card(value='10', suit=CLUBS), Card(value='K', suit=SPADES), Card(value='Q', suit=DIAMONDS) ])) round_history = MagicMock() round_history.get_lead_suit.return_value = CLUBS self.assertEqual(CLUBS, p.get_card_to_play(round_history).suit)
def test_no_field_plays_best_card(self): expected = Card('K', 'h') hand = [ Card('A', 'd'), expected, Card('J', 'c'), Card('Q', 'c'), Card('K', 'c') ] trump = 'h' field = [] player_id = 1 result = play_card_cautious(hand, trump, field, player_id) self.assertEqual(result, expected)
def test_no_lead_suit(self): trump = 'h' hand = [ Card('K', 'h'), Card('A', 'd'), Card('J', 'd'), Card('Q', 'c'), Card('K', 'c') ] desired_hand = [ Card('J', 'd'), Card('K', 'h'), Card('A', 'd'), Card('K', 'c'), Card('Q', 'c') ] sorted_cards = sorted(hand, key=cmp_to_key( Sorter(None, trump).compare_cards)) self.assertEqual(sorted_cards, desired_hand)
def test_get_more_valuable_card_trump_left(self): vc = get_more_valuable_card(Card(value='A', suit=HEARTS), Card(value='J', suit=DIAMONDS), HEARTS) self.assertEqual(Card(value='J', suit=DIAMONDS), vc) vc = get_more_valuable_card(Card(value='J', suit=DIAMONDS), Card(value='A', suit=HEARTS), HEARTS) self.assertEqual(Card(value='J', suit=DIAMONDS), vc)
def test_get_more_valuable_card_trump_nontrump(self): vc = get_more_valuable_card(Card(value='9', suit=HEARTS), Card(value='A', suit=SPADES), HEARTS) self.assertEqual(Card(value='9', suit=HEARTS), vc) vc = get_more_valuable_card(Card(value='A', suit=SPADES), Card(value='9', suit=HEARTS), HEARTS) self.assertEqual(Card(value='9', suit=HEARTS), vc)
def test_with_field_no_teammate_cant_win_plays_worst_card(self): expected = Card('J', 's') hand = [ Card('A', 'd'), expected, Card('K', 'd'), Card('Q', 's'), Card('K', 's') ] trump = 'h' field = [(0, Card('9', 'c'))] player_id = 1 result = play_card_cautious(hand, trump, field, player_id) self.assertEqual(result, expected)
def test_with_field_teammate_losing_can_win_plays_best_card(self): expected = Card('J', 'h') hand = [ Card('J', 'd'), expected, Card('A', 'd'), Card('Q', 'h'), Card('K', 'h') ] trump = 'h' field = [ (0, Card('9', 'c')), (1, Card('T', 'c')) ] player_id = 2 result = play_card_cautious(hand, trump, field, player_id) self.assertEqual(result, expected)
def test_lead_suit_does_equal_trump(self): trump = 'h' lead_suit = 'h' expected = { Card('9', 'h'): 100, Card('T', 'h'): 200, Card('J', 'h'): 1500, Card('Q', 'h'): 400, Card('K', 'h'): 500, Card('A', 'h'): 600, Card('9', 'c'): 1, Card('T', 'c'): 2, Card('J', 'c'): 3, Card('Q', 'c'): 4, Card('K', 'c'): 5, Card('A', 'c'): 6, Card('9', 'd'): 1, Card('T', 'd'): 2, Card('J', 'd'): 1000, Card('Q', 'd'): 4, Card('K', 'd'): 5, Card('A', 'd'): 6, Card('9', 's'): 1, Card('T', 's'): 2, Card('J', 's'): 3, Card('Q', 's'): 4, Card('K', 's'): 5, Card('A', 's'): 6 } result = calculate_heuristics(trump, lead_suit) for suit in c_suits: for value in c_values: card = Card(value, suit) self.assertEqual(result[card], expected[card])