1 |
efrain |
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_adaptive;
|
|
|
18 |
|
|
|
19 |
use qbehaviour_adaptive_mark_details;
|
|
|
20 |
use question_display_options;
|
|
|
21 |
use question_state;
|
|
|
22 |
|
|
|
23 |
defined('MOODLE_INTERNAL') || die();
|
|
|
24 |
|
|
|
25 |
global $CFG;
|
|
|
26 |
require_once(__DIR__ . '/../../../engine/lib.php');
|
|
|
27 |
require_once(__DIR__ . '/../behaviour.php');
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Unit tests for the adaptive behaviour the display of mark/penalty information.
|
|
|
31 |
*
|
|
|
32 |
* @package qbehaviour_adaptive
|
|
|
33 |
* @copyright 2012 The Open University
|
|
|
34 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
35 |
*/
|
|
|
36 |
class mark_display_test extends \basic_testcase {
|
|
|
37 |
/** @var qbehaviour_adaptive_renderer the renderer to test. */
|
|
|
38 |
protected $renderer;
|
|
|
39 |
|
|
|
40 |
/** @var question_display_options display options to use when rendering. */
|
|
|
41 |
protected $options;
|
|
|
42 |
|
|
|
43 |
protected function setUp(): void {
|
|
|
44 |
global $PAGE;
|
|
|
45 |
parent::setUp();
|
|
|
46 |
$this->renderer = $PAGE->get_renderer('qbehaviour_adaptive');
|
|
|
47 |
$this->options = new question_display_options();
|
|
|
48 |
}
|
|
|
49 |
|
11 |
efrain |
50 |
public function test_blank_before_graded(): void {
|
1 |
efrain |
51 |
$this->assertEquals('',
|
|
|
52 |
$this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
|
|
|
53 |
question_state::$todo), $this->options));
|
|
|
54 |
}
|
|
|
55 |
|
11 |
efrain |
56 |
public function test_correct_no_penalty(): void {
|
1 |
efrain |
57 |
$this->assertEquals('<div class="correctness badge correct">' . get_string('correct', 'question') . '</div>' .
|
|
|
58 |
'<div class="gradingdetails">' .
|
|
|
59 |
get_string('gradingdetails', 'qbehaviour_adaptive',
|
|
|
60 |
array('cur' => '1.00', 'raw' => '1.00', 'max' => '1.00')) . '</div>',
|
|
|
61 |
$this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
|
|
|
62 |
question_state::$gradedright, 1, 1, 1, 0, 0, false), $this->options));
|
|
|
63 |
}
|
|
|
64 |
|
11 |
efrain |
65 |
public function test_partial_first_try(): void {
|
1 |
efrain |
66 |
$this->assertEquals('<div class="correctness badge partiallycorrect">' . get_string('partiallycorrect', 'question') .
|
|
|
67 |
'</div><div class="gradingdetails">' .
|
|
|
68 |
get_string('gradingdetails', 'qbehaviour_adaptive',
|
|
|
69 |
array('cur' => '0.50', 'raw' => '0.50', 'max' => '1.00')) . ' ' .
|
|
|
70 |
get_string('gradingdetailspenalty', 'qbehaviour_adaptive', '0.10') . '</div>',
|
|
|
71 |
$this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
|
|
|
72 |
question_state::$gradedpartial, 1, 0.5, 0.5, 0.1, 0.1, true), $this->options));
|
|
|
73 |
}
|
|
|
74 |
|
11 |
efrain |
75 |
public function test_partial_second_try(): void {
|
1 |
efrain |
76 |
$mark = array('cur' => '0.80', 'raw' => '0.90', 'max' => '1.00');
|
|
|
77 |
$this->assertEquals('<div class="correctness badge partiallycorrect">' . get_string('partiallycorrect', 'question') .
|
|
|
78 |
'</div><div class="gradingdetails">' .
|
|
|
79 |
get_string('gradingdetails', 'qbehaviour_adaptive', $mark) . ' ' .
|
|
|
80 |
get_string('gradingdetailsadjustment', 'qbehaviour_adaptive', $mark) . ' ' .
|
|
|
81 |
get_string('gradingdetailspenalty', 'qbehaviour_adaptive', '0.10') . ' ' .
|
|
|
82 |
get_string('gradingdetailspenaltytotal', 'qbehaviour_adaptive', '0.20') . '</div>',
|
|
|
83 |
$this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
|
|
|
84 |
question_state::$gradedpartial, 1, 0.8, 0.9, 0.1, 0.2, true), $this->options));
|
|
|
85 |
}
|
|
|
86 |
|
11 |
efrain |
87 |
public function test_correct_third_try(): void {
|
1 |
efrain |
88 |
$mark = array('cur' => '0.80', 'raw' => '1.00', 'max' => '1.00');
|
|
|
89 |
$this->assertEquals('<div class="correctness badge partiallycorrect">' . get_string('partiallycorrect', 'question') .
|
|
|
90 |
'</div><div class="gradingdetails">' .
|
|
|
91 |
get_string('gradingdetails', 'qbehaviour_adaptive', $mark) . ' ' .
|
|
|
92 |
get_string('gradingdetailsadjustment', 'qbehaviour_adaptive', $mark) . '</div>',
|
|
|
93 |
$this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
|
|
|
94 |
question_state::$gradedpartial, 1, 0.8, 1.0, 0.1, 0.3, false), $this->options));
|
|
|
95 |
}
|
|
|
96 |
|
11 |
efrain |
97 |
public function test_correct_third_try_if_we_dont_increase_penalties_for_wrong(): void {
|
1 |
efrain |
98 |
$mark = array('cur' => '0.80', 'raw' => '1.00', 'max' => '1.00');
|
|
|
99 |
$this->assertEquals('<div class="correctness badge partiallycorrect">' . get_string('partiallycorrect', 'question') .
|
|
|
100 |
'</div><div class="gradingdetails">' .
|
|
|
101 |
get_string('gradingdetails', 'qbehaviour_adaptive', $mark) . ' ' .
|
|
|
102 |
get_string('gradingdetailsadjustment', 'qbehaviour_adaptive', $mark) . '</div>',
|
|
|
103 |
$this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
|
|
|
104 |
question_state::$gradedpartial, 1, 0.8, 1.0, 0, 0.2, false), $this->options));
|
|
|
105 |
}
|
|
|
106 |
}
|