Esempio n. 1
0
    def test_interrogate_lets_you_cancel_and_do_nothing(self):
        try:
            old_raw_input = raw_input
            Interactive.raw_input = mock_raw_input('1', '3L', 'cancel')

            player = HumanPlayer('joe')
            tom = AIPlayer('tom')

            state = GameState()
            state.current_player = player
            state.players = [player, tom]
            state.history = []
            state.question_cards = [(1, 'L'), (3, 'L'), (7, 'L')]

            with captured_output() as (out, err):
                turn_ended = interrogate_command(state)

            self.assertEqual('Interrogate\n'
                             'Question cards: 1L 3L 7L', output(out))
            self.assertEqual(0, len(state.history))
            self.assertFalse(turn_ended)
        finally:
            Interactive.raw_input = old_raw_input
Esempio n. 2
0
    def test_print_history(self):
        tom = HumanPlayer('Tom')
        juanpedro = HumanPlayer('Juan-Pedro')
        joe = HumanPlayer('Joe')
        history = [{'turn': 1, 'player': tom, 'opponent': juanpedro,
                    'range': Range((1, 'L'), (5, 'L')), 'result': 2, 'action': 'interrogate'},
                   {'turn': 2, 'player': joe, 'opponent': tom,
                    'range': Range((6, '$'), (6, '$'), choice='suit'), 'result': 0, 'action': 'interrogate'},
                   {'turn': 3, 'player': juanpedro, 'opponent': tom,
                    'range': Range((3, 'L'), (3, 'H')), 'result': 1, 'action': 'secret'},
                   {'turn': 4, 'player': tom, 'opponent': juanpedro,
                    'range': Range((4, '$'), (7, '$')), 'result': 0, 'action': 'secret'},
                   {'turn': 5, 'player': joe, 'opponent': tom,
                    'range': Range((9, 'H'), (3, 'H')), 'result': 4, 'action': 'secret'}]
        accusations = [{'player': tom, 'accused': juanpedro, 'cards': [(8, 'H'), (3, '$')], 'outcome': 'incorrect'},
                       {'player': juanpedro, 'accused': joe, 'cards': [(7, 'H'), (5, '$')], 'outcome': 'correct'}]

        state = GameState()
        state.history = history
        state.accusations = accusations
        state.current_player = juanpedro

        with captured_output() as (out, err):
            self.assertFalse(print_history(state))

        self.assertEqual('History\n'
                         'Turn  Player      Opponent    Range          Result  Note    \n'
                         '1     Tom         Juan-Pedro  1L->5L         2               \n'
                         '2     Joe         Tom         6$->6$ [suit]  0               \n'
                         '3     Juan-Pedro  Tom         3L->3H         1       (Secret)\n'
                         '4     Tom         Juan-Pedro  4$->7$         0       (Secret)\n'
                         '5     Joe         Tom         *************  ******  (Secret)\n'
                         '\n'
                         'Accusations\n'
                         '      Tom         Juan-Pedro  8H 3$          incorrect\n'
                         '      Juan-Pedro  Joe         7H 5$          correct',
                         output(out))