Ad
  • Custom User Avatar
  • Custom User Avatar

    Thank you! The test cases now check for 1e-6 accuracy in the assertEquals() method itself.

  • Custom User Avatar

    @Cypenborg This might be a good resource

  • Custom User Avatar

    There is no approximate equality in java?

  • Custom User Avatar

    Noted! The test cases now round the user's answer and solution to 6 decimals and then does an equality test.

    Edit: outdated

  • Custom User Avatar

    While calculating the actual probabilities are more repeatable, they require an in-depth understanding of probability theory. My aim with this kata was to show how probabilities can be calculated through simulations, which are much more accessible than learning theory. In simple simulations like this, all outcomes are technically possible as you are assigning random papers to random students - a simple permutation exercise. It is also quite straightforward to test as the input into the constructor is the simulation - you do no simulate yourself, you only calculate the empirical probability from the given simulation. The resultant empirical probabilities are still useful, many real-world models (in fact, I would even say most) use empirical probabilties because it is usually impossible to calculate real world probabilities without perfect information.

    E.g. mortality rates, i.e. the probability a person will die at a specific age, cannot be completely determined. Actuaries model mortality, most often, from death rates gathered from group of people in the past. To estimate future mortality, actuaries may simulate future mortality rates using these past rates and their trends over time.

    Hence, simulated probabilities are quite useful. While it is true that results from one simulation are biased to that simulation, as you do more and more simulations and average your results, you are expected to approach the true probability if it exists - which it does in this case. For 1., the true probability depends on the number of students in the class and for 2. the true probability is independent of it. See https://en.wikipedia.org/wiki/Law_of_large_numbers.

  • Custom User Avatar
  • Custom User Avatar

    expected: <0.32> but was: <0.3199999999999996>

    Strict equality tests for floating point numbers are consistently an issue in katas and extremely annoying if the solver's approach is correct but not exactly the same as the author's. Tests should allow for approximate equality up to a sufficiently large tolerance ( maybe 1e-8 ).

  • Custom User Avatar

    Note: we will calculate sample probabilities from simulations and not the actual probabilities for these events to happen.

    How are you going to test this? Calculating actual probabilities is going to be a lot more repeatable than rating random simulations for likeliness. Where do you draw the line between possible and impossible outcomes?