Problematic Probabilities – problem with test output

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:

@test checkmean(successes, trials)
@test checkmean(successes, trials)
@test checkprob(successes, trials)
@test checkprob(successes, trials)

As there is no source code for the tests either, I feel stuck. Any ideas?

Hi @mynameismypassword :wave:

Welcome to the Exercism forums!

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 image button in the toolbar, or enclosing the code in three ``` backtick marks :smile:

@colinleach and @depial for possible investigation around tests and test output.

It’s not immediately obvious to me what’s going wrong here, but we’ll look into it.

FYI, this exercise is a relatively recent addition. So far, 106 students started it and 98 completed successfully (a high percentage!).

Once we see the submitted code from @mynameismypassword we might have a better idea.

@mynameismypassword What are your functions outputting when two means/probabilities are equal?

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.

1 Like

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

Unfortunately, I can confirm that feedback in the online editor is really unhelpful:

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.

3 Likes

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.

Some thinking required…

The equality tests are reliable if the rationals are cast to float

Yep, this is the issue, and I think we’ll have to update the docs to include this information.

An example of the problem:

julia> 1//3 == 1/3
false

julia> float(1//3) == 1/3
true

julia> 1//4 == 1/4
true

julia> float(1//4) == 1/4
true

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.

4 Likes

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.

2 Likes