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 test_ddmatch_clear_wrong()
 {
     // Create a ddmatching question.
     $m = qtype_ddmatch_test_helper::make_a_ddmatching_question();
     $m->hints = array(new question_hint_with_parts(11, 'This is the first hint.', FORMAT_HTML, false, true), new question_hint_with_parts(12, 'This is the second hint.', FORMAT_HTML, true, true));
     $m->shufflestems = false;
     $this->start_attempt_at_question($m, 'interactive', 4);
     $choiceorder = $m->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] = $m->choices[$choice];
     }
     // Check the initial state.
     $this->check_current_state(question_state::$todo);
     $this->check_current_mark(null);
     $this->check_current_output($this->get_contains_select_expectation('sub0', $choices, null, true), $this->get_contains_select_expectation('sub1', $choices, null, true), $this->get_contains_select_expectation('sub2', $choices, null, true), $this->get_contains_select_expectation('sub3', $choices, null, true), $this->get_contains_submit_button_expectation(true), $this->get_does_not_contain_feedback_expectation(), $this->get_tries_remaining_expectation(3), $this->get_no_hint_visible_expectation());
     // Submit a completely wrong response.
     $this->process_submission(array('sub0' => $orderforchoice[3], 'sub1' => $orderforchoice[3], 'sub2' => $orderforchoice[3], 'sub3' => $orderforchoice[3], '-submit' => 1));
     // Verify.
     $this->check_current_state(question_state::$todo);
     $this->check_current_mark(null);
     $this->check_current_output($this->get_contains_select_expectation('sub0', $choices, $orderforchoice[3], false), $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[3], false), $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[3], false), $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[3], false), $this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub0', '0'), $this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub1', '0'), $this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub2', '0'), $this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub3', '0'), $this->get_contains_submit_button_expectation(false), $this->get_contains_hint_expectation('This is the first hint.'));
     // Try again.
     $this->process_submission(array('sub0' => 0, 'sub1' => 0, 'sub2' => 0, 'sub3' => 0, '-tryagain' => 1));
     // Verify.
     $this->check_current_state(question_state::$todo);
     $this->check_current_mark(null);
     $this->check_current_output($this->get_contains_select_expectation('sub0', $choices, null, true), $this->get_contains_select_expectation('sub1', $choices, null, true), $this->get_contains_select_expectation('sub2', $choices, null, true), $this->get_contains_select_expectation('sub3', $choices, null, true), $this->get_contains_submit_button_expectation(true), $this->get_does_not_contain_feedback_expectation(), $this->get_tries_remaining_expectation(2), $this->get_no_hint_visible_expectation());
     // Submit a partially wrong response.
     $this->process_submission(array('sub0' => $orderforchoice[3], 'sub1' => $orderforchoice[3], 'sub2' => $orderforchoice[2], 'sub3' => $orderforchoice[1], '-submit' => 1));
     // Verify.
     $this->check_current_state(question_state::$todo);
     $this->check_current_mark(null);
     $this->check_current_output($this->get_contains_select_expectation('sub0', $choices, $orderforchoice[3], false), $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[3], false), $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[2], false), $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], false), $this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub0', '0'), $this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub1', '0'), $this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub2', $orderforchoice[2]), $this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub3', $orderforchoice[1]), $this->get_contains_submit_button_expectation(false), $this->get_contains_hint_expectation('This is the second hint.'));
     // Try again.
     $this->process_submission(array('sub0' => 0, 'sub1' => 0, 'sub2' => $orderforchoice[2], 'sub3' => $orderforchoice[1], '-tryagain' => 1));
     // Verify.
     $this->check_current_state(question_state::$todo);
     $this->check_current_mark(null);
     $this->check_current_output($this->get_contains_select_expectation('sub0', $choices, null, true), $this->get_contains_select_expectation('sub1', $choices, null, true), $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[2], true), $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], true), $this->get_contains_submit_button_expectation(true), $this->get_does_not_contain_feedback_expectation(), $this->get_tries_remaining_expectation(1), $this->get_no_hint_visible_expectation());
 }