See Release Notes
Long Term Support Release
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 namespace qbehaviour_deferredcbm; 18 19 use question_display_options; 20 use question_engine; 21 use question_testcase; 22 23 defined('MOODLE_INTERNAL') || die(); 24 25 global $CFG; 26 require_once (__DIR__ . '/../../../engine/lib.php'); 27 require_once (__DIR__ . '/../../../engine/tests/helpers.php'); 28 29 30 /** 31 * Unit tests for the deferred feedback with certainty base marking behaviour. 32 * 33 * @package qbehaviour_deferredcbm 34 * @copyright 2009 The Open University 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class behaviour_type_test extends \qbehaviour_walkthrough_test_base { 38 39 /** @var qbehaviour_deferredcbm_type */ 40 protected $behaviourtype; 41 42 public function setUp(): void { 43 parent::setUp(); 44 $this->behaviourtype = question_engine::get_behaviour_type('deferredcbm'); 45 } 46 47 public function test_is_archetypal() { 48 $this->assertTrue($this->behaviourtype->is_archetypal()); 49 } 50 51 public function test_get_unused_display_options() { 52 $this->assertEquals(array('correctness', 'marks', 'specificfeedback', 'generalfeedback', 'rightanswer'), 53 $this->behaviourtype->get_unused_display_options()); 54 } 55 56 public function test_can_questions_finish_during_the_attempt() { 57 $this->assertFalse($this->behaviourtype->can_questions_finish_during_the_attempt()); 58 } 59 60 public function test_adjust_random_guess_score() { 61 $this->assertEquals(0, $this->behaviourtype->adjust_random_guess_score(0)); 62 $this->assertEquals(1, $this->behaviourtype->adjust_random_guess_score(1)); 63 } 64 65 public function test_summarise_usage_max_mark_1() { 66 67 // Create a usage comprising 3 true-false questions. 68 $this->quba->set_preferred_behaviour('deferredcbm'); 69 $this->quba->add_question(\test_question_maker::make_question('truefalse', 'true'), 3); 70 $this->quba->add_question(\test_question_maker::make_question('truefalse', 'true'), 3); 71 $this->quba->add_question(\test_question_maker::make_question('truefalse', 'true'), 3); 72 $this->quba->start_all_questions(); 73 74 // Process responses right, high certainty; right, med certainty; wrong, med certainty. 75 $this->quba->process_action(1, array('answer' => 1, '-certainty' => 3)); 76 $this->quba->process_action(2, array('answer' => 1, '-certainty' => 2)); 77 $this->quba->process_action(3, array('answer' => 0, '-certainty' => 2)); 78 $this->quba->finish_all_questions(); 79 80 // Get the summary. 81 $summarydata = $this->quba->get_summary_information(new question_display_options()); 82 83 // Verify. 84 $this->assertStringContainsString(get_string('breakdownbycertainty', 'qbehaviour_deferredcbm'), 85 $summarydata['qbehaviour_cbm_judgement_heading']['content']); 86 87 $this->assertStringContainsString('100%', 88 $summarydata['qbehaviour_cbm_judgement3']['content']); 89 $this->assertStringContainsString(get_string('judgementok', 'qbehaviour_deferredcbm'), 90 $summarydata['qbehaviour_cbm_judgement3']['content']); 91 92 $this->assertStringContainsString('50%', 93 $summarydata['qbehaviour_cbm_judgement2']['content']); 94 $this->assertStringContainsString(get_string('slightlyoverconfident', 'qbehaviour_deferredcbm'), 95 $summarydata['qbehaviour_cbm_judgement2']['content']); 96 97 $this->assertStringContainsString(get_string('noquestions', 'qbehaviour_deferredcbm'), 98 $summarydata['qbehaviour_cbm_judgement1']['content']); 99 } 100 101 public function test_summarise_usage_max_mark_3() { 102 103 // Create a usage comprising 3 true-false questions. 104 $this->quba->set_preferred_behaviour('deferredcbm'); 105 $this->quba->add_question(\test_question_maker::make_question('truefalse', 'true'), 1); 106 $this->quba->add_question(\test_question_maker::make_question('truefalse', 'true'), 1); 107 $this->quba->add_question(\test_question_maker::make_question('truefalse', 'true'), 1); 108 $this->quba->start_all_questions(); 109 110 // Process responses right, high certainty; right, med certainty; wrong, med certainty. 111 $this->quba->process_action(1, array('answer' => 1, '-certainty' => 3)); 112 $this->quba->process_action(2, array('answer' => 1, '-certainty' => 2)); 113 $this->quba->process_action(3, array('answer' => 0, '-certainty' => 2)); 114 $this->quba->finish_all_questions(); 115 116 // Get the summary. 117 $summarydata = $this->quba->get_summary_information(new question_display_options()); 118 119 // Verify. 120 $this->assertStringContainsString(get_string('breakdownbycertainty', 'qbehaviour_deferredcbm'), 121 $summarydata['qbehaviour_cbm_judgement_heading']['content']); 122 123 $this->assertStringContainsString('100%', 124 $summarydata['qbehaviour_cbm_judgement3']['content']); 125 $this->assertStringContainsString(get_string('judgementok', 'qbehaviour_deferredcbm'), 126 $summarydata['qbehaviour_cbm_judgement3']['content']); 127 128 $this->assertStringContainsString('50%', 129 $summarydata['qbehaviour_cbm_judgement2']['content']); 130 $this->assertStringContainsString(get_string('slightlyoverconfident', 'qbehaviour_deferredcbm'), 131 $summarydata['qbehaviour_cbm_judgement2']['content']); 132 133 $this->assertStringContainsString(get_string('noquestions', 'qbehaviour_deferredcbm'), 134 $summarydata['qbehaviour_cbm_judgement1']['content']); 135 } 136 137 public function test_calculate_bonus() { 138 $this->assertEqualsWithDelta(0.05, $this->behaviourtype->calculate_bonus(1, 1 / 2), question_testcase::GRADE_DELTA); 139 $this->assertEqualsWithDelta(-0.01, $this->behaviourtype->calculate_bonus(2, 9 / 10), question_testcase::GRADE_DELTA); 140 $this->assertEqualsWithDelta(0, $this->behaviourtype->calculate_bonus(3, 1), question_testcase::GRADE_DELTA); 141 } 142 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body