MDL-28942 qtype multichoice, multi-response. Avoid computing the wrong random guess score.

It is effectively impossible to compute the right random guess score, so we should not compute anything, rather than computing a number that we know is wrong.

This patch also fixes a multianswer unit test error that was shown up by this fix.
This commit is contained in:
Tim Hunt 2011-08-17 12:33:00 +01:00 committed by Eloy Lafuente (stronk7)
parent 64ce7fb6c5
commit a980739fd4
3 changed files with 14 additions and 2 deletions

View File

@ -77,7 +77,7 @@ class qtype_multianswer_test extends UnitTestCase {
$sadata->id = 1;
$sadata->qtype = 'shortanswer';
$sadata->defaultmark = 1;
$sadata->options->single = true;
$sadata->options->usecase = true;
$sadata->options->answers[1] = (object) array('answer' => 'Bow-wow', 'fraction' => 0);
$sadata->options->answers[2] = (object) array('answer' => 'Wiggly worm', 'fraction' => 0);
$sadata->options->answers[3] = (object) array('answer' => 'Pussy-cat', 'fraction' => 1);
@ -86,7 +86,7 @@ class qtype_multianswer_test extends UnitTestCase {
$mcdata->id = 1;
$mcdata->qtype = 'multichoice';
$mcdata->defaultmark = 1;
$mcdata->options->usecase = true;
$mcdata->options->single = true;
$mcdata->options->answers[1] = (object) array('answer' => 'Dog', 'fraction' => 0);
$mcdata->options->answers[2] = (object) array('answer' => 'Owl', 'fraction' => 1);
$mcdata->options->answers[3] = (object) array('answer' => '*', 'fraction' => 0);

View File

@ -182,6 +182,12 @@ class qtype_multichoice extends question_type {
}
public function get_random_guess_score($questiondata) {
if (!$questiondata->options->single) {
// Pretty much impossible to compute for _multi questions. Don't try.
return null;
}
// Single choice questions - average choice fraction.
$totalfraction = 0;
foreach ($questiondata->options->answers as $answer) {
$totalfraction += $answer->fraction;

View File

@ -71,6 +71,12 @@ class qtype_multichoice_test extends UnitTestCase {
$this->assertEqual(0.5, $this->qtype->get_random_guess_score($q));
}
public function test_get_random_guess_score_multi() {
$q = $this->get_test_question_data();
$q->options->single = false;
$this->assertNull($this->qtype->get_random_guess_score($q));
}
public function test_get_possible_responses_single() {
$q = $this->get_test_question_data();
$responses = $this->qtype->get_possible_responses($q);