aboutsummaryrefslogtreecommitdiff
path: root/tests/helper.php
blob: 680b359fc4a96f138be54b4c5ca913c91f5b6d02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Test helpers for the algebra question type.
 *
 * @package    qtype_algebra
 * @copyright  2017 Jean-Michel Vedrine
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

defined('MOODLE_INTERNAL') || die();

/**
 * Test helper class for the algebra question type.
 *
 * @copyright  2017 Jean-Michel Vedrine
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class qtype_algebra_test_helper extends question_test_helper {
    public function get_test_questions() {
        return array('simplemath', 'derive');
    }

    /**
     * Makes a algebra question with correct ansewer 7 and defaultmark 1.
     * This question also has one variable.
     * @return qtype_algebra_question
     */
    public function make_algebra_question_simplemath() {
        question_bank::load_question_definition_classes('algebra');
        $q = new qtype_algebra_question();
        test_question_maker::initialise_a_question($q);
        $q->name = 'Algebra question';
        $q->questiontext = 'P(x) = 3x and Q(x) = 4x. Calculate (P + Q)(x)';
        $q->generalfeedback = 'Generalfeedback: (P + Q)(x) = 7x.';
        $q->compareby = 'eval';
        $q->nchecks = 10;
        $q->tolerance = 0.001;
        $q->disallow = '';
        $q->allowedfuncs = '';
        $q->answerprefix = '';
        $q->answers = array(
            13 => new question_answer(13, '7*x', 1.0, 'This is a very good answer.', FORMAT_HTML),
        );
        $q->variables = array(
            7 => new qtype_algebra_variable(7, 'x', -5, 5)
        );
        $q->qtype = question_bank::get_qtype('algebra');
        return $q;
    }

    /**
     * Gets the question data for a algebra question with with correct
     * ansewer 7 and defaultmark 1.
     * This question also has one variable.
     * @return stdClass
     */
    public function get_algebra_question_data_simplemath() {
        $qdata = new stdClass();
        test_question_maker::initialise_question_data($qdata);

        $qdata->qtype = 'algebra';
        $qdata->name = 'Algebra question';
        $qdata->questiontext = 'P(x) = 3x and Q(x) = 4x. Calculate (P + Q)(x)';
        $qdata->generalfeedback = 'Generalfeedback: (P + Q)(x) = 7x.';

        $qdata->options = new stdClass();
        $qdata->options->compareby = 'eval';
        $qdata->options->nchecks = '10';
        $qdata->options->tolerance = 0.001;
        $qdata->options->disallow = '';
        $qdata->options->allowedfuncs = array();
        $qdata->options->answerprefix = '';
        $qdata->options->answers = array(
            13 => new question_answer(13, '7*x', 1.0, 'This is a very good answer.', FORMAT_HTML),
        );
        $qdata->options->variables = array(
            7 => new qtype_algebra_variable(7, 'x', -5, 5)
        );

        return $qdata;
    }

    /**
     * Gets the question form data for a algebra question with with correct
     * answer '7*x' and defaultmark 1.
     * @return stdClass
     */
    public function get_algebra_question_form_data_simplemath() {
        $form = new stdClass();

        $form->name = 'Algebra question';
        $form->questiontext = array('text' => 'P(x) = 3x and Q(x) = 4x. Calculate (P + Q)(x)',
                'format' => FORMAT_HTML);
        $form->defaultmark = 1.0;
        $form->generalfeedback = array('text' => 'Generalfeedback: (P + Q)(x) = 7x.', 'format' => FORMAT_HTML);
        $form->compareby = 'eval';
        $form->nchecks = '10';
        $form->tolerance = 0.001;
        $form->allowedfuncs = array('all' => 1);
        $form->disallow = '';
        $form->answerprefix = '';
        $form->answer = array('7*x');
        $form->fraction = array('1.0');
        $form->variable = array('x');
        $form->varmin = array('-5');
        $form->varmax = array('5');
        $form->feedback = array(
            array('text' => 'This is a very good answer.', 'format' => FORMAT_HTML),
        );
        $form->penalty = 0.3333333;

        return $form;
    }

    /**
     * Makes a algebra question with one correct and one partially correct answer.
     * @return qtype_algebra_question
     */
    public function make_algebra_question_derive() {
        question_bank::load_question_definition_classes('algebra');
        $q = new qtype_algebra_question();
        test_question_maker::initialise_a_question($q);
        $q->name = 'Algebra question';
        $q->questiontext = 'What is the derivative of the function \(f(x) = x^2\) ?';
        $q->generalfeedback = 'Generalfeedback: 2*x is the correct answer.';
        $q->compareby = 'eval';
        $q->nchecks = 10;
        $q->tolerance = 0.001;
        $q->disallow = '';
        $q->allowedfuncs = '';
        $q->answerprefix = 'f(x) =';
        $q->answers = array(
            13 => new question_answer(13, '2*x', 1.0, 'Correct.', FORMAT_HTML),
            14 => new question_answer(14, 'x', 0.2, 'It seems that you forgot something.', FORMAT_HTML),
        );
        $q->variables = array(
            7 => new qtype_algebra_variable(7, 'x', -5, 5)
        );
        $q->qtype = question_bank::get_qtype('algebra');

        return $q;
    }

    /**
     * Gets the question data for a algebra question with one correct and
     * one partially correct answer.
     * @return stdClass
     */
    public function get_algebra_question_data_derive() {
        $qdata = new stdClass();
        test_question_maker::initialise_question_data($qdata);

        $qdata->qtype = 'algebra';
        $qdata->name = 'Algebra question';
        $qdata->questiontext = 'What is the derivative of the function \(f(x) = x^2\) ?';
        $qdata->generalfeedback = 'Generalfeedback: 2*x is the correct answer.';

        $qdata->options = new stdClass();
        $qdata->options->compareby = 'eval';
        $qdata->options->nchecks = 10;
        $qdata->options->tolerance = 0.001;
        $qdata->options->disallow = '';
        $qdata->options->allowedfuncs = '';
        $qdata->options->answerprefix = 'f(x) =';
        $qdata->options->answers = array(
            13 => new question_answer(13, '2*x', 1.0, 'Correct.', FORMAT_HTML),
            14 => new question_answer(14, 'x', 0.2, 'It seems that you forgot something.', FORMAT_HTML),
        );
        $qdata->options->variables = array(
            7 => new qtype_algebra_variable(7, 'x', -5, 5)
        );

        return $qdata;
    }
}