Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue 19 #20

Merged
merged 3 commits into from
Apr 20, 2016
Merged

Fix for issue 19 #20

merged 3 commits into from
Apr 20, 2016

Commits on Apr 17, 2016

  1. Add modulo functionality

    Add an if to the pre_check that catches cases where there are less items
    to choose from than sides on the die. If this is the case, we can still
    pick items, but we have to use a modulo.
    Pick the `num_rolls` so that the result generated after rolling is larger
     than `100*len(sequence)`.
    The `pre_check()` function now has to return the modified `num_rolls` as
    well as a boolean to indicate whether modulo needs to be applied on the
    result.
    dwcoder committed Apr 17, 2016
    Configuration menu
    Copy the full SHA
    3608911 View commit details
    Browse the repository at this point in the history
  2. Write unit tests for the new pre_check function

    It is passing and doing as expected.
    dwcoder committed Apr 17, 2016
    Configuration menu
    Copy the full SHA
    1e1ce2b View commit details
    Browse the repository at this point in the history

Commits on Apr 19, 2016

  1. Put calculations in right place

    Move the calculations out of the `pre_check()` function.
    Also do smarter checks:
      - If len(sequence) == 1, we don't need any rolls. In this case, just
        return sequence[0]
      - If len(sequence) is a factor of dice_sides, we only need one roll
        along with the modulo operator.
      - For everything else, just require one extra roll, bringing it to a
        total of 2 rolls. This should remove a little bit of the edge bias
        introduced by the modulo
    Run the `pre_check()` function after the calculations have been done.
    
    For the unit tests:
      - remove the function `test_choice_len_too_short()`;
        we no longer have to raise an exception when the sequence length is
        too short.
      - Write new tests for the cases where `dice_sides = 6` and `len(sequence)`:
         - 1
         - 2,3
         - 4,5
    dwcoder committed Apr 19, 2016
    Configuration menu
    Copy the full SHA
    a08516d View commit details
    Browse the repository at this point in the history