"""Unittest for roll_dice.py."""

import unittest
from unittest import mock

import roll_dice
import player_class


class TestRollDice(unittest.TestCase):
    """Test class for rolling the dice."""

    @mock.patch('roll_dice.input', create=True)
    def test_roll(self, mocked_input):
        """Testing for input '1'."""
        mocked_input.side_effect = ['1']
        players = ([player_class.Player("Carl", 0, [], [0, 0, 1, 0]),
                    player_class.Player("John", 0, [], [0, 1, 1, 0]),
                    player_class.Player("Mike", 0, [], [0, 0, 1, 0, 1, 1, 1]),
                    player_class.Player("Kevin", 0, [], [0, 0, 0, 1, 0])])

        result = roll_dice.Roll.roll(players, 1, False)
        self.assertEqual(result, (False, False))

    # testing for input '2'.
    @mock.patch('roll_dice.input', create=True)
    def test_roll2(self, mocked_input):
        """Testing for input '2'."""
        mocked_input.side_effect = ['2']
        players = ([player_class.Player("Carl", 0, [], [0, 0, 1, 0]),
                    player_class.Player("John", 0, [], [0, 1, 1, 0]),
                    player_class.Player("Mike", 0, [], [0, 0, 1, 0, 1, 1, 1]),
                    player_class.Player("Kevin", 0, [], [0, 0, 0, 1, 0])])

        result = roll_dice.Roll.roll(players, 1, False)
        self.assertEqual(result, (True, False))

    # testing for input '3'.
    @mock.patch('roll_dice.input', create=True)
    def test_roll3(self, mocked_input):
        """Testing for input '3'."""
        mocked_input.side_effect = ['3']
        players = ([player_class.Player("Carl", 0, [], [0, 0, 1, 0]),
                    player_class.Player("John", 0, [], [0, 1, 1, 0]),
                    player_class.Player("Mike", 0, [], [0, 0, 1, 0, 1, 1, 1]),
                    player_class.Player("Kevin", 0, [], [0, 0, 0, 1, 0])])

        result = roll_dice.Roll.roll(players, 1, False)
        self.assertEqual(result, (False, True))

    # testing for other input. (needs fix)
    @mock.patch('roll_dice.input', create=True)
    def test_roll4(self, mocked_input):
        """Testing for input '4'."""
        mocked_input.side_effect = ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4' '4', '4', '4', '4']
        players = ([player_class.Player("Carl", 0, [], [0, 0, 1, 0]),
                    player_class.Player("John", 0, [], [0, 1, 1, 0]),
                    player_class.Player("Mike", 0, [], [0, 0, 1, 0, 1, 1, 1]),
                    player_class.Player("Kevin", 0, [], [0, 0, 0, 1, 0])])

        result = roll_dice.Roll.roll(players, 1, False)

        self.assertEqual(result, (False, False))

    def test_play(self):
        """Testing that the return value of the function play is always correct."""
        result = roll_dice.Roll.play_ai(11, 4)
        self.assertEqual(result, 1)

        result = roll_dice.Roll.play_ai(22, 4)
        self.assertEqual(result, 0)

        result = roll_dice.Roll.play_ai(8, 6)
        self.assertEqual(result, 0)

        result = roll_dice.Roll.play_ai(25, 7)
        self.assertEqual(result, 0)


if __name__ == '__main__':
    unittest.main()
