My code passes four tests and fails four others (Tests 4, 5, 7, and 8).
Usually the output helps me find my mistake, but in this case, all it says is this:
Could you provide the code you used for this solution in a code block? That would be really helpful for troubleshooting. You can codeblock something by using the button in the toolbar, or enclosing the code in three ``` backtick marks
@colinleach and @depial for possible investigation around tests and test output.
A bit of background, for those unfamiliar with Exercism internals. The test file (runtests.jl) is shown in the online editor for Practice exercises, but not for Concept exercises on the learning track - such as Problematic Probabilities. Nothing is really hidden, we are just trying to limit unnecessary distractions.
You should see reasonably detailed test output, even if you don’t see the test setup. Of course, students using the CLI interface and running tests on their local machines get all the necessary files, including runtests.jl.
Also (for the really keen student), all the source is in a public repo on GitHub.
Thanks to everyone offering help and the generous comments so far.
Here is my source code:
function rationalize(successes, trials)
[successes[i]//trials[i] for i in 1:length(trials)]
end
function probabilities(successes, trials)
[successes[i]/trials[i] for i in 1:length(trials)]
end
function checkmean(successes, trials)
mratio = sum(rationalize(successes, trials))/length(trials)
mprobs = sum(probabilities(successes, trials))/length(trials)
mratio == mprobs ? true : mratio
end
function checkprob(successes, trials)
tratio = prod(rationalize(successes, trials))
tprobs = prod(probabilities(successes, trials))
tratio == tprobs ? true : tratio
end
We’ll look into that, but I don’t have a quick fix for cases where the tests throws an error instead of simply failing.
When I ran this locally, the problem is a bit clearer.
check mean: Error During Test at runtests.jl:18
Expression evaluated to non-Boolean
Expression: checkmean(successes, trials)
Value: 499//1530
check mean: Error During Test at runtests.jl:21
Expression evaluated to non-Boolean
Expression: checkmean(successes, trials)
Value: 41//115
check probability: Error During Test at runtests.jl:32
Expression evaluated to non-Boolean
Expression: checkprob(successes, trials)
Value: 2//37125
check probability: Error During Test at runtests.jl:35
Expression evaluated to non-Boolean
Expression: checkprob(successes, trials)
Value: 1//10304
Test Summary: | Pass Error Total Time
tests | 8 4 12 0.6s
rationalize | 2 2 0.1s
probabilities | 2 2 0.0s
check mean | 2 2 4 0.4s
check probability | 2 2 4 0.1s
ERROR: LoadError: Some tests did not pass: 8 passed, 0 failed, 4 errored, 0 broken.
It is happy when the means/probabilities are not equal, returning a rational, but fails for equality, when it should return true and the test expects a Boolean.
The equality tests are reliable if the rationals are cast to float (float(mratio) == mprobs, etc). I’ll put my head together with @depial’s (much smarter) one, and see if we can clarify the instructions.
Thank you for reporting this, it is something I wasn’t aware of.
Maintainer detail: In an ideal world, we would upgrade the Julia test runner from v2 to v3, to give better feedback. Sadly, that’s a big job for anyone, and well outside my experience.
So, it appears equality between Rationals and Floats only works for fractions with a finite decimal representation.
@mynameismypassword casting your Rationals to Floats with float() to do the comparison will get you going. Thank you for bringing this to our attention!
Coincidentally, I’ve started looking into this in the past few days. I don’t think we necessarily have to upgrade to v3 to report more info, but it would probably be worthwhile to do both things at once. I’ll open an issue on GH to track this.
Thank you both for your swift and informative responses. I can confirm that float()'ing works, and I am sure others would find amendments to the instructions beneficial.