public function test_classify_response() { $tf = test_question_maker::make_question('truefalse', 'true'); $tf->start_attempt(new question_attempt_step(), 1); $this->assertEquals(array($tf->id => new question_classified_response(0, get_string('false', 'qtype_truefalse'), 0.0)), $tf->classify_response(array('answer' => '0'))); $this->assertEquals(array($tf->id => new question_classified_response(1, get_string('true', 'qtype_truefalse'), 1.0)), $tf->classify_response(array('answer' => '1'))); $this->assertEquals(array($tf->id => question_classified_response::no_response()), $tf->classify_response(array())); }
public function classify_response(array $response) { if (!array_key_exists('answer', $response)) { return array($this->id => question_classified_response::no_response()); } list($fraction) = $this->grade_response($response); if ($response['answer']) { return array($this->id => new question_classified_response(1, get_string('true', 'qtype_truefalse'), $fraction)); } else { return array($this->id => new question_classified_response(0, get_string('false', 'qtype_truefalse'), $fraction)); } }
public function test_classify_response_choice_added_after_attempt() { $match = test_question_maker::make_a_matching_question(); $firststep = new question_attempt_step(); $match->start_attempt($firststep, 1); $response = $match->prepare_simulated_post_data(array('Dog' => 'Amphibian', 'Frog' => 'Insect', 'Toad' => '', 'Cat' => 'Mammal')); $match = test_question_maker::make_a_matching_question(); $match->stems[5] = "Snake"; $match->stemsformat[5] = FORMAT_HTML; $match->choices[5] = "Reptile"; $match->right[5] = 5; $match->apply_attempt_state($firststep); $this->assertEquals(array(1 => new question_classified_response(2, 'Amphibian', 0), 2 => new question_classified_response(3, 'Insect', 0), 3 => question_classified_response::no_response(), 4 => new question_classified_response(1, 'Mammal', 0.2)), $match->classify_response($response)); }
public function classify_response(array $response) { $selectedchoicekeys = array(); foreach ($this->stemorder as $key => $stemid) { if (array_key_exists($this->field($key), $response) && $response[$this->field($key)]) { $selectedchoicekeys[$stemid] = $this->choiceorder[$response[$this->field($key)]]; } else { $selectedchoicekeys[$stemid] = 0; } } $parts = array(); foreach ($this->stems as $stemid => $stem) { if ($this->right[$stemid] == 0 || !isset($selectedchoicekeys[$stemid])) { // Choice for a deleted subquestion, ignore. (See apply_attempt_state.) continue; } $selectedchoicekey = $selectedchoicekeys[$stemid]; if (empty($selectedchoicekey)) { $parts[$stemid] = question_classified_response::no_response(); continue; } $choice = $this->choices[$selectedchoicekey]; if ($choice == get_string('deletedchoice', 'qtype_match')) { // Deleted choice, ignore. (See apply_attempt_state.) continue; } $parts[$stemid] = new question_classified_response($selectedchoicekey, $choice, ($selectedchoicekey == $this->right[$stemid]) / count($this->stems)); } return $parts; }
public function test_classify_response() { $mc = test_question_maker::make_a_multichoice_single_question(); $mc->shuffleanswers = false; $mc->start_attempt(new question_attempt_step(), 1); $this->assertEquals(array($mc->id => new question_classified_response(14, 'B', -0.3333333)), $mc->classify_response(array('answer' => 1))); $this->assertEquals(array($mc->id => question_classified_response::no_response()), $mc->classify_response(array())); }
public function test_classify_response_unit() { $num = test_question_maker::make_question('numerical', 'unit'); $num->start_attempt(new question_attempt_step(), 1); $this->assertEqual(array(new question_classified_response(13, '1.25', 0.5)), $num->classify_response(array('answer' => '1.25', 'unit' => ''))); $this->assertEqual(array(new question_classified_response(13, '1.25 m', 1.0)), $num->classify_response(array('answer' => '1.25', 'unit' => 'm'))); $this->assertEqual(array(new question_classified_response(13, '125 cm', 1.0)), $num->classify_response(array('answer' => '125', 'unit' => 'cm'))); $this->assertEqual(array(new question_classified_response(14, '123 cm', 0.5)), $num->classify_response(array('answer' => '123', 'unit' => 'cm'))); $this->assertEqual(array(new question_classified_response(14, '1.27 m', 0.5)), $num->classify_response(array('answer' => '1.27', 'unit' => 'm'))); $this->assertEqual(array(new question_classified_response(17, '3.0 m', 0)), $num->classify_response(array('answer' => '3.0', 'unit' => 'm'))); $this->assertEqual(array(question_classified_response::no_response()), $num->classify_response(array('answer' => ''))); }
public function test_classify_response() { $question = test_question_maker::make_question('calculated'); $question->start_attempt(new question_attempt_step(), 1); $values = $question->vs->get_values(); $this->assertEqual(array( new question_classified_response(13, $values['a'] + $values['b'], 1.0)), $question->classify_response(array('answer' => $values['a'] + $values['b']))); $this->assertEqual(array( new question_classified_response(14, $values['a'] - $values['b'], 0.0)), $question->classify_response(array('answer' => $values['a'] - $values['b']))); $this->assertEqual(array( new question_classified_response(17, 7 * $values['a'], 0.0)), $question->classify_response(array('answer' => 7 * $values['a']))); $this->assertEqual(array( question_classified_response::no_response()), $question->classify_response(array('answer' => ''))); }
public function test_classify_response() { $dd = test_question_maker::make_question('ddmarker'); $dd->shufflechoices = false; $dd->start_attempt(new question_attempt_step(), 1); $this->assertEquals(array(1 => new question_classified_response(1, 'quick', 1 / 3), 2 => new question_classified_response(2, 'fox', 1 / 3), 3 => new question_classified_response(3, 'lazy', 1 / 3)), $dd->classify_response(array('c1' => '50,50', 'c2' => '150,50', 'c3' => '100,150'))); $this->assertEquals(array(1 => new question_classified_response(1, 'quick', 1 / 3), 2 => question_classified_response::no_response(), 3 => question_classified_response::no_response()), $dd->classify_response(array('c1' => '50,50', 'c2' => '100,150', 'c3' => '150,50'))); }
public function test_classify_response() { $dd = test_question_maker::make_question('ddimageortext'); $dd->shufflechoices = false; $dd->start_attempt(new question_attempt_step(), 1); $this->assertEquals(array(1 => new question_classified_response(1, '1. quick', 1), 2 => new question_classified_response(2, '2. fox', 1), 3 => new question_classified_response(3, '3. lazy', 1), 4 => new question_classified_response(4, '4. dog', 1)), $dd->classify_response(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2'))); $this->assertEquals(array(1 => question_classified_response::no_response(), 2 => new question_classified_response(1, '1. quick', 0), 3 => new question_classified_response(4, '4. dog', 0), 4 => new question_classified_response(4, '4. dog', 1)), $dd->classify_response(array('p1' => '', 'p2' => '1', 'p3' => '2', 'p4' => '2'))); }
public function test_classify_response() { $gapselect = qtype_gapselect_test_helper::make_a_gapselect_question(); $gapselect->shufflechoices = false; $gapselect->start_attempt(new question_attempt_step(), 1); $this->assertEquals(array(1 => new question_classified_response(1, 'quick', 1 / 3), 2 => new question_classified_response(2, 'dog', 0), 3 => new question_classified_response(1, 'lazy', 1 / 3)), $gapselect->classify_response(array('p1' => '1', 'p2' => '2', 'p3' => '1'))); $this->assertEquals(array(1 => question_classified_response::no_response(), 2 => new question_classified_response(1, 'fox', 1 / 3), 3 => new question_classified_response(2, 'assiduous', 0)), $gapselect->classify_response(array('p1' => '0', 'p2' => '1', 'p3' => '2'))); }
public function test_classify_response_unit_no_star() { $num = test_question_maker::make_question('numerical', 'unit'); unset($num->answers[17]); $num->start_attempt(new question_attempt_step(), 1); $this->assertEquals(array(new question_classified_response(0, '42 cm', 0)), $num->classify_response(array('answer' => '42', 'unit' => 'cm'))); $this->assertEquals(array(new question_classified_response(0, '3.0', 0)), $num->classify_response(array('answer' => '3.0', 'unit' => ''))); $this->assertEquals(array(new question_classified_response(0, '3.0 m', 0)), $num->classify_response(array('answer' => '3.0', 'unit' => 'm'))); $this->assertEquals(array(question_classified_response::no_response()), $num->classify_response(array('answer' => '', 'unit' => ''))); }
public function classify_response(array $response) { $parts = array(); $hits = $this->choose_hits($response); foreach ($this->places as $placeno => $place) { if (isset($hits[$placeno])) { $shuffledchoiceno = $this->get_right_choice_for($placeno); $choice = $this->get_selected_choice(1, $shuffledchoiceno); $parts[$placeno] = new question_classified_response( $choice->no, $choice->summarise(), 1 / count($this->places)); } else { $parts[$placeno] = question_classified_response::no_response(); } } return $parts; }
public function classify_response(array $response) { if (empty($response['answer'])) { return array($this->id => question_classified_response::no_response()); } if ($this->unitdisplay == qtype_numerical::UNITSELECT) { $selectedunit = $response['unit']; } else { $selectedunit = null; } list($value, $unit) = $this->ap->apply_units($response['answer'], $selectedunit); $ans = $this->get_matching_answer($value); if (!$ans) { return array($this->id => question_classified_response::no_response()); } $resp = $response['answer']; if ($this->unitdisplay == qtype_numerical::UNITSELECT) { $resp = $this->ap->add_unit($resp, $unit); } return array($this->id => new question_classified_response($ans->id, $resp, $this->apply_unit_penalty($ans->fraction, $unit))); }
public function classify_response(array $response) { if (!$this->is_gradable_response($response)) { return array($this->id => question_classified_response::no_response()); } if ($this->has_separate_unit_field()) { $selectedunit = $response['unit']; } else { $selectedunit = null; } list($value, $unit, $multiplier) = $this->ap->apply_units($response['answer'], $selectedunit); $ans = $this->get_matching_answer($value, $multiplier); $resp = $response['answer']; if ($this->has_separate_unit_field()) { $resp = $this->ap->add_unit($resp, $unit); } if ($value === null) { // Invalid response shown as no response (but show actual response). return array($this->id => new question_classified_response(null, $resp, 0)); } else { if (!$ans) { // Does not match any answer. return array($this->id => new question_classified_response(0, $resp, 0)); } } return array($this->id => new question_classified_response($ans->id, $resp, $this->apply_unit_penalty($ans->fraction, $ans->unitisright))); }
public function test_classify_response_no_star() { $sa = test_question_maker::make_question('shortanswer', 'frogonly'); $sa->start_attempt(new question_attempt_step(), 1); $this->assertEquals(array( new question_classified_response(13, 'frog', 1.0)), $sa->classify_response(array('answer' => 'frog'))); $this->assertEquals(array( new question_classified_response(0, 'toad', 0.0)), $sa->classify_response(array('answer' => 'toad'))); $this->assertEquals(array( question_classified_response::no_response()), $sa->classify_response(array('answer' => ''))); }
public function test_classify_response() { $sa = test_regexp_question_maker::make_a_regexp_question(); $sa->start_attempt(new question_attempt_step(), 1); $this->assertEqual(array(new question_classified_response(13, "it's blue, white and red", 1.0)), $sa->classify_response(array('answer' => "it's blue, white and red"))); $this->assertEqual(array(new question_classified_response(14, 'they are blue, white, red', 0.8)), $sa->classify_response(array('answer' => 'they are blue, white, red'))); $this->assertEqual(array(new question_classified_response(14, 'it is blue, white, red', 0.8)), $sa->classify_response(array('answer' => 'it is blue, white, red'))); $this->assertEqual(array(new question_classified_response(14, 'blue, white, red', 0.8)), $sa->classify_response(array('answer' => 'blue, white, red'))); $this->assertEqual(array(new question_classified_response(15, 'red and white', 0.0)), $sa->classify_response(array('answer' => 'red and white'))); $this->assertEqual(array(new question_classified_response(15, 'black', 0.0)), $sa->classify_response(array('answer' => 'black'))); $this->assertEqual(array(question_classified_response::no_response()), $sa->classify_response(array('answer' => ''))); }
/** * Analyse the data from one question attempt. * @param question_attempt $qa the data to analyse. */ protected function add_data_from_one_attempt(question_attempt $qa) { $blankresponse = question_classified_response::no_response(); $partresponses = $qa->classify_response(); foreach ($partresponses as $subpartid => $partresponse) { if (!isset($this->responses[$subpartid][$partresponse->responseclassid][$partresponse->response])) { $resp = new stdClass(); $resp->count = 0; if (!is_null($partresponse->fraction)) { $resp->fraction = $partresponse->fraction; } else { $resp->fraction = $this->responseclasses[$subpartid][$partresponse->responseclassid]->fraction; } $this->responses[$subpartid][$partresponse->responseclassid][$partresponse->response] = $resp; } $this->responses[$subpartid][$partresponse->responseclassid][$partresponse->response]->count += 1; } }
public function classify_response(array $response) { $classification = array(); foreach ($this->prts as $index => $prt) { if (!$this->can_execute_prt($prt, $response, true)) { foreach ($prt->get_nodes_summary() as $nodeid => $choices) { $classification[$index . '-' . $nodeid] = question_classified_response::no_response(); } continue; } $prtinput = $this->get_prt_input($index, $response, true); $results = $this->prts[$index]->evaluate_response($this->session, $this->options, $prtinput, $this->seed); $answernotes = implode(' | ', $results->answernotes); foreach ($prt->get_nodes_summary() as $nodeid => $choices) { if (in_array($choices->truenote, $results->answernotes)) { $classification[$index . '-' . $nodeid] = new question_classified_response($choices->truenote, $answernotes, $results->fraction); } else { if (in_array($choices->falsenote, $results->answernotes)) { $classification[$index . '-' . $nodeid] = new question_classified_response($choices->falsenote, $answernotes, $results->fraction); } else { $classification[$index . '-' . $nodeid] = question_classified_response::no_response(); } } } } return $classification; }
public function classify_response(array $response) { $selectedchoices = array(); foreach ($this->stemorder as $key => $stemid) { if (array_key_exists($this->field($key), $response) && $response[$this->field($key)]) { $selectedchoices[$stemid] = $this->choiceorder[$response[$this->field($key)]]; } else { $selectedchoices[$stemid] = 0; } } $parts = array(); foreach ($this->stems as $stemid => $stem) { if (empty($selectedchoices[$stemid])) { $parts[$stemid] = question_classified_response::no_response(); continue; } $choice = $this->choices[$selectedchoices[$stemid]]; $parts[$stemid] = new question_classified_response($selectedchoices[$stemid], $choice, ($selectedchoices[$stemid] == $this->right[$stemid]) / count($this->stems)); } return $parts; }
public function classify_response(array $response) { $parts = array(); foreach ($this->places as $placeno => $place) { $group = $place->group; if (!array_key_exists($this->field($placeno), $response) || !$response[$this->field($placeno)]) { $parts[$placeno] = question_classified_response::no_response(); continue; } $fieldname = $this->field($placeno); $choiceno = $this->choiceorder[$group][$response[$fieldname]]; $choice = $this->choices[$group][$choiceno]; $correct = $this->get_right_choice_for($placeno) == $response[$fieldname]; $parts[$placeno] = new question_classified_response($choiceno, $choice->summarise(), $correct ? 1 : 0); } return $parts; }
public function classify_response(array $response) { if (empty($response['answer'])) { return array($this->id => question_classified_response::no_response()); } $ans = $this->get_matching_answer($response); if (!$ans) { return array($this->id => question_classified_response::no_response()); } return array($this->id => new question_classified_response( $ans->id, $response['answer'], $ans->fraction)); }
public function test_classify_response() { $sa = test_question_maker::make_a_shortanswer_question(); $sa->start_attempt(new question_attempt_step(), 1); $this->assertEqual(array(new question_classified_response(13, 'frog', 1.0)), $sa->classify_response(array('answer' => 'frog'))); $this->assertEqual(array(new question_classified_response(14, 'toad', 0.8)), $sa->classify_response(array('answer' => 'toad'))); $this->assertEqual(array(new question_classified_response(15, 'cat', 0.0)), $sa->classify_response(array('answer' => 'cat'))); $this->assertEqual(array(question_classified_response::no_response()), $sa->classify_response(array('answer' => ''))); }
public function classify_response(array $response) { if (empty($response['answer'])) { return array($this->id => question_classified_response::no_response()); } if ($this->has_separate_unit_field()) { $selectedunit = $response['unit']; } else { $selectedunit = null; } list($value, $unit, $multiplier) = $this->ap->apply_units($response['answer'], $selectedunit); $ans = $this->get_matching_answer($value, $multiplier); $resp = $response['answer']; if ($this->has_separate_unit_field()) { $resp = $this->ap->add_unit($resp, $unit); } if (!$ans) { return array($this->id => new question_classified_response(0, $resp, 0)); } return array($this->id => new question_classified_response($ans->id, $resp, $this->apply_unit_penalty($ans->fraction, $ans->unitisright))); }
public function test_classify_response() { $match = test_question_maker::make_a_matching_question(); $match->start_attempt(new question_attempt_step(), 1); $response = $match->prepare_simulated_post_data(array(0 => 'Amphibian', 1 => 'Insect', 2 => '', 3 => '')); $this->assertEquals(array(1 => new question_classified_response(2, 'Amphibian', 0), 2 => new question_classified_response(3, 'Insect', 0), 3 => question_classified_response::no_response(), 4 => question_classified_response::no_response()), $match->classify_response($response)); $response = $match->prepare_simulated_post_data(array(0 => 'Mammal', 1 => 'Amphibian', 2 => 'Amphibian', 3 => 'Mammal')); $this->assertEquals(array(1 => new question_classified_response(1, 'Mammal', 0.25), 2 => new question_classified_response(2, 'Amphibian', 0.25), 3 => new question_classified_response(2, 'Amphibian', 0.25), 4 => new question_classified_response(1, 'Mammal', 0.25)), $match->classify_response($response)); }
public function classify_response(array $response) { if (!array_key_exists('answer', $response) || !array_key_exists($response['answer'], $this->order)) { return array($this->id => question_classified_response::no_response()); } $choiceid = $this->order[$response['answer']]; $ans = $this->answers[$choiceid]; return array($this->id => new question_classified_response($choiceid, $this->html_to_text($ans->answer, $ans->answerformat), $ans->fraction)); }
public function test_classify_response() { $ddmatch = qtype_ddmatch_test_helper::make_a_ddmatching_question(); $ddmatch->shufflestems = false; $ddmatch->start_attempt(new question_attempt_step(), 1); $choiceorder = $ddmatch->get_choice_order(); $orderforchoice = array_combine(array_values($choiceorder), array_keys($choiceorder)); $choices = array(0 => get_string('choose') . '...'); foreach ($choiceorder as $key => $choice) { $choices[$key] = $ddmatch->choices[$choice]; } $this->assertEquals(array(1 => new question_classified_response(2, 'Amphibian', 0), 2 => new question_classified_response(3, 'Insect', 0), 3 => question_classified_response::no_response(), 4 => question_classified_response::no_response()), $ddmatch->classify_response(array('sub0' => $orderforchoice[2], 'sub1' => $orderforchoice[3], 'sub2' => 0, 'sub3' => 0))); $this->assertEquals(array(1 => new question_classified_response(1, 'Mammal', 0.25), 2 => new question_classified_response(2, 'Amphibian', 0.25), 3 => new question_classified_response(2, 'Amphibian', 0.25), 4 => new question_classified_response(1, 'Mammal', 0.25)), $ddmatch->classify_response(array('sub0' => $orderforchoice[1], 'sub1' => $orderforchoice[2], 'sub2' => $orderforchoice[2], 'sub3' => $orderforchoice[1]))); }
public function classify_response(array $response) { $parts = array(); foreach ($this->places as $place => $group) { if (!array_key_exists($this->field($place), $response) || !$response[$this->field($place)]) { $parts[$place] = question_classified_response::no_response(); continue; } $fieldname = $this->field($place); $choiceno = $this->choiceorder[$group][$response[$fieldname]]; $choice = $this->choices[$group][$choiceno]; $parts[$place] = new question_classified_response($choiceno, html_to_text($choice->text, 0, false), ($this->get_right_choice_for($place) == $response[$fieldname]) / count($this->places)); } return $parts; }
public function test_classify_response_test0() { $q = test_question_maker::make_question('stack', 'test0'); $q->start_attempt(new question_attempt_step(), 4); $expected = array('firsttree-0' => new question_classified_response('firsttree-1-F', 'ATEqualComAss: (AlgEquiv:false). | firsttree-1-F', 0)); $this->assertEquals($expected, $q->classify_response(array('ans1' => '7'))); $expected = array('firsttree-0' => new question_classified_response('firsttree-1-T', 'firsttree-1-T', 1)); $this->assertEquals($expected, $q->classify_response(array('ans1' => '2'))); $expected = array('firsttree-0' => question_classified_response::no_response()); $this->assertEquals($expected, $q->classify_response(array('ans1' => ''))); }