From ea3c6edd4a19e7ae9a56cc7342dd0c5158818551 Mon Sep 17 00:00:00 2001 From: Chris Sangwin <C.J.Sangwin@ed.ac.uk> Date: Wed, 15 May 2024 15:07:49 +0100 Subject: [PATCH] Add test-case related to issue #1189. --- doc/en/Authoring/Multiple_choice_questions.md | 8 +++++- doc/en/Developer/Parser.md | 6 ++--- tests/input_checkbox_test.php | 26 +++++++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/doc/en/Authoring/Multiple_choice_questions.md b/doc/en/Authoring/Multiple_choice_questions.md index 48f230b15..99c29a7d1 100644 --- a/doc/en/Authoring/Multiple_choice_questions.md +++ b/doc/en/Authoring/Multiple_choice_questions.md @@ -56,7 +56,13 @@ When STACK displays the "teacher's answer", e.g. after a quiz is due, this will If you need "none of these" you must include this as an explicit option, and not rely on the student not checking any boxes in the checkbox type. Indeed, it would be impossible to distinguish the active selection of "none of these" from a passive failure to respond to the question. -If one of the responses is \(x=1 \text{ or } x=2\) then it is probably best to use `nounor` which is commutative and associative. Do not use `or` which always simplifies its arguments. In this example `x=1 or x=2` evaluates to `false`. +## Model answer: nouns ## + +If one of the responses is \(x=1 \text{ or } x=2\) then use `nounor` which is commutative and associative. Do not use `or` which always simplifies its arguments. In this example `x=1 or x=2` evaluates to `false`. + +Functions `diff` and `int` will evaluate, so you don't have displayed calculus operation. If one of the responses is a _displayed_ derivative or integral then construct your answer with Maxima's inert forms `'diff` and `'int`. + +## Model answer: LaTeX display in dropdowns ## HTML dropdowns cannot display LaTeX within the options. This is a restriction of HTML/MathJax (not of STACK). You can use HTML-entities within a string field. For example diff --git a/doc/en/Developer/Parser.md b/doc/en/Developer/Parser.md index 61b8bdb7b..a994ccac9 100644 --- a/doc/en/Developer/Parser.md +++ b/doc/en/Developer/Parser.md @@ -53,9 +53,7 @@ We give each parser rule a name, numbered in the approximate appropriate order i There are two separate classes of expressions which need to be protected as "nouns". 1. The Maxima Boolean functions do not respect `simp:false`. So, we have parallel operators such as `A nounand B`. These should always be used when connecting to Maxima. Evaluation/simplification of Boolean expressions such as `true and false` is done on the Maxima side. Teachers and students should use `and`, etc. and these are always translated into an evaluation form. -2. With `simp:false` we still have evaluation of expressions such as `diff(x^3,x)` to `3*x^2`. To protect student's answers ("Your last answer was..") we have parallel noun forms such as `noundiff` and `nounint`. Note, some of these also change the display of expressions. -3. Maxima uses the apostophie to create noun forms, e.g. `'diff(x^3,x)`. From STACK 4.3, teachers are able to use this. - - +2. Maxima uses the apostophie to create noun forms, e.g. `'diff(x^3,x)`. Teachers are able to use this, and it is the preferred route. +3. We retain parallel noun forms such as `noundiff` and `nounint` for back-compatibility. Note, some of these also change the display of expressions. diff --git a/tests/input_checkbox_test.php b/tests/input_checkbox_test.php index 704c5c259..fce294de0 100644 --- a/tests/input_checkbox_test.php +++ b/tests/input_checkbox_test.php @@ -490,4 +490,30 @@ class input_checkbox_test extends qtype_stack_testcase { '\left( 2,\, 3\right)\)</span></span></li></ul>'; $this->assertEquals($expected, $el->get_teacher_answer_display(false, false)); } + + public function test_noundiff() { + $options = new stack_options(); + $ta = '[[noundiff(f,x),true],[nounint(f,t),false]]'; + $el = stack_input_factory::make('checkbox', 'ans1', $ta, null, array('options' => '')); + + $expected = '<div class="answer"><div class="option"><input type="checkbox" name="stack1__ans1_1" ' . + 'value="1" id="stack1__ans1_1" checked="checked" /><label for="stack1__ans1_1"><span ' . + 'class="filter_mathjaxloader_equation"><span class="nolink">\(\frac{\mathrm{d} f}{\mathrm{d} x}\)' . + '</span></span></label></div><div class="option"><input type="checkbox" name="stack1__ans1_2" ' . + 'value="2" id="stack1__ans1_2" /><label for="stack1__ans1_2"><span class="filter_mathjaxloader_equation">' . + '<span class="nolink">\(\int {f}{\;\mathrm{d}t}\)</span></span></label></div></div>'; + $this->assertEquals($expected, $el->render(new stack_input_state( + stack_input::SCORE, array('1'), '', '', '', '', ''), 'stack1__ans1', false, array())); + $state = $el->validate_student_response(array('ans1_1' => '1'), + $options, $ta, new stack_cas_security()); + + $this->assertEquals(stack_input::SCORE, $state->status); + $this->assertEquals(array('1'), $state->contents); + $this->assertEquals('[noundiff(f,x)]', $state->contentsmodified); + $this->assertEquals($ta, $el->get_teacher_answer()); + $el->adapt_to_model_answer($ta); + $expected = 'A correct answer is: <ul><li><span class="filter_mathjaxloader_equation"><span class="nolink">' . + '\(\frac{\mathrm{d} f}{\mathrm{d} x}\)</span></span></li></ul>'; + $this->assertEquals($expected, $el->get_teacher_answer_display(false, false)); + } } -- GitLab