PageRenderTime 29ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/question/behaviour/adaptive/tests/walkthrough_test.php

https://bitbucket.org/kudutest1/moodlegit
PHP | 747 lines | 506 code | 117 blank | 124 comment | 1 complexity | dcb2b7e45fd78969b70d6f652669f565 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
  18. * behaviour.
  19. *
  20. * @package qbehaviour
  21. * @subpackage adaptive
  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. global $CFG;
  27. require_once(dirname(__FILE__) . '/../../../engine/lib.php');
  28. require_once(dirname(__FILE__) . '/../../../engine/tests/helpers.php');
  29. /**
  30. * Unit tests for the adaptive behaviour.
  31. *
  32. * @copyright 2009 The Open University
  33. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34. */
  35. class qbehaviour_adaptive_walkthrough_test extends qbehaviour_walkthrough_test_base {
  36. protected function get_contains_penalty_info_expectation($penalty) {
  37. $penaltyinfo = get_string('gradingdetailspenalty', 'qbehaviour_adaptive',
  38. format_float($penalty, $this->displayoptions->markdp));
  39. return new question_pattern_expectation('/'.preg_quote($penaltyinfo, '/').'/');
  40. }
  41. protected function get_does_not_contain_penalty_info_expectation() {
  42. $penaltyinfo = get_string('gradingdetailspenalty', 'qbehaviour_adaptive', 'XXXXX');
  43. $penaltypattern = '/'.str_replace('XXXXX', '\\w*', preg_quote($penaltyinfo, '/')).'/';
  44. return new question_no_pattern_expectation($penaltypattern);
  45. }
  46. protected function get_contains_total_penalty_expectation($penalty) {
  47. $penaltyinfo = get_string('gradingdetailspenaltytotal', 'qbehaviour_adaptive',
  48. format_float($penalty, $this->displayoptions->markdp));
  49. return new question_pattern_expectation('/'.preg_quote($penaltyinfo, '/').'/');
  50. }
  51. protected function get_does_not_contain_total_penalty_expectation() {
  52. $penaltyinfo = get_string('gradingdetailspenaltytotal', 'qbehaviour_adaptive', 'XXXXX');
  53. $penaltypattern = '/'.str_replace('XXXXX', '\\w*', preg_quote($penaltyinfo, '/')).'/';
  54. return new question_no_pattern_expectation($penaltypattern);
  55. }
  56. protected function get_contains_disregarded_info_expectation() {
  57. $penaltyinfo = get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive');
  58. return new question_pattern_expectation('/'.preg_quote($penaltyinfo, '/').'/');
  59. }
  60. protected function get_does_not_contain_disregarded_info_expectation() {
  61. $penaltyinfo = get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive');
  62. return new question_no_pattern_expectation('/'.preg_quote($penaltyinfo, '/').'/');
  63. }
  64. public function test_adaptive_multichoice() {
  65. // Create a multiple choice, single response question.
  66. $mc = test_question_maker::make_a_multichoice_single_question();
  67. $mc->penalty = 0.3333333;
  68. $this->start_attempt_at_question($mc, 'adaptive', 3);
  69. $rightindex = $this->get_mc_right_answer_index($mc);
  70. $wrongindex = ($rightindex + 1) % 3;
  71. // Check the initial state.
  72. $this->check_current_state(question_state::$todo);
  73. $this->check_current_mark(null);
  74. $this->check_current_output(
  75. $this->get_contains_marked_out_of_summary(),
  76. $this->get_contains_question_text_expectation($mc),
  77. $this->get_contains_mc_radio_expectation(0, true, false),
  78. $this->get_contains_mc_radio_expectation(1, true, false),
  79. $this->get_contains_mc_radio_expectation(2, true, false),
  80. $this->get_contains_submit_button_expectation(true),
  81. $this->get_does_not_contain_feedback_expectation());
  82. // Process a submit.
  83. $this->process_submission(array('answer' => $wrongindex, '-submit' => 1));
  84. // Verify.
  85. $this->check_current_state(question_state::$todo);
  86. $this->check_current_mark(0);
  87. $this->check_current_output(
  88. $this->get_contains_mark_summary(0),
  89. $this->get_contains_mc_radio_expectation($wrongindex, true, true),
  90. $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false),
  91. $this->get_contains_mc_radio_expectation(($wrongindex + 2) % 3, true, false),
  92. $this->get_contains_incorrect_expectation(),
  93. $this->get_contains_penalty_info_expectation(1.00),
  94. $this->get_does_not_contain_total_penalty_expectation());
  95. $this->assertRegExp('/B|C/',
  96. $this->quba->get_response_summary($this->slot));
  97. // Process a change of answer to the right one, but not sumbitted.
  98. $this->process_submission(array('answer' => $rightindex));
  99. // Verify.
  100. $this->check_current_state(question_state::$todo);
  101. $this->check_current_mark(0);
  102. $this->check_current_output(
  103. $this->get_contains_mark_summary(0),
  104. $this->get_contains_mc_radio_expectation($rightindex, true, true),
  105. $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false),
  106. $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, true, false));
  107. $this->assertRegExp('/B|C/',
  108. $this->quba->get_response_summary($this->slot));
  109. // Now submit the right answer.
  110. $this->process_submission(array('answer' => $rightindex, '-submit' => 1));
  111. // Verify.
  112. $this->check_current_state(question_state::$complete);
  113. $this->check_current_mark(3 * (1 - $mc->penalty));
  114. $this->check_current_output(
  115. $this->get_contains_mark_summary(3 * (1 - $mc->penalty)),
  116. $this->get_contains_mc_radio_expectation($rightindex, true, true),
  117. $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false),
  118. $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, true, false),
  119. $this->get_contains_correct_expectation(),
  120. $this->get_does_not_contain_penalty_info_expectation(),
  121. $this->get_does_not_contain_total_penalty_expectation());
  122. $this->assertEquals('A',
  123. $this->quba->get_response_summary($this->slot));
  124. // Finish the attempt.
  125. $this->quba->finish_all_questions();
  126. // Verify.
  127. $this->check_current_state(question_state::$gradedright);
  128. $this->check_current_mark(3 * (1 - $mc->penalty));
  129. $this->check_current_output(
  130. $this->get_contains_mark_summary(3 * (1 - $mc->penalty)),
  131. $this->get_contains_mc_radio_expectation($rightindex, false, true),
  132. $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false),
  133. $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, false, false),
  134. $this->get_contains_correct_expectation());
  135. // Process a manual comment.
  136. $this->manual_grade('Not good enough!', 1, FORMAT_HTML);
  137. // Verify.
  138. $this->check_current_state(question_state::$mangrpartial);
  139. $this->check_current_mark(1);
  140. $this->check_current_output(
  141. $this->get_contains_mark_summary(1),
  142. new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
  143. // Now change the correct answer to the question, and regrade.
  144. $mc->answers[13]->fraction = -0.33333333;
  145. $mc->answers[14]->fraction = 1; // We don't know which "wrong" index we chose above!
  146. $mc->answers[15]->fraction = 1; // Therefore, treat answers B and C with the same score.
  147. $this->quba->regrade_all_questions();
  148. // Verify.
  149. $this->check_current_state(question_state::$mangrpartial);
  150. $this->check_current_mark(1);
  151. $this->check_current_output(
  152. $this->get_contains_mark_summary(1),
  153. $this->get_contains_partcorrect_expectation());
  154. $autogradedstep = $this->get_step($this->get_step_count() - 2);
  155. $this->assertEquals($autogradedstep->get_fraction(), 1, '', 0.0000001);
  156. }
  157. public function test_adaptive_multichoice2() {
  158. // Create a multiple choice, multiple response question.
  159. $mc = test_question_maker::make_a_multichoice_multi_question();
  160. $mc->penalty = 0.3333333;
  161. $mc->shuffleanswers = 0;
  162. $this->start_attempt_at_question($mc, 'adaptive', 2);
  163. // Check the initial state.
  164. $this->check_current_state(question_state::$todo);
  165. $this->check_current_mark(null);
  166. $this->check_current_output(
  167. $this->get_contains_marked_out_of_summary(),
  168. $this->get_contains_question_text_expectation($mc),
  169. $this->get_contains_submit_button_expectation(true),
  170. $this->get_does_not_contain_feedback_expectation());
  171. // Process a submit.
  172. $this->process_submission(array('choice0' => 1, 'choice2' => 1, '-submit' => 1));
  173. // Verify.
  174. $this->check_current_state(question_state::$complete);
  175. $this->check_current_mark(2);
  176. $this->check_current_output(
  177. $this->get_contains_mark_summary(2),
  178. $this->get_contains_submit_button_expectation(true),
  179. $this->get_contains_correct_expectation(),
  180. $this->get_does_not_contain_penalty_info_expectation(),
  181. $this->get_does_not_contain_total_penalty_expectation());
  182. // Save the same correct answer again. Should not do anything.
  183. $numsteps = $this->get_step_count();
  184. $this->process_submission(array('choice0' => 1, 'choice2' => 1));
  185. // Verify.
  186. $this->check_step_count($numsteps);
  187. $this->check_current_mark(2);
  188. $this->check_current_state(question_state::$complete);
  189. // Finish the attempt.
  190. $this->quba->finish_all_questions();
  191. // Verify.
  192. $this->check_step_count($numsteps + 1);
  193. $this->check_current_state(question_state::$gradedright);
  194. $this->check_current_mark(2);
  195. $this->check_current_output(
  196. $this->get_contains_mark_summary(2),
  197. $this->get_contains_submit_button_expectation(false),
  198. $this->get_contains_correct_expectation());
  199. }
  200. public function test_adaptive_shortanswer_partially_right() {
  201. // Create a short answer question
  202. $sa = test_question_maker::make_question('shortanswer');
  203. $this->start_attempt_at_question($sa, 'adaptive');
  204. // Check the initial state.
  205. $this->check_current_state(question_state::$todo);
  206. $this->check_current_mark(null);
  207. $this->check_current_output(
  208. $this->get_contains_marked_out_of_summary(),
  209. $this->get_contains_submit_button_expectation(true),
  210. $this->get_does_not_contain_feedback_expectation());
  211. // Submit a partially correct answer.
  212. $this->process_submission(array('-submit' => 1, 'answer' => 'toad'));
  213. // Verify.
  214. $this->check_current_state(question_state::$todo);
  215. $this->check_current_mark(0.8);
  216. $this->check_current_output(
  217. $this->get_contains_mark_summary(0.8),
  218. $this->get_contains_submit_button_expectation(true),
  219. $this->get_contains_partcorrect_expectation(),
  220. $this->get_contains_penalty_info_expectation(0.33),
  221. $this->get_does_not_contain_total_penalty_expectation(),
  222. $this->get_does_not_contain_validation_error_expectation());
  223. // Submit an incorrect answer.
  224. $this->process_submission(array('-submit' => 1, 'answer' => 'bumblebee'));
  225. // Verify.
  226. $this->check_current_state(question_state::$todo);
  227. $this->check_current_mark(0.8);
  228. $this->check_current_output(
  229. $this->get_contains_mark_summary(0.8),
  230. $this->get_contains_submit_button_expectation(true),
  231. $this->get_contains_incorrect_expectation(),
  232. $this->get_contains_penalty_info_expectation(0.33),
  233. $this->get_contains_total_penalty_expectation(0.67),
  234. $this->get_does_not_contain_validation_error_expectation());
  235. // Submit a correct answer.
  236. $this->process_submission(array('-submit' => 1, 'answer' => 'frog'));
  237. // Verify.
  238. $this->check_current_state(question_state::$complete);
  239. $this->check_current_mark(0.8);
  240. $this->check_current_output(
  241. $this->get_contains_mark_summary(0.8),
  242. $this->get_contains_submit_button_expectation(true),
  243. $this->get_contains_correct_expectation(),
  244. $this->get_does_not_contain_penalty_info_expectation(),
  245. $this->get_does_not_contain_total_penalty_expectation(),
  246. $this->get_does_not_contain_validation_error_expectation());
  247. // Finish the attempt.
  248. $this->quba->finish_all_questions();
  249. // Verify.
  250. $this->check_current_state(question_state::$gradedright);
  251. $this->check_current_mark(0.8);
  252. $this->check_current_output(
  253. $this->get_contains_mark_summary(0.8),
  254. $this->get_contains_submit_button_expectation(false),
  255. $this->get_contains_correct_expectation(),
  256. $this->get_does_not_contain_validation_error_expectation());
  257. }
  258. public function test_adaptive_shortanswer_wrong_right_wrong() {
  259. // Create a short answer question
  260. $sa = test_question_maker::make_question('shortanswer');
  261. $this->start_attempt_at_question($sa, 'adaptive', 6);
  262. // Check the initial state.
  263. $this->check_current_state(question_state::$todo);
  264. $this->check_current_mark(null);
  265. $this->check_current_output(
  266. $this->get_contains_marked_out_of_summary(),
  267. $this->get_contains_submit_button_expectation(true),
  268. $this->get_does_not_contain_feedback_expectation());
  269. // Submit a wrong answer.
  270. $this->process_submission(array('-submit' => 1, 'answer' => 'hippopotamus'));
  271. // Verify.
  272. $this->check_current_state(question_state::$todo);
  273. $this->check_current_mark(0);
  274. $this->check_current_output(
  275. $this->get_contains_mark_summary(0),
  276. $this->get_contains_submit_button_expectation(true),
  277. $this->get_contains_incorrect_expectation(),
  278. $this->get_contains_penalty_info_expectation(2.00),
  279. $this->get_does_not_contain_total_penalty_expectation(),
  280. $this->get_does_not_contain_validation_error_expectation());
  281. // Submit the same wrong answer again. Nothing should change.
  282. $this->process_submission(array('-submit' => 1, 'answer' => 'hippopotamus'));
  283. // Verify.
  284. $this->check_current_state(question_state::$todo);
  285. $this->check_current_mark(0);
  286. $this->check_current_output(
  287. $this->get_contains_mark_summary(0),
  288. $this->get_contains_submit_button_expectation(true),
  289. $this->get_contains_incorrect_expectation(),
  290. $this->get_contains_penalty_info_expectation(2.00),
  291. $this->get_does_not_contain_total_penalty_expectation(),
  292. $this->get_does_not_contain_validation_error_expectation());
  293. // Submit a correct answer.
  294. $this->process_submission(array('-submit' => 1, 'answer' => 'frog'));
  295. // Verify.
  296. $this->check_current_state(question_state::$complete);
  297. $this->check_current_mark(4.00);
  298. $this->check_current_output(
  299. $this->get_contains_mark_summary(4.00),
  300. $this->get_contains_submit_button_expectation(true),
  301. $this->get_contains_correct_expectation(),
  302. $this->get_does_not_contain_penalty_info_expectation(),
  303. $this->get_does_not_contain_total_penalty_expectation(),
  304. $this->get_does_not_contain_validation_error_expectation());
  305. // Submit another incorrect answer.
  306. $this->process_submission(array('-submit' => 1, 'answer' => 'bumblebee'));
  307. // Verify.
  308. $this->check_current_state(question_state::$complete);
  309. $this->check_current_mark(4.00);
  310. $this->check_current_output(
  311. $this->get_contains_mark_summary(4.00),
  312. $this->get_contains_submit_button_expectation(true),
  313. $this->get_contains_incorrect_expectation(),
  314. $this->get_does_not_contain_penalty_info_expectation(),
  315. $this->get_does_not_contain_total_penalty_expectation(),
  316. $this->get_does_not_contain_validation_error_expectation());
  317. // Finish the attempt.
  318. $this->quba->finish_all_questions();
  319. // Verify.
  320. $this->check_current_state(question_state::$gradedwrong);
  321. $this->check_current_mark(4.00);
  322. $this->check_current_output(
  323. $this->get_contains_mark_summary(4.00),
  324. $this->get_contains_submit_button_expectation(false),
  325. $this->get_contains_incorrect_expectation(),
  326. $this->get_does_not_contain_validation_error_expectation());
  327. }
  328. public function test_adaptive_shortanswer_invalid_after_complete() {
  329. // Create a short answer question
  330. $sa = test_question_maker::make_question('shortanswer');
  331. $this->start_attempt_at_question($sa, 'adaptive');
  332. // Check the initial state.
  333. $this->check_current_state(question_state::$todo);
  334. $this->check_current_mark(null);
  335. $this->check_current_output(
  336. $this->get_contains_marked_out_of_summary(),
  337. $this->get_contains_submit_button_expectation(true),
  338. $this->get_does_not_contain_feedback_expectation());
  339. // Submit a wrong answer.
  340. $this->process_submission(array('-submit' => 1, 'answer' => 'hippopotamus'));
  341. // Verify.
  342. $this->check_current_state(question_state::$todo);
  343. $this->check_current_mark(0);
  344. $this->check_current_output(
  345. $this->get_contains_mark_summary(0),
  346. $this->get_contains_submit_button_expectation(true),
  347. $this->get_contains_incorrect_expectation(),
  348. $this->get_contains_penalty_info_expectation(0.33),
  349. $this->get_does_not_contain_total_penalty_expectation(),
  350. $this->get_does_not_contain_validation_error_expectation());
  351. // Submit a correct answer.
  352. $this->process_submission(array('-submit' => 1, 'answer' => 'frog'));
  353. // Verify.
  354. $this->check_current_state(question_state::$complete);
  355. $this->check_current_mark(0.66666667);
  356. $this->check_current_output(
  357. $this->get_contains_mark_summary(0.67),
  358. $this->get_contains_submit_button_expectation(true),
  359. $this->get_contains_correct_expectation(),
  360. $this->get_does_not_contain_penalty_info_expectation(),
  361. $this->get_does_not_contain_total_penalty_expectation(),
  362. $this->get_does_not_contain_validation_error_expectation());
  363. // Submit an empty answer.
  364. $this->process_submission(array('-submit' => 1, 'answer' => ''));
  365. // Verify.
  366. $this->check_current_state(question_state::$invalid);
  367. $this->check_current_mark(0.66666667);
  368. $this->check_current_output(
  369. $this->get_contains_mark_summary(0.67),
  370. $this->get_contains_submit_button_expectation(true),
  371. $this->get_does_not_contain_penalty_info_expectation(),
  372. $this->get_does_not_contain_total_penalty_expectation(),
  373. $this->get_contains_validation_error_expectation());
  374. // Submit another wrong answer.
  375. $this->process_submission(array('-submit' => 1, 'answer' => 'bumblebee'));
  376. // Verify.
  377. $this->check_current_state(question_state::$complete);
  378. $this->check_current_mark(0.66666667);
  379. $this->check_current_output(
  380. $this->get_contains_mark_summary(0.67),
  381. $this->get_contains_submit_button_expectation(true),
  382. $this->get_contains_incorrect_expectation(),
  383. $this->get_does_not_contain_penalty_info_expectation(),
  384. $this->get_does_not_contain_total_penalty_expectation(),
  385. $this->get_does_not_contain_validation_error_expectation());
  386. // Finish the attempt.
  387. $this->quba->finish_all_questions();
  388. // Verify.
  389. $this->check_current_state(question_state::$gradedwrong);
  390. $this->check_current_mark(0.66666667);
  391. $this->check_current_output(
  392. $this->get_contains_mark_summary(0.67),
  393. $this->get_contains_submit_button_expectation(false),
  394. $this->get_contains_incorrect_expectation(),
  395. $this->get_does_not_contain_validation_error_expectation());
  396. }
  397. public function test_adaptive_shortanswer_zero_penalty() {
  398. // Create a short answer question
  399. $sa = test_question_maker::make_question('shortanswer');
  400. // Disable penalties for this question
  401. $sa->penalty = 0;
  402. $this->start_attempt_at_question($sa, 'adaptive');
  403. // Check the initial state.
  404. $this->check_current_state(question_state::$todo);
  405. $this->check_current_mark(null);
  406. $this->check_current_output(
  407. $this->get_contains_marked_out_of_summary(),
  408. $this->get_contains_submit_button_expectation(true),
  409. $this->get_does_not_contain_feedback_expectation());
  410. // Submit a wrong answer.
  411. $this->process_submission(array('-submit' => 1, 'answer' => 'hippopotamus'));
  412. // Verify.
  413. $this->check_current_state(question_state::$todo);
  414. $this->check_current_mark(0);
  415. $this->check_current_output(
  416. $this->get_contains_mark_summary(0),
  417. $this->get_contains_submit_button_expectation(true),
  418. $this->get_contains_incorrect_expectation(),
  419. $this->get_does_not_contain_penalty_info_expectation(),
  420. $this->get_does_not_contain_total_penalty_expectation(),
  421. $this->get_does_not_contain_validation_error_expectation());
  422. // Submit a correct answer.
  423. $this->process_submission(array('-submit' => 1, 'answer' => 'frog'));
  424. // Verify.
  425. $this->check_current_state(question_state::$complete);
  426. $this->check_current_mark(1.0);
  427. $this->check_current_output(
  428. $this->get_contains_mark_summary(1.0),
  429. $this->get_contains_submit_button_expectation(true),
  430. $this->get_contains_correct_expectation(),
  431. $this->get_does_not_contain_penalty_info_expectation(),
  432. $this->get_does_not_contain_total_penalty_expectation(),
  433. $this->get_does_not_contain_validation_error_expectation());
  434. // Finish the attempt.
  435. $this->quba->finish_all_questions();
  436. // Verify.
  437. $this->check_current_state(question_state::$gradedright);
  438. $this->check_current_mark(1.0);
  439. $this->check_current_output(
  440. $this->get_contains_mark_summary(1.0),
  441. $this->get_contains_submit_button_expectation(false),
  442. $this->get_contains_correct_expectation(),
  443. $this->get_does_not_contain_validation_error_expectation());
  444. }
  445. public function test_adaptive_shortanswer_try_to_submit_blank() {
  446. // Create a short answer question with correct answer true.
  447. $sa = test_question_maker::make_question('shortanswer');
  448. $this->start_attempt_at_question($sa, 'adaptive');
  449. // Check the initial state.
  450. $this->check_current_state(question_state::$todo);
  451. $this->check_current_mark(null);
  452. $this->check_current_output(
  453. $this->get_contains_marked_out_of_summary(),
  454. $this->get_contains_submit_button_expectation(true),
  455. $this->get_does_not_contain_feedback_expectation());
  456. // Submit with blank answer.
  457. $this->process_submission(array('-submit' => 1, 'answer' => ''));
  458. // Verify.
  459. $this->check_current_state(question_state::$invalid);
  460. $this->check_current_mark(null);
  461. $this->check_current_output(
  462. $this->get_contains_marked_out_of_summary(),
  463. $this->get_contains_submit_button_expectation(true),
  464. $this->get_does_not_contain_correctness_expectation(),
  465. $this->get_does_not_contain_penalty_info_expectation(),
  466. $this->get_does_not_contain_total_penalty_expectation(),
  467. $this->get_contains_validation_error_expectation(),
  468. $this->get_contains_disregarded_info_expectation());
  469. $this->assertNull($this->quba->get_response_summary($this->slot));
  470. // Now get it wrong.
  471. $this->process_submission(array('-submit' => 1, 'answer' => 'toad'));
  472. // Verify.
  473. $this->check_current_state(question_state::$todo);
  474. $this->check_current_mark(0.8);
  475. $this->check_current_output(
  476. $this->get_contains_mark_summary(0.8),
  477. $this->get_contains_submit_button_expectation(true),
  478. $this->get_contains_partcorrect_expectation(),
  479. $this->get_contains_penalty_info_expectation(0.33),
  480. $this->get_does_not_contain_total_penalty_expectation(),
  481. $this->get_does_not_contain_validation_error_expectation());
  482. // Now submit blank again.
  483. $this->process_submission(array('-submit' => 1, 'answer' => ''));
  484. // Verify.
  485. $this->check_current_state(question_state::$invalid);
  486. $this->check_current_mark(0.8);
  487. $this->check_current_output(
  488. $this->get_contains_mark_summary(0.8),
  489. $this->get_contains_submit_button_expectation(true),
  490. $this->get_does_not_contain_correctness_expectation(),
  491. $this->get_does_not_contain_penalty_info_expectation(),
  492. $this->get_does_not_contain_total_penalty_expectation(),
  493. $this->get_contains_validation_error_expectation());
  494. }
  495. public function test_adaptive_numerical() {
  496. // Create a numerical question
  497. $sa = test_question_maker::make_question('numerical', 'pi');
  498. $this->start_attempt_at_question($sa, 'adaptive');
  499. // Check the initial state.
  500. $this->check_current_state(question_state::$todo);
  501. $this->check_current_mark(null);
  502. $this->check_current_output(
  503. $this->get_contains_marked_out_of_summary(),
  504. $this->get_contains_submit_button_expectation(true),
  505. $this->get_does_not_contain_feedback_expectation());
  506. // Submit the correct answer.
  507. $this->process_submission(array('-submit' => 1, 'answer' => '3.14'));
  508. // Verify.
  509. $this->check_current_state(question_state::$complete);
  510. $this->check_current_mark(1);
  511. $this->check_current_output(
  512. $this->get_contains_mark_summary(1),
  513. $this->get_contains_submit_button_expectation(true),
  514. $this->get_contains_correct_expectation(),
  515. $this->get_does_not_contain_penalty_info_expectation(),
  516. $this->get_does_not_contain_total_penalty_expectation(),
  517. $this->get_does_not_contain_validation_error_expectation());
  518. // Submit an incorrect answer.
  519. $this->process_submission(array('-submit' => 1, 'answer' => '-5'));
  520. // Verify.
  521. $this->check_current_state(question_state::$complete);
  522. $this->check_current_mark(1);
  523. $this->check_current_output(
  524. $this->get_contains_mark_summary(1),
  525. $this->get_contains_submit_button_expectation(true),
  526. $this->get_contains_incorrect_expectation(),
  527. $this->get_does_not_contain_penalty_info_expectation(),
  528. $this->get_does_not_contain_total_penalty_expectation(),
  529. $this->get_does_not_contain_validation_error_expectation());
  530. // Finish the attempt.
  531. $this->quba->finish_all_questions();
  532. // Verify.
  533. $this->check_current_state(question_state::$gradedwrong);
  534. $this->check_current_mark(1);
  535. $this->check_current_output(
  536. $this->get_contains_mark_summary(1),
  537. $this->get_contains_submit_button_expectation(false),
  538. $this->get_contains_incorrect_expectation(),
  539. $this->get_does_not_contain_validation_error_expectation());
  540. }
  541. public function test_adaptive_numerical_invalid() {
  542. // Create a numerical question
  543. $numq = test_question_maker::make_question('numerical', 'pi');
  544. $numq->penalty = 0.1;
  545. $this->start_attempt_at_question($numq, 'adaptive');
  546. // Check the initial state.
  547. $this->check_current_state(question_state::$todo);
  548. $this->check_current_mark(null);
  549. $this->check_current_output(
  550. $this->get_contains_marked_out_of_summary(),
  551. $this->get_contains_submit_button_expectation(true),
  552. $this->get_does_not_contain_feedback_expectation());
  553. // Submit a non-numerical answer.
  554. $this->process_submission(array('-submit' => 1, 'answer' => 'Pi'));
  555. // Verify.
  556. $this->check_current_state(question_state::$invalid);
  557. $this->check_current_mark(null);
  558. $this->check_current_output(
  559. $this->get_contains_marked_out_of_summary(1),
  560. $this->get_contains_submit_button_expectation(true),
  561. $this->get_does_not_contain_correctness_expectation(),
  562. $this->get_does_not_contain_penalty_info_expectation(),
  563. $this->get_does_not_contain_total_penalty_expectation(),
  564. $this->get_contains_validation_error_expectation(),
  565. $this->get_contains_disregarded_info_expectation());
  566. // Submit an incorrect answer.
  567. $this->process_submission(array('-submit' => 1, 'answer' => '-5'));
  568. // Verify.
  569. $this->check_current_state(question_state::$todo);
  570. $this->check_current_mark(0);
  571. $this->check_current_output(
  572. $this->get_contains_mark_summary(0),
  573. $this->get_contains_submit_button_expectation(true),
  574. $this->get_contains_incorrect_expectation(),
  575. $this->get_contains_penalty_info_expectation(0.1),
  576. $this->get_does_not_contain_total_penalty_expectation(),
  577. $this->get_does_not_contain_validation_error_expectation(),
  578. $this->get_does_not_contain_disregarded_info_expectation());
  579. // Submit another non-numerical answer.
  580. $this->process_submission(array('-submit' => 1, 'answer' => 'Pi*2'));
  581. // Verify.
  582. $this->check_current_state(question_state::$invalid);
  583. $this->check_current_mark(0);
  584. $this->check_current_output(
  585. $this->get_contains_mark_summary(0),
  586. $this->get_contains_submit_button_expectation(true),
  587. $this->get_does_not_contain_correctness_expectation(),
  588. $this->get_does_not_contain_penalty_info_expectation(),
  589. $this->get_does_not_contain_total_penalty_expectation(),
  590. $this->get_contains_validation_error_expectation(),
  591. $this->get_contains_disregarded_info_expectation());
  592. // Submit the correct answer.
  593. $this->process_submission(array('-submit' => 1, 'answer' => '3.14'));
  594. // Verify.
  595. $this->check_current_state(question_state::$complete);
  596. $this->check_current_mark(0.9);
  597. $this->check_current_output(
  598. $this->get_contains_mark_summary(0.9),
  599. $this->get_contains_submit_button_expectation(true),
  600. $this->get_contains_correct_expectation(),
  601. $this->get_does_not_contain_penalty_info_expectation(),
  602. $this->get_does_not_contain_total_penalty_expectation(),
  603. $this->get_does_not_contain_validation_error_expectation(),
  604. $this->get_does_not_contain_disregarded_info_expectation());
  605. // Submit another non-numerical answer.
  606. $this->process_submission(array('-submit' => 1, 'answer' => 'Pi/3'));
  607. // Verify.
  608. $this->check_current_state(question_state::$invalid);
  609. $this->check_current_mark(0.9);
  610. $this->check_current_output(
  611. $this->get_contains_mark_summary(0.9),
  612. $this->get_contains_submit_button_expectation(true),
  613. $this->get_does_not_contain_correctness_expectation(),
  614. $this->get_does_not_contain_penalty_info_expectation(),
  615. $this->get_does_not_contain_total_penalty_expectation(),
  616. $this->get_contains_validation_error_expectation(),
  617. $this->get_contains_disregarded_info_expectation());
  618. // Finish the attempt.
  619. $this->quba->finish_all_questions();
  620. // Verify.
  621. $this->check_current_state(question_state::$gradedwrong);
  622. $this->check_current_mark(0.9);
  623. $this->check_current_output(
  624. $this->get_contains_mark_summary(0.9),
  625. $this->get_contains_submit_button_expectation(false),
  626. $this->get_contains_incorrect_expectation(),
  627. $this->get_does_not_contain_validation_error_expectation(),
  628. $this->get_does_not_contain_disregarded_info_expectation());
  629. }
  630. }