PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/question/behaviour/adaptivenopenalty/simpletest/testwalkthrough.php

https://github.com/kpike/moodle
PHP | 194 lines | 112 code | 31 blank | 51 comment | 1 complexity | 323a84f108a9bb139b4d7f990aeac00b MD5 | raw file
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * This file contains tests that walks a question through the adaptive (no penalties)k
  18. * behaviour.
  19. *
  20. * @package qbehaviour
  21. * @subpackage adaptivenopenalty
  22. * @copyright 2009 The Open University
  23. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24. */
  25. defined('MOODLE_INTERNAL') || die();
  26. require_once(dirname(__FILE__) . '/../../../engine/lib.php');
  27. require_once(dirname(__FILE__) . '/../../../engine/simpletest/helpers.php');
  28. /**
  29. * Unit tests for the adaptive (no penalties) behaviour.
  30. *
  31. * @copyright 2009 The Open University
  32. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33. */
  34. class qbehaviour_adaptivenopenalty_walkthrough_test extends qbehaviour_walkthrough_test_base {
  35. public function test_multichoice() {
  36. // Create a multiple choice, single response question.
  37. $mc = test_question_maker::make_a_multichoice_single_question();
  38. $mc->penalty = 0.3333333;
  39. $this->start_attempt_at_question($mc, 'adaptivenopenalty', 3);
  40. $rightindex = $this->get_mc_right_answer_index($mc);
  41. $wrongindex = ($rightindex + 1) % 3;
  42. // Check the initial state.
  43. $this->check_current_state(question_state::$todo);
  44. $this->check_current_mark(null);
  45. $this->check_current_output(
  46. $this->get_contains_marked_out_of_summary(),
  47. $this->get_contains_question_text_expectation($mc),
  48. $this->get_contains_mc_radio_expectation(0, true, false),
  49. $this->get_contains_mc_radio_expectation(1, true, false),
  50. $this->get_contains_mc_radio_expectation(2, true, false),
  51. $this->get_contains_submit_button_expectation(true),
  52. $this->get_does_not_contain_feedback_expectation());
  53. // Process a submit.
  54. $this->process_submission(array('answer' => $wrongindex, '-submit' => 1));
  55. // Verify.
  56. $this->check_current_state(question_state::$todo);
  57. $this->check_current_mark(0);
  58. $this->check_current_output(
  59. $this->get_contains_mark_summary(0),
  60. $this->get_contains_mc_radio_expectation($wrongindex, true, true),
  61. $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false),
  62. $this->get_contains_mc_radio_expectation(($wrongindex + 2) % 3, true, false),
  63. $this->get_contains_incorrect_expectation());
  64. $this->assertPattern('/B|C/',
  65. $this->quba->get_response_summary($this->slot));
  66. // Process a change of answer to the right one, but not sumbitted.
  67. $this->process_submission(array('answer' => $rightindex));
  68. // Verify.
  69. $this->check_current_state(question_state::$todo);
  70. $this->check_current_mark(0);
  71. $this->check_current_output(
  72. $this->get_contains_mark_summary(0),
  73. $this->get_contains_mc_radio_expectation($rightindex, true, true),
  74. $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false),
  75. $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, true, false));
  76. $this->assertPattern('/B|C/',
  77. $this->quba->get_response_summary($this->slot));
  78. // Now submit the right answer.
  79. $this->process_submission(array('answer' => $rightindex, '-submit' => 1));
  80. // Verify.
  81. $this->check_current_state(question_state::$complete);
  82. $this->check_current_mark(3);
  83. $this->check_current_output(
  84. $this->get_contains_mark_summary(3),
  85. $this->get_contains_mc_radio_expectation($rightindex, true, true),
  86. $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false),
  87. $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, true, false),
  88. $this->get_contains_correct_expectation());
  89. $this->assertEqual('A',
  90. $this->quba->get_response_summary($this->slot));
  91. // Finish the attempt.
  92. $this->quba->finish_all_questions();
  93. // Verify.
  94. $this->check_current_state(question_state::$gradedright);
  95. $this->check_current_mark(3);
  96. $this->check_current_output(
  97. $this->get_contains_mark_summary(3),
  98. $this->get_contains_mc_radio_expectation($rightindex, false, true),
  99. $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false),
  100. $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, false, false),
  101. $this->get_contains_correct_expectation());
  102. // Process a manual comment.
  103. $this->manual_grade('Not good enough!', 1);
  104. // Verify.
  105. $this->check_current_state(question_state::$mangrpartial);
  106. $this->check_current_mark(1);
  107. $this->check_current_output(
  108. $this->get_contains_mark_summary(1),
  109. new PatternExpectation('/' . preg_quote('Not good enough!') . '/'));
  110. // Now change the correct answer to the question, and regrade.
  111. $mc->answers[13]->fraction = -0.33333333;
  112. $mc->answers[15]->fraction = 1;
  113. $this->quba->regrade_all_questions();
  114. // Verify.
  115. $this->check_current_state(question_state::$mangrpartial);
  116. $this->check_current_mark(1);
  117. $this->check_current_output(
  118. $this->get_contains_mark_summary(1),
  119. $this->get_contains_partcorrect_expectation());
  120. $autogradedstep = $this->get_step($this->get_step_count() - 2);
  121. $this->assertWithinMargin($autogradedstep->get_fraction(), 0, 0.0000001);
  122. }
  123. public function test_multichoice2() {
  124. // Create a multiple choice, multiple response question.
  125. $mc = test_question_maker::make_a_multichoice_multi_question();
  126. $mc->penalty = 0.3333333;
  127. $mc->shuffleanswers = 0;
  128. $this->start_attempt_at_question($mc, 'adaptivenopenalty', 2);
  129. // Check the initial state.
  130. $this->check_current_state(question_state::$todo);
  131. $this->check_current_mark(null);
  132. $this->check_current_output(
  133. $this->get_contains_marked_out_of_summary(),
  134. $this->get_contains_question_text_expectation($mc),
  135. $this->get_contains_submit_button_expectation(true),
  136. $this->get_does_not_contain_feedback_expectation());
  137. // Process a submit.
  138. $this->process_submission(array('choice0' => 1, 'choice2' => 1, '-submit' => 1));
  139. // Verify.
  140. $this->check_current_state(question_state::$complete);
  141. $this->check_current_mark(2);
  142. $this->check_current_output(
  143. $this->get_contains_mark_summary(2),
  144. $this->get_contains_submit_button_expectation(true),
  145. $this->get_contains_correct_expectation());
  146. // Save the same correct answer again. Should no do anything.
  147. $numsteps = $this->get_step_count();
  148. $this->process_submission(array('choice0' => 1, 'choice2' => 1));
  149. // Verify.
  150. $this->check_step_count($numsteps);
  151. $this->check_current_state(question_state::$complete);
  152. // Finish the attempt.
  153. $this->quba->finish_all_questions();
  154. // Verify.
  155. $this->check_step_count($numsteps + 1);
  156. $this->check_current_state(question_state::$gradedright);
  157. $this->check_current_mark(2);
  158. $this->check_current_output(
  159. $this->get_contains_mark_summary(2),
  160. $this->get_contains_submit_button_expectation(false),
  161. $this->get_contains_correct_expectation());
  162. }
  163. }