Repository navigation
Conversation
|
Hi @jippiee, and thanks for your PR! Here comes a very delayed response, but better late than never I hope! With this response I hope that @exercism/java will find interest in eventually approving it. I came up with this exercise (in exercism/problem-specifications#1397) and @lemoncurry created the exercise on the Java track (in #1621). One of my motivations behind this exercise was that I was working with random numbers at work and had to test that some function returned random data according to the proper probability distribution. Testing that a solution doesn't use Let us know what @lemoncurry thinks also. As for your two proposed properties, here is some feedback for them:
In summary,
|
|
@jippiee - are you still actively working on this PR? If not, we might close it to clean up our backlog. It can always be reopened if needed. |
|
Ok, I've updated the test and also included comments describing how the test with the distribution works. I've also included a Note on why Here I've also plotted the distributions. The green is the correct one. |
|
Closing and reopening to trigger travis CI to retry this... |
|
Looks like there is a slight style violation at line 189:
So just reduce the indentation there to 12 (ie. delete 4 spaces). Other than that, I will try to take a look at this tomorrow morning. |
jmrunkle
left a comment
There was a problem hiding this comment.
Thanks for working on this. We are getting pretty close now.
| } | ||
|
|
||
| /* | ||
| * Extra Notes: |
There was a problem hiding this comment.
This is a very interesting statistical commentary, but I'm not sure it belongs here. Perhaps this sort of thing should go in the mentoring notes for this exercise?
There was a problem hiding this comment.
Yes, this really remains to be decided.
The purpose of the exercise (I can say because I came up with it) is to explore probabilistic property testing.
But any maintainer is fit to choose how to make any exercise fit some track-specific goal.
I think this stuff is ingenious -- and it is, it seems, one of the things people do wrong: Not understanding that just because the range is correct, the distribution isn't necessarily.
Alternative suggestions for placements:
- In a hint: Would increase exposure.
- In a git commit message: Would remove exposure.
- In a blog post linked to from a hint: Would require someone to want to write a blog post.
There was a problem hiding this comment.
The idea for this comment was, that if a student has a wrong solution which fails the testAbilityIsDistributedAccordingToRules test, but they don't jet know why it is failing, they might want to check out the source of the tests and thus stumble on this note. I admit that probably not every student will find it, but for some it might help them solve the exercise.
There was a problem hiding this comment.
Personally, I am leaning towards having a hints.md file that includes this extra information about this test. If it makes you feel better, put a Javadoc comment on the test method telling them to check the hints.
|
@jmrunkle wrote:
Ever since reviewing this, my impression has been that the solution is sufficient, but that it lacks explanation for maintainers to want to touch it. So my review was an encouragement to convince those less statistics savvy (myself included) that it won't, in practice, fail, without resorting to "trust me, I know math", because I think such an argument is extremely fragile in the context of Exercism, where we rely heavily on commit history. |
Added comment explaining methodology Added inRange and testDistribution helper methods Updated reference solution
jippiee
left a comment
There was a problem hiding this comment.
This is the updated test and reference solution.
| * The parameters (10000, 0.1, 0.01) were chosen based on the results | ||
| * of the table above, and were tested further in the test setup with a | ||
| * loop of 1000000, which passed. | ||
| * | ||
| * Further following should hold true: | ||
| * relativeError <= 0.2 | ||
| * constantError <= 0.02 | ||
| * Otherwise it becomes increasingly likely that an 'ability' method | ||
| * which gives "Throw three dice and sum them" would wrongly pass the | ||
| * test. |
There was a problem hiding this comment.
Here is a chart of what I am talking about:
The yellow and green graphs are the distributions of two wrong implementations mentioned at the beginning.
The red graph is the reference distribution.
The pink graph represents the error bounds for the parameters currently in use: Any distribution that we create by repeatedly calling ability, which falls completely within these bounds is accepted, otherwise rejected.
The blue graph represents the error bounds for the two maximum parameters mentioned. Should the parameters be even larger, it will become increasingly likely that we accept a solution which actually conforms to the green graph ("Throw three dice. Sum them.") than the red one ("Throw four dice. Sum the largest three.").
There was a problem hiding this comment.
I think this is missing the graph showing the error bounds for the green graph. This only shows an idealized distribution for the green case (roll 3, sum them). I'm curious that there is even more overlap if you consider the error bounds for the green distribution. With that said, I think this is probably sufficient to get us close enough as-is.
There was a problem hiding this comment.
NOTE: If you move the long comments to a hints.md file, you could also put the graphic into the markdown. Just a thought.
| /* This distribution was generated by going through all possible | ||
| * combinations for throwing four dice, computing the ability for that | ||
| * combination, and incrementing the array at that index. | ||
| */ | ||
| int[] referenceDist = new int[] { | ||
| 0, 0, 0, 1, 4, 10, 21, 38, 62, 91, 122, 148, 167, 172, 160, 131, 94, 54, 21 | ||
| }; |
There was a problem hiding this comment.
Instead use actual generation code? Or maybe put the code in a comment?
There was a problem hiding this comment.
I'm debating the merits. I assume the generation is time-prohibitive to just generate it in the test. We could leave it in an unused method just for documentation purposes?
There was a problem hiding this comment.
Is this comment bad?
If you ask me the ingenious part of this PR is that @jippiee precomputes the heavy parts and remains confident to any chosen probability that there isn't false negatives. But this array is certainly magical and deserves an explanation.
There was a problem hiding this comment.
Also, while some comments can be moved to the hint file, this one is overly specific about some magical constants. So I might be inclined to keep it local, since you really don't care about what the numbers are until you read them, but they also really need an explanation.
There was a problem hiding this comment.
I think it would be nice to have an unused method that computes this array which can have some nice Javadoc and the actual precomputed array can say it was generated by method X.
So something like this:
/* Built by {@link generateReferenceDistribution} */
int[] referenceDist = new int[] ...
/**
* Generates a distribution by going through all possible
* combinations for throwing four dice, computing the ability for that
* combination, and incrementing the array at that index.
*/
private static int[] generateReferenceDistribution() { ... }There was a problem hiding this comment.
That's not a bad idea, but not an entirely uncontentious one either.
Dead code vs. looking up commits for explanations.
I would be happy with either.
There was a problem hiding this comment.
I'm not saying we should go with the following, but it made me think of golden tests, i.e. unit tests stored in files: "When you add a new test, your testing framework can generate the missing golden file from the current output of the function."
| return; | ||
| } | ||
| } | ||
| fail(); |
There was a problem hiding this comment.
This should probably include an error message saying what happened so that the student could debug the test failure: "ability appears to always return the same value"
|
@jippiee - any more updates on this PR? |
|
To get this PR merged, I see some points that were raised:
The comment links refer to the discussion on each of these. It would be a pity to not have this included because of minor, unresolved ideas about where to place comments. :-) Also, this PR probably needs rebasing after v3 has moved practice exercises to a sub-directory. |
|
If there are no further updates or comments on this PR, I will probably close it in one week. Otherwise, please comment and then synchronize the files and we can continue the review. |
Closing as there has been no followup on this. Feel free to reopen if / when you are willing to address the merge conflicts, etc and continue the review. |


The idea for these tests is that currently you can simply return a constant value within range of 3 to 18 in the ability method and all test will still pass. (See my solution)
The first test
testRandomAbilityIsRandomasserts that within 100 calls toability()there are at leased 2 different values returned.The second test
testDistributionMatchesReferenceasserts that the resulting distribution matches the reference distribution. This reference is simply the count of all distinct abilities for all possible dice rolls. I generated this with:To be considered as matching, a distribution populated by 10000 random values must differ less than 2% from the reference. These two values (cycles=10000, threshold=0.02) were determined by experimentation. The larger this first value (cycles) is, the more precise the second value (threshold) can be. To determine the threshold I let the entire test loop 1000000 times and keep track of the max difference. It was 0.0166. I created this test to catch the implementations that only return the sum of 3 dice rolls or (even wore) return a random number between 3 and 18.
Reviewer Resources:
Track Policies