Exemplo n.º 1
0
 def dupes(p: P):
     for roll, count in p.rolls_with_counts():
         dupes = 0
         for i in range(1, len(roll)):
             if roll[i] == roll[i - 1]:
                 dupes += 1
         yield dupes, count
Exemplo n.º 2
0
def _rwc_validation_helper(p: P, which: slice) -> Tuple[Mock, Mock]:
    # Use the brute-force mechanism to validate our harder-to-understand implementation.
    # Note that there can be repeats and order is not guaranteed, which is why we have
    # to accumulate counts for rolls and then compare entire results.
    known_counts: DefaultDict[_RollCountT, _CountT] = defaultdict(int)
    test_counts: DefaultDict[_RollCountT, _CountT] = defaultdict(int)

    for roll, count in _brute_force_combinations_with_counts(tuple(p), which):
        known_counts[roll] += count

    with patch(
            "dyce.p._rwc_homogeneous_n_h_using_karonen_partial_selection",
            side_effect=_rwc_homogeneous_n_h_using_karonen_partial_selection,
    ) as karonen, patch(
            "dyce.p._rwc_homogeneous_n_h_using_multinomial_coefficient",
            side_effect=_rwc_homogeneous_n_h_using_multinomial_coefficient,
    ) as multinomial_coefficient:
        for roll, count in p.rolls_with_counts(which):
            test_counts[roll] += count

    assert test_counts == known_counts, f"which: {which}"

    return karonen, multinomial_coefficient
Exemplo n.º 3
0
 def _sum_method(p: P, outcome: _OutcomeT) -> H:
     return H((sum(1 for v in roll if v == outcome), count)
              for roll, count in p.rolls_with_counts())