diff options
author | Jean-Michel Vedrine <vedrine@vedrine.org> | 2018-01-01 19:10:49 +0100 |
---|---|---|
committer | Jean-Michel Vedrine <vedrine@vedrine.org> | 2018-01-01 19:10:49 +0100 |
commit | 294edec77a967e743631bfe2cde6b8ecc47b980c (patch) | |
tree | 992d1425dc9ccaaea338b8a43196a28e6f16b673 | |
parent | 256a9808276e420bc7ee6168f04ab31b6cfe4d44 (diff) |
Test multiplication display
-rw-r--r-- | tests/helper.php | 12 | ||||
-rw-r--r-- | tests/parser_test.php | 18 | ||||
-rw-r--r-- | tests/questiontype_test.php | 2 |
3 files changed, 28 insertions, 4 deletions
diff --git a/tests/helper.php b/tests/helper.php index 97639bc..e36ed9c 100644 --- a/tests/helper.php +++ b/tests/helper.php @@ -97,8 +97,7 @@ class qtype_algebra_test_helper extends question_test_helper { /** * Gets the question form data for a algebra question with with correct - * answer 'frog', partially correct answer 'toad' and defaultmark 1. - * This question also has a '*' match anything answer. + * answer '7*x' and defaultmark 1. * @return stdClass */ public function get_algebra_question_form_data_simplemath() { @@ -109,8 +108,17 @@ class qtype_algebra_test_helper extends question_test_helper { '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 = ''; + $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), ); diff --git a/tests/parser_test.php b/tests/parser_test.php index 71a9d77..13dbe23 100644 --- a/tests/parser_test.php +++ b/tests/parser_test.php @@ -37,13 +37,29 @@ require_once($CFG->dirroot . '/question/type/algebra/parser.php'); */ class qtype_algebra_parser_test extends advanced_testcase { - + /** + * Test base elements of the parser + */ public function test_parser_vars_functions() { $p = new qtype_algebra_parser; $expr = $p->parse('sin(2x) + cos(3y)'); $this->assertEquals(array('x', 'y'), $expr->get_variables()); $this->assertEquals(array('sin', 'cos'), $expr->get_functions()); + $this->assertEquals('\sin \left( 2 x_{} \right) + \cos \left( 3 y_{} \right)', $expr->tex()); + } + + /** + * Test how various multiplications are displayed using TeX + */ + public function test_parser_multiply_display() { + $p = new qtype_algebra_parser; + + $expr = $p->parse('sin(2x) + cos(3y)'); $this->assertEquals('\sin \left( 2 x_{} \right) + \cos \left( 3 y_{} \right)', $expr->tex()); + $expr = $p->parse('sin(4 x) + cos(5 y)'); + $this->assertEquals('\sin \left( 4 x_{} \right) + \cos \left( 5 y_{} \right)', $expr->tex()); + $expr = $p->parse('sin(6*x) + cos(7*y)'); + $this->assertEquals('\sin \left( 6 x_{} \right) + \cos \left( 7 y_{} \right)', $expr->tex()); } } diff --git a/tests/questiontype_test.php b/tests/questiontype_test.php index 7a4cf4b..929b074 100644 --- a/tests/questiontype_test.php +++ b/tests/questiontype_test.php @@ -83,7 +83,7 @@ class qtype_algebra_test extends advanced_testcase { ), $this->qtype->get_possible_responses($q)); } - public function test_question_saving_frogtoad() { + public function test_question_saving_simplemath() { $this->resetAfterTest(true); $this->setAdminUser(); |