Exemple #1
0
    def test_maximal_value_for_2d4(self, mock_randint):
        mock_randint.side_effect = lambda _, b: b

        value, _, maximal = calculate(self.dices_2d4)

        self.assertEqual(self.dices_2d4[0] * 4 + self.dices_2d4[2], value)
        self.assertEqual(self.dices_2d4[0] * 4 + self.dices_2d4[2], maximal)
Exemple #2
0
    def test_minimal_value_for_3d6(self, mock_randint):
        mock_randint.side_effect = lambda a, _: a

        value, minimal, _ = calculate(self.dices_3d6)

        self.assertEqual(self.dices_3d6[0] * 1 + self.dices_3d6[2], value)
        self.assertEqual(self.dices_3d6[0] * 1 + self.dices_3d6[2], minimal)
Exemple #3
0
def roll_dices(_, update):
    try:
        dices = parse(update.message.text)

        value, minimal, maximal = calculate(dices)
        update.message.reply_text('%d (%d..%d)' % (value, minimal, maximal))

    except InvalidFormat as exc:
        update.message.reply_text('Error: Invalid format %s' % exc.format)

    except InvalidDicesCount as exc:
        update.message.reply_text(
            'Error: Invalid dices count %d (min %d, max %d)' %
            (exc.dices, minimal_dices_count, maximal_dices_count))

    except InvalidFacesCount as exc:
        update.message.reply_text(
            'Error: Invalid faces count %d (min %d, max %d)' %
            (exc.faces, minimal_faces_count, maximal_faces_count))

    except:
        update.message.reply_text('Error: Unknown')
Exemple #4
0
    def test_should_use_randint_once_for_3d(self, mock_randint):
        mock_randint.return_value = 1

        _ = calculate(self.dices_3d6)

        self.assertEqual(1, mock_randint.call_count)
Exemple #5
0
    def test_should_use_min_and_max_for_3d6(self, mock_randint):
        mock_randint.return_value = 1

        _ = calculate(self.dices_3d6)

        mock_randint.assert_called_with(3 * 1 + 3, 3 * 6 + 3)
Exemple #6
0
    def test_should_use_min_and_max_for_2d4(self, mock_randint):
        mock_randint.return_value = 1

        _ = calculate(self.dices_2d4)

        mock_randint.assert_called_with(2 * 1 - 2, 2 * 4 - 2)
Exemple #7
0
    def test_should_use_min_and_max_for_1d2(self, mock_randint):
        mock_randint.return_value = 1

        _ = calculate(self.dices_1d2)

        mock_randint.assert_called_with(1, 2)