def test_when_playing_multiple_cards_on_the_first_play_then_do_not_throw_exception(self): cards = [ PresidentCard(HEARTS, '3'), PresidentCard(DIAMONDS, '3'), ] last_played = None game_settings.validate_cards(cards, last_played)
def test_when_last_play_is_one_card_and_one_trump_card_is_played_then_do_not_throw_exception(self): cards = [ PresidentCard(HEARTS, TRUMP_CARD_SHORT_NAME), ] last_played = [ PresidentCard(HEARTS, '3'), ] game_settings.validate_cards(cards, last_played)
def test_when_multiple_cards_are_played_and_they_are_the_same_rank_then_do_not_throw_exception(self): cards = [ PresidentCard(HEARTS, '4'), PresidentCard(DIAMONDS, '4'), ] last_played = [ PresidentCard(HEARTS, '3'), PresidentCard(CLUBS, '3'), ] game_settings.validate_cards(cards, last_played)
def test_current_play_has_same_number_as_last_play_then_do_not_throw_exception(self): cards = [ PresidentCard(HEARTS, '4'), PresidentCard(SPADES, '4'), ] last_played = [ PresidentCard(HEARTS, '3'), PresidentCard(CLUBS, '3'), ] game_settings.validate_cards(cards, last_played)
def test_when_player_plays_cards_then_cards_played_is_updated_to_cards( self, mocked_player): cards_played = [ PresidentCard(HEARTS, '3'), PresidentCard(SPADES, '3'), ] mocked_player.play_turn.return_value = cards_played turn = Turn(player=mocked_player) turn.play_turn() self.assertListEqual(cards_played, turn.cards_played)
def test_when_new_play_has_lower_rank_than_last_play_then_throw_exception(self): cards = [ PresidentCard(HEARTS, '4'), ] last_played = [ PresidentCard(HEARTS, '5'), ] with self.assertRaises(Exception) as context: game_settings.validate_cards(cards, last_played) expected_error = 'Cannot play a lower card than the last player.' self.assertEqual(expected_error, str(context.exception))
def test_when_last_play_is_three_card_and_current_play_is_one_trump_then_throw_exception(self): cards = [ PresidentCard(HEARTS, TRUMP_CARD_SHORT_NAME) ] last_played = [ PresidentCard(HEARTS, '3'), PresidentCard(CLUBS, '3'), PresidentCard(DIAMONDS, '3'), ] with self.assertRaises(Exception) as context: game_settings.validate_cards(cards, last_played) expected_error = 'When playing trump cards, you must play one less than previous play.' self.assertEqual(expected_error, str(context.exception))
def test_when_multiple_cards_are_played_and_they_are_not_the_same_rank_then_throw_exception(self): cards = [ PresidentCard(HEARTS, '4'), PresidentCard(DIAMONDS, '5'), ] last_played = [ PresidentCard(HEARTS, '3'), PresidentCard(CLUBS, '3'), ] with self.assertRaises(Exception) as context: game_settings.validate_cards(cards, last_played) expected_error = 'When playing multiple cards they must be the same rank.' self.assertEqual(expected_error, str(context.exception))
def test_when_current_play_is_not_trump_but_different_number_than_last_play_then_throw_exception(self): cards = [ PresidentCard(HEARTS, '4'), PresidentCard(DIAMONDS, '4'), PresidentCard(SPADES, '4'), ] last_played = [ PresidentCard(HEARTS, '3'), PresidentCard(CLUBS, '3'), ] with self.assertRaises(Exception) as context: game_settings.validate_cards(cards, last_played) expected_error = 'Expected 2 cards but 3 were played.' self.assertEqual(expected_error, str(context.exception))
def test_when_validate_cards_for_no_cards_played_then_do_not_throw_exception(self): cards = [] last_played = [ PresidentCard(HEARTS, '3'), ] game_settings.validate_cards(cards, last_played)
def test_when_initalize_PresidentCard_for_valid_suit_and_shot_name_then_card_is_created( self): suit = HEARTS short_name = '2' card = PresidentCard(suit, short_name) self.assertNotEqual(None, card.president_rank)
def test_when_player_plays_cards_then_player_passed_is_false( self, mocked_player): mocked_player.play_turn.return_value = [PresidentCard(HEARTS, '3')] turn = Turn(player=mocked_player) turn.play_turn() self.assertEqual(False, turn.player_passed)
def test_when_initalize_PresidentCard_for_invalid_short_name_then_throw_exception( self): suit = HEARTS short_name = 'Invalid Name' with self.assertRaises(Exception) as context: PresidentCard(suit, short_name) expected_error = 'There is no card for short name \"Invalid Name\".' self.assertEqual(expected_error, str(context.exception))
def test_when_initalize_PresidentCard_for_invalid_suit_then_throw_exception( self): suit = 'FAKE SUIT' short_name = '2' with self.assertRaises(Exception) as context: PresidentCard(suit, short_name) expected_error = 'FAKE SUIT is not a supported suit.' self.assertEqual(expected_error, str(context.exception))
def test_when_class_has_previous_turn_then_last_turn_is_the_previous_turn( self, mocked_turn): cards = [PresidentCard(HEARTS, '3')] mocked_turn.cards_played.return_value = cards players = [ StandardPlayer('Player1'), StandardPlayer('Player2'), ] game_round = Round(players=players, start_player_index=0) game_round.turns = [mocked_turn] self.assertEqual(cards, game_round.last_played)
def test_when_passed_start_card_then_is_start_card_returns_true(self): card = PresidentCard(START_CARD_SUIT, START_CARD_SHORT_NAME) result = game_settings.is_start_card(card) self.assertEqual(True, result)
def test_when_passed_card_with_different_suit_then_is_start_card_returns_false(self): card = PresidentCard(HEARTS, START_CARD_SHORT_NAME) result = game_settings.is_start_card(card) self.assertEqual(False, result)
def test_when_passed_card_with_different_rank_then_is_start_card_returns_false(self): card = PresidentCard(START_CARD_SUIT, '7') result = game_settings.is_start_card(card) self.assertEqual(False, result)
def test_when_passed_trump_card_then_is_trump_card_returns_true(self): card = PresidentCard(HEARTS, TRUMP_CARD_SHORT_NAME) result = game_settings.is_trump_card(card) self.assertEqual(True, result)
def test_when_passed_card_other_than_trump_rank_then_is_trump_card_returns_false(self): card = PresidentCard(HEARTS, '7') result = game_settings.is_trump_card(card) self.assertEqual(False, result)
def test_when_sort_multiple_president_cards_then_should_sort_by(self): card = PresidentCard(START_CARD_SUIT, '7') result = game_settings.is_start_card(card) self.assertEqual(False, result)