Beispiel #1
0
    def test_deal_with_no_response(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._state = controller.States.DEALING
        controller._no_response = True
        controller._discarded = []
        controller._to_move = controller._player1
        controller._player1.cards = {DurakCard('JH')}
        controller._player2.cards = set()
        controller._deck = []
        controller._on_table = Table([DurakCard('6S'), DurakCard('6H')])
        controller._on_table.given_more = {DurakCard('7S'), DurakCard('7H')}
        controller._logger_enabled = False

        controller.deal()

        self.assertItemsEqual(controller._player2.cards, {
            DurakCard('6S'),
            DurakCard('6H'),
            DurakCard('7S'),
            DurakCard('7H')
        })
        self.assertFalse(controller._no_response)
        self.assertEqual(controller._to_move, controller._player1)
        self.assertEqual(controller._state, controller.States.MOVING)
Beispiel #2
0
    def test_successful_register_give_more(self):
        controller = GameController()
        controller._state = controller.States.GIVING_MORE
        controller._no_response = True
        controller._to_move = controller._player1
        controller._deck = [DurakCard('JH')]
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(cards=(DurakCard('AC'),
                                                   DurakCard('6S'),
                                                   DurakCard('6H')),
                                            trump=controller._trump)
        controller._player2.cards = CardSet(cards=(DurakCard('7C'),
                                                   DurakCard('7H'),
                                                   DurakCard('7D')),
                                            trump=controller._trump)
        controller._on_table = Table([DurakCard('6D')])

        controller.register_give_more([DurakCard('6S'), DurakCard('6H')])

        self.assertItemsEqual(controller._player1.cards, [DurakCard('AC')])
        self.assertSequenceEqual(controller._on_table, [DurakCard('6D')])
        self.assertItemsEqual(
            controller._on_table.given_more,
            [DurakCard('6S'), DurakCard('6H')])
        self.assertEqual(controller._state, controller.States.DEALING)
Beispiel #3
0
    def test_register_give_more_is_error_if_player_can_not_give_these_cards(
            self):
        controller = GameController()
        controller._state = controller.States.GIVING_MORE
        controller._no_response = True
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(cards=(DurakCard('AC'),
                                                   DurakCard('AH'),
                                                   DurakCard('6H')),
                                            trump=controller._trump)
        controller._player2.cards = CardSet(cards=(
            DurakCard('7C'),
            DurakCard('7H'),
            DurakCard('7D'),
            DurakCard('7S'),
        ),
                                            trump=controller._trump)
        controller._on_table = [DurakCard('6D')]

        with self.assertRaises(exes.InvalidCard):
            controller.register_give_more(
                [DurakCard('AC'),
                 DurakCard('AH'),
                 DurakCard('6H')])
Beispiel #4
0
    def test_successful_register_give_more(self):
        controller = GameController()
        controller._state = controller.States.GIVING_MORE
        controller._no_response = True
        controller._to_move = controller._player1
        controller._deck = [DurakCard('JH')]
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(
            cards=(DurakCard('AC'), DurakCard('6S'), DurakCard('6H')),
            trump=controller._trump
        )
        controller._player2.cards = CardSet(
            cards=(DurakCard('7C'), DurakCard('7H'), DurakCard('7D')),
            trump=controller._trump
        )
        controller._on_table = Table([DurakCard('6D')])

        controller.register_give_more([DurakCard('6S'), DurakCard('6H')])

        self.assertItemsEqual(controller._player1.cards, [DurakCard('AC')])
        self.assertSequenceEqual(controller._on_table, [DurakCard('6D')])
        self.assertItemsEqual(
            controller._on_table.given_more, [DurakCard('6S'), DurakCard('6H')]
        )
        self.assertEqual(controller._state, controller.States.DEALING)
Beispiel #5
0
    def test_deal_with_no_response(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._state = controller.States.DEALING
        controller._no_response = True
        controller._discarded = []
        controller._to_move = controller._player1
        controller._player1.cards = {DurakCard('JH')}
        controller._player2.cards = set()
        controller._deck = []
        controller._on_table = Table([DurakCard('6S'), DurakCard('6H')])
        controller._on_table.given_more = {DurakCard('7S'), DurakCard('7H')}
        controller._logger_enabled = False

        controller.deal()

        self.assertItemsEqual(
            controller._player2.cards,
            {
                DurakCard('6S'),
                DurakCard('6H'),
                DurakCard('7S'),
                DurakCard('7H')
            }
        )
        self.assertFalse(controller._no_response)
        self.assertEqual(controller._to_move, controller._player1)
        self.assertEqual(controller._state, controller.States.MOVING)
Beispiel #6
0
    def test_register_give_more_is_error_if_player_can_not_give_these_cards(self):
        controller = GameController()
        controller._state = controller.States.GIVING_MORE
        controller._no_response = True
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(
            cards=(DurakCard('AC'), DurakCard('AH'), DurakCard('6H')),
            trump=controller._trump
        )
        controller._player2.cards = CardSet(
            cards=(
                DurakCard('7C'),
                DurakCard('7H'),
                DurakCard('7D'),
                DurakCard('7S'),
            ),
            trump=controller._trump
        )
        controller._on_table = [DurakCard('6D')]

        with self.assertRaises(exes.InvalidCard):
            controller.register_give_more([
                DurakCard('AC'), DurakCard('AH'), DurakCard('6H')
            ])
Beispiel #7
0
    def test_register_give_more_with_no_cards_goes_to_dealing(self):
        controller = GameController()
        controller._state = controller.States.GIVING_MORE
        controller._no_response = True

        controller.register_give_more([])

        self.assertEqual(controller.state, controller.States.DEALING)
Beispiel #8
0
    def test_register_give_more_with_no_cards_goes_to_dealing(self):
        controller = GameController()
        controller._state = controller.States.GIVING_MORE
        controller._no_response = True

        controller.register_give_more([])

        self.assertEqual(controller.state, controller.States.DEALING)
Beispiel #9
0
    def test_deal_cards_and_return_value(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._state = controller.States.DEALING
        controller._no_response = False
        controller._discarded = []
        controller._to_move = controller._player1
        controller._player1.cards = {DurakCard('6S'), DurakCard('6H')}
        controller._player2.cards = {DurakCard('7S'), DurakCard('7H')}
        controller._deck = [
            DurakCard('AS'),
            DurakCard('AH'),
            DurakCard('KS'),
            DurakCard('KH'),
            DurakCard('QS'),
            DurakCard('QH'),
            DurakCard('JS'),
            DurakCard('JH'),
            DurakCard('TS'),
            DurakCard('TH'),
        ]
        controller._on_table = Table()
        controller._logger_enabled = False

        return_value = controller.deal()

        self.assertItemsEqual(
            controller._player1.cards, [
                DurakCard('6S'),
                DurakCard('6H'),
                DurakCard('AS'),
                DurakCard('AH'),
                DurakCard('KS'),
                DurakCard('KH'),
            ]
        )
        self.assertItemsEqual(
            controller._player2.cards, [
                DurakCard('7S'),
                DurakCard('7H'),
                DurakCard('QS'),
                DurakCard('QH'),
                DurakCard('JS'),
                DurakCard('JH'),
            ]
        )
        self.assertSequenceEqual(
            controller._deck, [DurakCard('TS'), DurakCard('TH')]
        )
        self.assertDictEqual(return_value, {
            'player1_cards': controller._player1.cards - {DurakCard('6S'), DurakCard('6H')},
            'player2_cards': controller._player2.cards - {DurakCard('7S'), DurakCard('7H')},
        })
Beispiel #10
0
    def test_deal_cards_and_return_value(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._state = controller.States.DEALING
        controller._no_response = False
        controller._discarded = []
        controller._to_move = controller._player1
        controller._player1.cards = {DurakCard('6S'), DurakCard('6H')}
        controller._player2.cards = {DurakCard('7S'), DurakCard('7H')}
        controller._deck = [
            DurakCard('AS'),
            DurakCard('AH'),
            DurakCard('KS'),
            DurakCard('KH'),
            DurakCard('QS'),
            DurakCard('QH'),
            DurakCard('JS'),
            DurakCard('JH'),
            DurakCard('TS'),
            DurakCard('TH'),
        ]
        controller._on_table = Table()
        controller._logger_enabled = False

        return_value = controller.deal()

        self.assertItemsEqual(controller._player1.cards, [
            DurakCard('6S'),
            DurakCard('6H'),
            DurakCard('AS'),
            DurakCard('AH'),
            DurakCard('KS'),
            DurakCard('KH'),
        ])
        self.assertItemsEqual(controller._player2.cards, [
            DurakCard('7S'),
            DurakCard('7H'),
            DurakCard('QS'),
            DurakCard('QH'),
            DurakCard('JS'),
            DurakCard('JH'),
        ])
        self.assertSequenceEqual(
            controller._deck,
            [DurakCard('TS'), DurakCard('TH')])
        self.assertDictEqual(
            return_value, {
                'player1_cards': controller._player1.cards -
                {DurakCard('6S'), DurakCard('6H')},
                'player2_cards': controller._player2.cards -
                {DurakCard('7S'), DurakCard('7H')},
            })
Beispiel #11
0
    def test_register_give_more_is_error_if_max_count_is_exceeded(self):
        controller = GameController()
        controller._state = controller.States.GIVING_MORE
        controller._no_response = True
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(cards=(DurakCard('AC'),
                                                   DurakCard('AH')),
                                            trump=controller._trump)
        controller._player2.cards = CardSet(cards=(DurakCard('7C'), ),
                                            trump=controller._trump)
        controller._on_table = [DurakCard('6D')]

        with self.assertRaises(exes.TooMuchGiveMoreCards):
            controller.register_give_more([DurakCard('6S'), DurakCard('6H')])
Beispiel #12
0
    def test_register_give_more_is_error_if_max_count_is_exceeded(self):
        controller = GameController()
        controller._state = controller.States.GIVING_MORE
        controller._no_response = True
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(
            cards=(DurakCard('AC'), DurakCard('AH')), trump=controller._trump
        )
        controller._player2.cards = CardSet(
            cards=(DurakCard('7C'),), trump=controller._trump
        )
        controller._on_table = [DurakCard('6D')]

        with self.assertRaises(exes.TooMuchGiveMoreCards):
            controller.register_give_more([DurakCard('6S'), DurakCard('6H')])
Beispiel #13
0
    def test_deal_clears_the_table(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._state = controller.States.DEALING
        controller._no_response = True
        controller._discarded = []
        controller._to_move = controller._player1
        controller._player1.cards = set()
        controller._player2.cards = set()
        controller._deck = []
        controller._on_table = Table([DurakCard('6S'), DurakCard('6H')])
        controller._on_table.given_more = {DurakCard('7S'), DurakCard('7H')}
        controller._logger_enabled = False

        controller.deal()

        self.assertSequenceEqual(controller._on_table, [])
        self.assertItemsEqual(controller._on_table.given_more, set())
Beispiel #14
0
    def test_deal_clears_the_table(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._state = controller.States.DEALING
        controller._no_response = True
        controller._discarded = []
        controller._to_move = controller._player1
        controller._player1.cards = set()
        controller._player2.cards = set()
        controller._deck = []
        controller._on_table = Table([DurakCard('6S'), DurakCard('6H')])
        controller._on_table.given_more = {DurakCard('7S'), DurakCard('7H')}
        controller._logger_enabled = False

        controller.deal()

        self.assertSequenceEqual(controller._on_table, [])
        self.assertItemsEqual(controller._on_table.given_more, set())
Beispiel #15
0
    def test_deal_no_cards_needed(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._state = controller.States.DEALING
        controller._no_response = False
        controller._discarded = []
        controller._to_move = controller._player1
        controller._player1.cards = {
            DurakCard('6S'),
            DurakCard('6H'),
            DurakCard('8S'),
            DurakCard('8H'),
            DurakCard('9S'),
            DurakCard('9H')
        }
        controller._player2.cards = {DurakCard('7S'), DurakCard('7H')}
        controller._deck = [
            DurakCard('AS'),
            DurakCard('AH'),
            DurakCard('KS'),
            DurakCard('KH'),
            DurakCard('QS'),
            DurakCard('QH'),
            DurakCard('JS'),
            DurakCard('JH'),
            DurakCard('TS'),
            DurakCard('TH'),
        ]
        controller._on_table = Table()
        controller._logger_enabled = False

        controller.deal()

        self.assertItemsEqual(
            controller._player1.cards, {
                DurakCard('6S'),
                DurakCard('6H'),
                DurakCard('8S'),
                DurakCard('8H'),
                DurakCard('9S'),
                DurakCard('9H')
            }
        )
Beispiel #16
0
    def test_deal_no_cards_needed(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._state = controller.States.DEALING
        controller._no_response = False
        controller._discarded = []
        controller._to_move = controller._player1
        controller._player1.cards = {
            DurakCard('6S'),
            DurakCard('6H'),
            DurakCard('8S'),
            DurakCard('8H'),
            DurakCard('9S'),
            DurakCard('9H')
        }
        controller._player2.cards = {DurakCard('7S'), DurakCard('7H')}
        controller._deck = [
            DurakCard('AS'),
            DurakCard('AH'),
            DurakCard('KS'),
            DurakCard('KH'),
            DurakCard('QS'),
            DurakCard('QH'),
            DurakCard('JS'),
            DurakCard('JH'),
            DurakCard('TS'),
            DurakCard('TH'),
        ]
        controller._on_table = Table()
        controller._logger_enabled = False

        controller.deal()

        self.assertItemsEqual(
            controller._player1.cards, {
                DurakCard('6S'),
                DurakCard('6H'),
                DurakCard('8S'),
                DurakCard('8H'),
                DurakCard('9S'),
                DurakCard('9H')
            })
Beispiel #17
0
    def test_deal_with_response(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._state = controller.States.DEALING
        controller._no_response = False
        controller._discarded = []
        controller._to_move = controller._player1
        controller._player1.cards = {DurakCard('JH')}
        controller._player2.cards = {DurakCard('JS')}
        controller._deck = []
        controller._on_table = Table([DurakCard('6S'), DurakCard('6H')])
        controller._logger_enabled = False

        controller.deal()

        self.assertSequenceEqual(
            controller._discarded,
            [DurakCard('6S'), DurakCard('6H')])
        self.assertEqual(controller._to_move, controller._player2)
        self.assertEqual(controller._state, controller.States.MOVING)
Beispiel #18
0
    def test_deal_with_response(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._state = controller.States.DEALING
        controller._no_response = False
        controller._discarded = []
        controller._to_move = controller._player1
        controller._player1.cards = {DurakCard('JH')}
        controller._player2.cards = {DurakCard('JS')}
        controller._deck = []
        controller._on_table = Table([DurakCard('6S'), DurakCard('6H')])
        controller._logger_enabled = False

        controller.deal()

        self.assertSequenceEqual(
            controller._discarded, [DurakCard('6S'), DurakCard('6H')]
        )
        self.assertEqual(controller._to_move, controller._player2)
        self.assertEqual(controller._state, controller.States.MOVING)
Beispiel #19
0
 def test_register_give_more_is_error_if_state_is_not_giving_more(self):
     controller = GameController()
     controller._state = controller.States.MOVING
     controller._no_response = True
     with self.assertRaises(exes.InvalidAction):
         controller.register_give_more([DurakCard('AC')])
Beispiel #20
0
 def test_register_give_more_is_error_if_state_is_not_giving_more(self):
     controller = GameController()
     controller._state = controller.States.MOVING
     controller._no_response = True
     with self.assertRaises(exes.InvalidAction):
         controller.register_give_more([DurakCard('AC')])