When you evaluate a quiz which has a max score of 0 you'll end up with fatal php errors on the database level at various points in the code. All errors are a variation of the "Division by zero" error.
Despite the fatal errors I've marked this issue as normal since this use-case isn't really one you would normally use.

The issue arises when you try to score a ...
... long answer question which has a max score of 0.
... short answer question which has a max score of 0.
... quiz which has a total max score of 0.

I've also tested the other question types, but these seem able to handle a max score of 0 points well.

The patch I've created basically does 2 things.
For the long and short answers I've added a check that looks if the max score is bigger than 0. If it is the score will be calculated as it used to if it isn't the score will be 0.

For the quiz as a whole I've added the same check, but in this case the score will be a 100%. It seemed the most logical thing to give the user a 100% score if he finished a quiz for which he could get a maximum of 0 points.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

da_cloud created an issue. See original summary.

Da_Cloud’s picture

Status: Needs review » Needs work

The last submitted patch, 2: quiz-fix_critical_issue_when_maxscore_is_0-2623560-0-7.patch, failed testing.

Da_Cloud’s picture

My fault there. Accidentally uploaded the patch for my project instead of the patch for the module's repo.

Da_Cloud’s picture

Da_Cloud’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: quiz-fix_critical_issue_when_maxscore_is_0-2623560-4-7.patch, failed testing.

Da_Cloud’s picture

Version: 7.x-4.0-rc1 » 7.x-4.x-dev
Status: Needs work » Needs review
Da_Cloud’s picture

Seems the issue also occurs in the 5.x branch, so I re-rolled the patch for 5.x.

Da_Cloud’s picture

Version: 7.x-4.x-dev » 7.x-5.x-dev
djdevin’s picture

Thanks! Ideally this would be outside of the Quiz question modules so that they don't have to worry about the weighting.

My question is - shouldn't the score still be stored as 0 (instead of as 100 in your patch?)?

Since the question is worth 0 points I'm not sure how getting 100% of 0 makes sense.

Da_Cloud’s picture

The max score of the question is 0 and the score you've received is also 0. So it all comes down to which percentage you would give 0 points out of 0 points.

In my personal situation the end user just wanted to create some kind of survey with open questions. Since you can't answer a survey with a wrong answer she just put all the max scores of the questions on 0. Which is also why I've turned the end score into 100 as in this scenario the question would be right.

Da_Cloud’s picture

I also see part of the confusion. I seem to have done a check on $score where the problem lies with $ratio being 0.
If $score=0 and $max_score=5 we'll end up with 0/5 which is indeed 0.
If $score=0 and $max_score=0 we'll end up with a divide by zero.

The total max score of the quiz being 0 doesn't seem to be an issue in the 5.x branch, it is however an issue in the 4.x branch

Might be wise to extend the test scripts to test on certain causes where either the score or the max score is 0. If you think those are useful I could give it a go to see if I can create those.

Da_Cloud’s picture

For now I've only created a test case for the short_answer module.

The last submitted patch, 14: tests_only.patch, failed testing.

Da_Cloud’s picture

Status: Needs review » Closed (duplicate)
Related issues: +#2999514: NAN when scoring long/short answers