aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--question.php2
-rw-r--r--questiontype.php2
-rw-r--r--tests/helper.php74
-rw-r--r--tests/question_test.php35
4 files changed, 74 insertions, 39 deletions
diff --git a/question.php b/question.php
index 52eea54..bfff2fa 100644
--- a/question.php
+++ b/question.php
@@ -331,7 +331,7 @@ class qtype_algebra_question extends question_graded_by_strategy
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class question_variable {
+class qtype_algebra_variable {
/** @var integer the answer id. */
public $id;
diff --git a/questiontype.php b/questiontype.php
index f49bd55..347b427 100644
--- a/questiontype.php
+++ b/questiontype.php
@@ -501,7 +501,7 @@ class qtype_algebra extends question_type {
$question->variables = array();
if (!empty($questiondata->options->variables)) {
foreach ($questiondata->options->variables as $v) {
- $question->variables[$v->id] = new question_variable($v->id, $v->name, $v->min, $v->max);
+ $question->variables[$v->id] = new qtype_algebra_variable($v->id, $v->name, $v->min, $v->max);
}
}
$question->compareby = $questiondata->options->compareby;
diff --git a/tests/helper.php b/tests/helper.php
index 98f5dd6..8bab2e5 100644
--- a/tests/helper.php
+++ b/tests/helper.php
@@ -37,7 +37,7 @@ class qtype_algebra_test_helper extends question_test_helper {
/**
* Makes a algebra question with correct ansewer 7 and defaultmark 1.
- * This question also has no variables.
+ * This question also has one variable.
* @return qtype_algebra_question
*/
public function make_algebra_question_simplemath() {
@@ -45,16 +45,20 @@ class qtype_algebra_test_helper extends question_test_helper {
$q = new qtype_algebra_question();
test_question_maker::initialise_a_question($q);
$q->name = 'Algebra question';
- $q->questiontext = 'Calculate 4 + 3';
- $q->generalfeedback = 'Generalfeedback: 4 + 3 = 7.';
+ $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->usecase = false;
+ $q->disallow = '';
+ $q->allowedfuncs = '';
+ $q->answerprefix = '';
$q->answers = array(
- 13 => new question_answer(13, '7', 1.0, '7 is a very good answer.', FORMAT_HTML),
+ 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->variables = array();
$q->qtype = question_bank::get_qtype('algebra');
return $q;
}
@@ -62,7 +66,7 @@ class qtype_algebra_test_helper extends question_test_helper {
/**
* Gets the question data for a algebra question with with correct
* ansewer 7 and defaultmark 1.
- * This question also has no variables.
+ * This question also has one variable.
* @return stdClass
*/
public function get_algebra_question_data_simplemath() {
@@ -71,17 +75,22 @@ class qtype_algebra_test_helper extends question_test_helper {
$qdata->qtype = 'algebra';
$qdata->name = 'Algebra question';
- $qdata->questiontext = 'Calculate 4 + 3';
- $qdata->generalfeedback = 'Generalfeedback: 4 + 3 = 7.';
+ $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;
+ $q->options->disallow = '';
+ $q->options->allowedfuncs = '';
+ $q->options->answerprefix = '';
$qdata->options->answers = array(
- 13 => new question_answer(13, '7', 1.0, '7 is a very good answer.', FORMAT_HTML),
+ 13 => new question_answer(13, '7', 1.0, 'This is a very good answer.', FORMAT_HTML),
+ );
+ $qdata->options->variables = array(
+ 7 => new qtype_algebra_variable(7, 'x', -5, 5)
);
- $qdata->options->variables = array();
return $qdata;
}
@@ -96,21 +105,21 @@ class qtype_algebra_test_helper extends question_test_helper {
$form = new stdClass();
$form->name = 'Algebra question';
- $form->questiontext = array('text' => 'Calculate 4 + 3', 'format' => FORMAT_HTML);
+ $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: 4 + 3 = 7.', 'format' => FORMAT_HTML);
- $form->answer = array('7');
+ $form->generalfeedback = array('text' => 'Generalfeedback: (P + Q)(x) = 7x.', 'format' => FORMAT_HTML);
+ $form->answer = array('7*x');
$form->fraction = array('1.0');
$form->feedback = array(
- array('text' => '7 is a very good answer.', 'format' => FORMAT_HTML),
+ array('text' => 'This is a very good answer.', 'format' => FORMAT_HTML),
);
return $form;
}
/**
- * Makes a algebra question with just the correct ansewer 'frog', and
- * no other answer matching.
+ * Makes a algebra question with one correct and one partially correct answer.
* @return qtype_algebra_question
*/
public function make_algebra_question_derive() {
@@ -120,8 +129,18 @@ class qtype_algebra_test_helper extends question_test_helper {
$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');
@@ -129,8 +148,8 @@ class qtype_algebra_test_helper extends question_test_helper {
}
/**
- * Gets the question data for a algebra questionwith just the correct
- * ansewer 'frog', and no other answer matching.
+ * 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() {
@@ -139,13 +158,22 @@ class qtype_algebra_test_helper extends question_test_helper {
$qdata->qtype = 'algebra';
$qdata->name = 'Algebra question';
- $qdata->questiontext = 'Name the best amphibian: __________';
- $qdata->generalfeedback = 'Generalfeedback: you should have said frog.';
+ $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->usecase = false;
+ $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, 'frog', 1.0, 'Frog is right.', FORMAT_HTML),
+ 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;
diff --git a/tests/question_test.php b/tests/question_test.php
index 264b24a..051044b 100644
--- a/tests/question_test.php
+++ b/tests/question_test.php
@@ -38,8 +38,15 @@ require_once($CFG->dirroot . '/question/type/algebra/tests/helper.php');
*/
class qtype_algebra_question_test extends advanced_testcase {
+ /**
+ * @return qtype_formulas_question the requested question object.
+ */
+ protected function get_test_algebra_question($which = null) {
+ return test_question_maker::make_question('algebra', $which);
+ }
+
public function test_is_gradable_response() {
- $question = test_question_maker::make_question('simplemath');
+ $question = $this->get_test_algebra_question('simplemath');
$this->assertFalse($question->is_gradable_response(array()));
$this->assertFalse($question->is_gradable_response(array('answer' => '')));
@@ -49,7 +56,7 @@ class qtype_algebra_question_test extends advanced_testcase {
}
public function test_grading_test0() {
- $question = test_question_maker::make_question('simplemath');
+ $question = $this->get_test_algebra_question('simplemath');
$this->assertEquals(array(0, question_state::$gradedwrong),
$question->grade_response(array('answer' => 'x')));
@@ -62,7 +69,7 @@ class qtype_algebra_question_test extends advanced_testcase {
}
public function test_grading_test1() {
- $question = test_question_maker::make_question('derive');
+ $question = $this->get_test_algebra_question('derive');
$this->assertEquals(array(0, question_state::$gradedwrong),
$question->grade_response(array('answer' => 'x')));
@@ -74,37 +81,37 @@ class qtype_algebra_question_test extends advanced_testcase {
$question->grade_response(array('answer' => 'x+x')));
}
public function test_get_correct_response() {
- $question = test_question_maker::make_question('simplemath');
+ $question = $this->get_test_algebra_question('simplemath');
- $this->assertEquals(array('answer' => '2*x'),
+ $this->assertEquals(array('answer' => '7*x'),
$question->get_correct_response());
}
public function test_get_question_summary() {
- $sa = test_question_maker::make_question('algebra');
- $qsummary = $sa->get_question_summary();
+ $question = $this->get_test_algebra_question('derive');
+ $qsummary = $question->get_question_summary();
$this->assertEquals('What is the derivative of the function \(f(x) = x^2\) ?', $qsummary);
}
public function test_summarise_response() {
- $sa = test_question_maker::make_question('derive');
- $summary = $sa->summarise_response(array('answer' => '2*x'));
+ $question = $this->get_test_algebra_question('derive');
+ $summary = $question->summarise_response(array('answer' => '2*x'));
$this->assertEquals('2*x', $summary);
}
public function test_classify_response() {
- $sa = test_question_maker::make_question('derive');
- $sa->start_attempt(new question_attempt_step(), 1);
+ $question = test_question_maker::make_question('derive');
+ $question->start_attempt(new question_attempt_step(), 1);
$this->assertEquals(array(
new question_classified_response(13, '2*x', 1.0)),
- $sa->classify_response(array('answer' => '2*x')));
+ $question->classify_response(array('answer' => '2*x')));
$this->assertEquals(array(
new question_classified_response(15, '5*x', 0.0)),
- $sa->classify_response(array('answer' => '5*x')));
+ $question->classify_response(array('answer' => '5*x')));
$this->assertEquals(array(
question_classified_response::no_response()),
- $sa->classify_response(array('answer' => '')));
+ $question->classify_response(array('answer' => '')));
}
}