コード例 #1
0
ファイル: test_roll.py プロジェクト: extesla/dice-python
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)
コード例 #2
0
ファイル: test_roll.py プロジェクト: extesla/dice-python
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)
コード例 #3
0
ファイル: test_roll.py プロジェクト: extesla/dice-python
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)
コード例 #4
0
ファイル: test_roll.py プロジェクト: extesla/dice-python
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)
コード例 #5
0
ファイル: test_roll.py プロジェクト: extesla/dice-python
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)
コード例 #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),
    ])
コード例 #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)
コード例 #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),
    ])
コード例 #9
0
ファイル: test_roll.py プロジェクト: extesla/dice-python
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),
    ])
コード例 #10
0
ファイル: test_roll.py プロジェクト: extesla/dice-python
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)
コード例 #11
0
ファイル: test_roll.py プロジェクト: extesla/dice-python
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),
    ])
コード例 #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)
コード例 #13
0
ファイル: test_roll.py プロジェクト: extesla/dice-python
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)
コード例 #14
0
ファイル: test_roll.py プロジェクト: extesla/dice-python
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)
コード例 #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)])
コード例 #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)
コード例 #17
0
ファイル: test_roll.py プロジェクト: extesla/dice-python
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)
    ])
コード例 #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")
コード例 #19
0
 def test_keep_low(self: object) -> None:
     result = roll.roll('4d6kl3')
     self.assertTrue(isinstance(result, int))
     self.assertTrue(3 <= result <= 18)
コード例 #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)
コード例 #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)
コード例 #22
0
 def test_add(self: object) -> None:
     self.assertEqual(roll.roll('3+7'), 10)
コード例 #23
0
 def test_multiply(self: object) -> None:
     self.assertEqual(roll.roll('3*7'), 21)
コード例 #24
0
ファイル: test_roll.py プロジェクト: extesla/dice-python
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")
コード例 #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)
コード例 #26
0
 def test_subtract(self: object) -> None:
     self.assertEqual(roll.roll('3-7'), -4)
コード例 #27
0
 def test_roll(self: object) -> None:
     self.assertEqual(roll.roll('8'), 8)
コード例 #28
0
 def test_dice_expression(self: object) -> None:
     result = roll.roll('3d6-2')
     self.assertTrue(isinstance(result, int))
     self.assertTrue(1 <= result <= 16)
コード例 #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)
コード例 #30
0
 def test_drop_high(self: object) -> None:
     result = roll.roll('4d6dh1')
     self.assertTrue(isinstance(result, int))
     self.assertTrue(3 <= result <= 18)
コード例 #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)
コード例 #32
0
 def test_die(self: object) -> None:
     result = roll.roll('d6')
     self.assertTrue(isinstance(result, int))
     self.assertTrue(1 <= result <= 6)
コード例 #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)