Beispiel #1
0
def test_roll_1d20_multiply_with_spaces(mocker):
    mock_random = mocker.patch("random.randint")
    mock_random.return_value = 6

    actual = roll("1d20  * 3")
    assert actual == [18]
    mock_random.assert_called_once_with(1, 20)
Beispiel #2
0
def test_roll_1d20_subtraction_with_spaces(mocker):
    mock_random = mocker.patch("random.randint")
    mock_random.return_value = 12

    actual = roll("1d20 -   5")
    assert actual == [7]
    mock_random.assert_called_once_with(1, 20)
Beispiel #3
0
def test_roll_1d20_divide_to_integer(mocker):
    mock_random = mocker.patch("random.randint")
    mock_random.return_value = 17

    actual = roll("1d20/3")
    assert actual == [5]
    mock_random.assert_called_once_with(1, 20)
Beispiel #4
0
def test_roll_1d20_divide_with_spaces(mocker):
    mock_random = mocker.patch("random.randint")
    mock_random.return_value = 12

    actual = roll("1d20 /  3")
    assert actual == [4]
    mock_random.assert_called_once_with(1, 20)
Beispiel #5
0
def test_roll_1d20_addition_with_spaces(mocker):
    mock_random = mocker.patch("random.randint")
    mock_random.return_value = 17

    actual = roll("1d20  + 5")
    assert actual == [22]
    mock_random.assert_called_once_with(1, 20)
Beispiel #6
0
def test_roll_2d20_advantage_with_modifiers_after_flag(mocker, mock_randint):
    mock_randint.side_effect = [8, 15]

    actual = roll("2d20!advantage+5")
    assert actual == [20]
    mock_randint.assert_has_calls([
        mocker.call(1, 20),
        mocker.call(1, 20),
    ])
Beispiel #7
0
def test_roll_1d6(mock_randint):
    """
    Assert that when 1d6 is rolled, that the expected value is returned.
    """
    mock_randint.return_value = 3

    actual = roll("1d6")
    assert actual == [3]
    mock_randint.assert_called_once_with(1, 6)
Beispiel #8
0
def test_roll_2d20_advantage(mocker, mock_randint):
    mock_randint.side_effect = [8, 15]

    actual = roll("2d20!advantage")
    assert actual == [15]
    mock_randint.assert_has_calls([
        mocker.call(1, 20),
        mocker.call(1, 20),
    ])
Beispiel #9
0
def test_roll_2d20_advantage_with_modifiers_after_flag(mocker):
    mock_random = mocker.patch("random.randint")
    mock_random.side_effect = [8, 15]

    actual = roll("2d20!advantage+5")
    assert actual == [20]
    mock_random.assert_has_calls([
        mocker.call(1, 20),
        mocker.call(1, 20),
    ])
Beispiel #10
0
def test_roll_1d6(mocker):
    """
    Assert that when 1d6 is rolled, that the expected value is returned.
    """
    mock_random = mocker.patch("random.randint")
    mock_random.return_value = 3

    actual = roll("1d6")
    assert actual == [3]
    mock_random.assert_called_once_with(1, 6)
Beispiel #11
0
def test_roll_2d20_advantage(mocker):
    mock_random = mocker.patch("random.randint")
    mock_random.side_effect = [8, 15]

    actual = roll("2d20!advantage")
    assert actual == [15]
    mock_random.assert_has_calls([
        mocker.call(1, 20),
        mocker.call(1, 20),
    ])
Beispiel #12
0
def test_roll_1dF(mock_randint):
    #: TBW
    #:
    #: Given
    #: When
    #: Then
    with patch("random.randint") as mock_randint:
        mock_randint.return_value = 3
        actual = roll("1dF")
        self.assertEqual(actual, 3)
        mock_randint.assert_called_once_with(6)
Beispiel #13
0
def test_roll_1dF(mocker):
    #: TBW
    #:
    #: Given
    #: When
    #: Then
    with patch("random.randint") as mock_randint:
        mock_randint.return_value = 3
        actual = roll("1dF")
        self.assertEqual(actual, 3)
        mock_randint.assert_called_once_with(6)
Beispiel #14
0
def test_roll_d20(mocker):
    #: TBW
    #:
    #: Given the roll function
    #: When the roll function is called with the expression "d20"
    #: Then the expression should evaluate as if it were given the
    #:     expression: "1d20"
    with patch("random.randint") as mock_randint:
        mock_randint.return_value = 3
        actual = roll("d20")
        self.assertEqual(actual, 3)
        mock_randint.assert_called_once_with(20)
Beispiel #15
0
def test_roll_3d6(mocker, mock_randint):
    """
    Assert that when 3d6 is rolled, that the expected value is returned.
    """
    mock_randint.side_effect = [3, 1, 4]

    actual = roll("3d6")
    assert actual == [8]
    mock_randint.assert_has_calls(
        [mocker.call(1, 6),
         mocker.call(1, 6),
         mocker.call(1, 6)])
Beispiel #16
0
def test_roll_d20(mock_randint):
    #: TBW
    #:
    #: Given the roll function
    #: When the roll function is called with the expression "d20"
    #: Then the expression should evaluate as if it were given the
    #:     expression: "1d20"
    with patch("random.randint") as mock_randint:
        mock_randint.return_value = 3
        actual = roll("d20")
        self.assertEqual(actual, 3)
        mock_randint.assert_called_once_with(20)
Beispiel #17
0
def test_roll_3d6(mocker):
    """
    Assert that when 3d6 is rolled, that the expected value is returned.
    """
    mock_random = mocker.patch("random.randint")
    mock_random.side_effect = [3, 1, 4]

    actual = roll("3d6")
    assert actual == [8]
    mock_random.assert_has_calls([
        mocker.call(1, 6),
        mocker.call(1, 6),
        mocker.call(1, 6)
    ])
Beispiel #18
0
def test_roll_2d20_advantage_with_modifiers_before_flag(mock_randint):
    #: We currently don't support applying flags to an expression, only to
    #: the actual dice roll.
    with pytest.raises(ParseException):
        roll("2d20+5!advantage")
Beispiel #19
0
 def test_keep_low(self: object) -> None:
     result = roll.roll('4d6kl3')
     self.assertTrue(isinstance(result, int))
     self.assertTrue(3 <= result <= 18)
Beispiel #20
0
def test_roll_1d20_addition_with_spaces(mock_randint):
    mock_randint.return_value = 17

    actual = roll("1d20  + 5")
    assert actual == [22]
    mock_randint.assert_called_once_with(1, 20)
Beispiel #21
0
def test_roll_1d20_subtraction_floor(mock_randint):
    mock_randint.return_value = 2

    actual = roll("1d20-5")
    assert actual == [1]
    mock_randint.assert_called_once_with(1, 20)
Beispiel #22
0
 def test_add(self: object) -> None:
     self.assertEqual(roll.roll('3+7'), 10)
Beispiel #23
0
 def test_multiply(self: object) -> None:
     self.assertEqual(roll.roll('3*7'), 21)
Beispiel #24
0
def test_roll_2d20_advantage_with_modifiers_before_flag(mocker):
    #: We currently don't support applying flags to an expression, only to
    #: the actual dice roll.
    with pytest.raises(ParseException):
        roll("2d20+5!advantage")
Beispiel #25
0
def test_roll_1d20_subtraction_with_spaces(mock_randint):
    mock_randint.return_value = 12

    actual = roll("1d20 -   5")
    assert actual == [7]
    mock_randint.assert_called_once_with(1, 20)
Beispiel #26
0
 def test_subtract(self: object) -> None:
     self.assertEqual(roll.roll('3-7'), -4)
Beispiel #27
0
 def test_roll(self: object) -> None:
     self.assertEqual(roll.roll('8'), 8)
Beispiel #28
0
 def test_dice_expression(self: object) -> None:
     result = roll.roll('3d6-2')
     self.assertTrue(isinstance(result, int))
     self.assertTrue(1 <= result <= 16)
Beispiel #29
0
def test_roll_1d20_divide_with_spaces(mock_randint):
    mock_randint.return_value = 12

    actual = roll("1d20 /  3")
    assert actual == [4]
    mock_randint.assert_called_once_with(1, 20)
Beispiel #30
0
 def test_drop_high(self: object) -> None:
     result = roll.roll('4d6dh1')
     self.assertTrue(isinstance(result, int))
     self.assertTrue(3 <= result <= 18)
Beispiel #31
0
def test_roll_1d20_multiply_with_spaces(mock_randint):
    mock_randint.return_value = 6

    actual = roll("1d20  * 3")
    assert actual == [18]
    mock_randint.assert_called_once_with(1, 20)
Beispiel #32
0
 def test_die(self: object) -> None:
     result = roll.roll('d6')
     self.assertTrue(isinstance(result, int))
     self.assertTrue(1 <= result <= 6)
Beispiel #33
0
def test_roll_1d20_divide_to_integer(mock_randint):
    mock_randint.return_value = 17

    actual = roll("1d20/3")
    assert actual == [5]
    mock_randint.assert_called_once_with(1, 20)