コード例 #1
0
ファイル: drv_test.py プロジェクト: sjjessop/omnidice
def test_weighted():
    """
    You can compute a DRV from disjoint cases.
    """
    var = DRV({1: 0.5, 2: 0.5})
    var2 = DRV.weighted_average((
        (var, 0.5),
        (var + 2, 0.5),
    ))
    # So, var2 should be uniformly distributed
    assert var2.is_same(DRV({x: 0.25 for x in range(1, 5)}))
コード例 #2
0
def test_more_dice(reg):
    """
    Test with higher numbers of dice. Three dice is wild + 2 @ regular, etc.
    """
    def remove_highest(values):
        return sum(values) - max(values)

    expected = DRV.weighted_average((
        (pool(d6, count=reg).apply(remove_highest), Fraction(1, 6)),
        (reg @ d6 + d6.explode().given(lambda x: x != 1), Fraction(5, 6)),
    ))
    _check(
        opend6.dice(reg + 1),
        expected,
        single=False,
        totals=reg @ d6 + d6.explode(),
        highest=pool(d6, count=reg + 1).apply(max),
    )
コード例 #3
0
def test_dice():
    """The dice() function returns the summarised data from the rolls."""
    with pytest.raises(ValueError):
        opend6.dice(0)
    # One die is a wild die.
    assert opend6.dice(1).is_same(opend6.wild_die)
    # Two dice is wild + regular, and we need to test that addition is correct.
    expected = DRV.weighted_average((
        (DRV({0: 1}), Fraction(1, 6)),
        (d6 + d6.explode().given(lambda x: x != 1), Fraction(5, 6)),
    ))
    _check(
        opend6.dice(2),
        expected,
        single=False,
        totals=d6 + d6.explode(),
        highest=pool(d6, d6).apply(max),
    )
コード例 #4
0
def test_dice_char():
    """The char parameter adds dice bought with Character Points"""

    # I don't think the rules explicity say what happens on a botch, if an
    # exploded character die is the highest score rolled. I'm going to assume
    # that the botch cancels the 6.
    def cancel(value):
        return max(value - 6, 0)

    expected = DRV.weighted_average((
        (d6.explode().apply(cancel), Fraction(1, 6)),
        (d6.explode() + d6.explode().given(lambda x: x != 1), Fraction(5, 6)),
    ))
    _check(
        opend6.dice(1, char=1),
        expected,
        single=False,
        totals=2 @ d6.explode(),
        highest=pool(d6, d6).apply(max),
    )