Skip to content

Commit

Permalink
Merge branch 'dev' into geogebra_stackjs
Browse files Browse the repository at this point in the history
  • Loading branch information
sangwinc committed Oct 21, 2023
2 parents c1ee5c8 + fdc1752 commit 796a1e1
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 63 deletions.
2 changes: 1 addition & 1 deletion amd/build/input.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/stackjsvle.min.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions doc/en/Developer/Releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Check

* Run PHP [unit tests](Unit_tests.md).
* Run code checker.
* If needed re-build the minified Javascript (e.g. `npx grunt --root=question/type/stack`).

Version numbers

Expand Down
4 changes: 2 additions & 2 deletions lang/en/qtype_stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@
$string['ddl_badanswer'] = 'The model answer field for this input is malformed: <code>{$a}</code>. ';
$string['ddl_unknown'] = 'STACK received <code>{$a}</code> but this is not listed by the teacher as an option. ';

$string['teacheranswershow'] = 'A correct answer is \( {$a->display} \), which can be typed in as follows: {$a->value}';
$string['teacheranswershow_disp'] = 'A correct answer is {$a->display}.';
$string['teacheranswershow'] = 'The answer \( {$a->display} \), which can be typed as {$a->value}, would be correct.';
$string['teacheranswershow_disp'] = 'The answer {$a->display} would be correct.';
$string['teacheranswershow_mcq'] = 'A correct answer is: {$a->display}';
$string['teacheranswershownotes'] = 'A correct answer is not provided for this input.';
$string['teacheranswerempty'] = 'This input can be left blank.';
Expand Down
83 changes: 44 additions & 39 deletions tests/input_algebraic_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ public function test_validate_student_response_algebraic_1() {
$el = stack_input_factory::make('algebraic', 'sans1', 'x^2/(1+x^2)');
$state = $el->validate_student_response(array('sans1' => 'x^2'), $options, 'x^2/(1+x^2)', new stack_cas_security());
$this->assertEquals(stack_input::VALID, $state->status);
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( \frac{x^2}{1+x^2} \)</span></span>, which can be typed in as follows: '
. '<code>x^2/(1+x^2)</code>', $el->get_teacher_answer_display('x^2/(1+x^2)', '\frac{x^2}{1+x^2}'));
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( \frac{x^2}{1+x^2} \)</span></span>, which can be typed as '
. '<code>x^2/(1+x^2)</code>, would be correct.',
$el->get_teacher_answer_display('x^2/(1+x^2)', '\frac{x^2}{1+x^2}'));

$el->set_parameter('showValidation', 1);
$vr = '<div class="stackinputfeedback standard" id="sans1_val" aria-live="assertive">' .
Expand Down Expand Up @@ -277,9 +278,10 @@ public function test_validate_student_response_algebraic_9() {
$this->assertEquals('', $state->errors);
$this->assertEquals('1 < x nounand x < 7', $state->contentsmodified);
$this->assertEquals('\[ 1 < x\,{\mbox{ and }}\, x < 7 \]', $state->contentsdisplayed);
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( 1<x \,{\mbox{and}}\,x<8 \)</span></span>, which can be typed in as follows: '
. '<code>1 < x and x < 8</code>', $el->get_teacher_answer_display('1<x nounand x<8', '1<x \,{\mbox{and}}\,x<8'));
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( 1<x \,{\mbox{and}}\,x<8 \)</span></span>, which can be typed as '
. '<code>1 < x and x < 8</code>, would be correct.',
$el->get_teacher_answer_display('1<x nounand x<8', '1<x \,{\mbox{and}}\,x<8'));
}

public function test_validate_student_response_algebraic_10() {
Expand Down Expand Up @@ -435,9 +437,10 @@ public function test_validate_student_response_insertstars_sqrt_1() {
$this->assertEquals(stack_input::VALID, $state->status);
$this->assertEquals('2*sqrt(+2)/3', $state->contentsmodified);
$this->assertEquals('\[ \frac{2\cdot \sqrt{2}}{3} \]', $state->contentsdisplayed);
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( \frac{2\cdot \sqrt{2}}{3} \)</span></span>, which can be typed in as follows: '
. '<code>2*sqrt(2)/3</code>', $el->get_teacher_answer_display('2*sqrt(2)/3', '\frac{2\cdot \sqrt{2}}{3}'));
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( \frac{2\cdot \sqrt{2}}{3} \)</span></span>, which can be typed as '
. '<code>2*sqrt(2)/3</code>, would be correct.',
$el->get_teacher_answer_display('2*sqrt(2)/3', '\frac{2\cdot \sqrt{2}}{3}'));
}

public function test_validate_student_response_sametype_true_1() {
Expand Down Expand Up @@ -828,9 +831,9 @@ public function test_validate_lg_1() {
$this->assertEquals(stack_input::VALID, $state->status);
$this->assertEquals('lg(27,3)', $state->contentsmodified);
$this->assertEquals('\[ \log_{3}\left(27\right) \]', $state->contentsdisplayed);
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">' .
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">' .
'<span class="nolink">\[ \[ \log_{3}\left(27\right) \]</span></span> \), ' .
'which can be typed in as follows: <code>lg(27,3)</code>',
'which can be typed as <code>lg(27,3)</code>, would be correct.',
$el->get_teacher_answer_display($state->contentsmodified, $state->contentsdisplayed));
}

Expand All @@ -841,9 +844,9 @@ public function test_validate_lg_10() {
$this->assertEquals(stack_input::VALID, $state->status);
$this->assertEquals('lg(23,10)', $state->contentsmodified);
$this->assertEquals('\[ \log_{10}\left(23\right) \]', $state->contentsdisplayed);
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">' .
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">' .
'<span class="nolink">\[ \[ \log_{10}\left(23\right) \]</span></span> \), ' .
'which can be typed in as follows: <code>lg(23,10)</code>',
'which can be typed as <code>lg(23,10)</code>, would be correct.',
$el->get_teacher_answer_display($state->contentsmodified, $state->contentsdisplayed));
}

Expand All @@ -854,9 +857,9 @@ public function test_validate_lg_10b() {
$this->assertEquals(stack_input::VALID, $state->status);
$this->assertEquals('lg(19)', $state->contentsmodified);
$this->assertEquals('\[ \log_{10}\left(19\right) \]', $state->contentsdisplayed);
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">' .
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">' .
'<span class="nolink">\[ \[ \log_{10}\left(19\right) \]</span></span> \), ' .
'which can be typed in as follows: <code>lg(19)</code>',
'which can be typed as <code>lg(19)</code>, would be correct.',
$el->get_teacher_answer_display($state->contentsmodified, $state->contentsdisplayed));
}

Expand Down Expand Up @@ -967,9 +970,9 @@ public function test_validate_student_response_star_space_1() {
$this->assertEquals('3*sin(a*b)', $state->contentsmodified);
$this->assertEquals('Illegal spaces found in expression <span class="stacksyntaxexample">' .
'3*sin(a<span class="stacksyntaxexamplehighlight">_</span>b)</span>.', $state->errors);
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">' .
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">' .
'<span class="nolink">\( 3\, \sin(a \cdot b) \)</span></span>, ' .
'which can be typed in as follows: <code>3*sin(a*b)</code>',
'which can be typed as <code>3*sin(a*b)</code>, would be correct.',
$el->get_teacher_answer_display('3*sin(a*b)', '3\\, \\sin(a \cdot b)'));
}

Expand Down Expand Up @@ -1051,9 +1054,9 @@ public function test_validate_student_response_prefixpm() {
$this->assertEquals('', $state->errors);
$this->assertEquals('\[ x= \pm b \]', $state->contentsdisplayed);
// Internally the teacher's answer will be in the #pm# form, which is not what students type.
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( x= \pm b \)</span></span>, which can be typed in as follows: '
. '<code>x = +-b</code>', $el->get_teacher_answer_display('x= #pm# b', 'x= \pm b'));
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( x= \pm b \)</span></span>, which can be typed as '
. '<code>x = +-b</code>, would be correct.', $el->get_teacher_answer_display('x= #pm# b', 'x= \pm b'));
}

public function test_validate_student_response_pm_expr() {
Expand All @@ -1067,9 +1070,9 @@ public function test_validate_student_response_pm_expr() {
$this->assertEquals('', $state->note);
$this->assertEquals('', $state->errors);
$this->assertEquals('\[ {a \pm b \pm c} \]', $state->contentsdisplayed);
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( {a \pm b \pm c} \)</span></span>, which can be typed in as follows: '
. '<code>a+-b+-c</code>', $el->get_teacher_answer_display('a#pm#b#pm#c', '{a \pm b \pm c}'));
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( {a \pm b \pm c} \)</span></span>, which can be typed as '
. '<code>a+-b+-c</code>, would be correct.', $el->get_teacher_answer_display('a#pm#b#pm#c', '{a \pm b \pm c}'));
}

public function test_validate_student_response_pm_eq() {
Expand All @@ -1083,9 +1086,9 @@ public function test_validate_student_response_pm_eq() {
$this->assertEquals('', $state->note);
$this->assertEquals('', $state->errors);
$this->assertEquals('\[ {x \pm a}={y \pm b} \]', $state->contentsdisplayed);
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( {x \pm a}={y \pm b} \)</span></span>, which can be typed in as follows: '
. '<code>x+-a = y+-b</code>',
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( {x \pm a}={y \pm b} \)</span></span>, which can be typed as '
. '<code>x+-a = y+-b</code>, would be correct.',
$el->get_teacher_answer_display('x #pm# a = y #pm# b', '{x \pm a}={y \pm b}'));
}

Expand All @@ -1112,8 +1115,9 @@ public function test_validate_student_response_with_align_right() {
$this->assertEquals('sin(x)', $state->contentsmodified);
$this->assertEquals('\[ \sin \left( x \right) \]', $state->contentsdisplayed);
$this->assertEquals('', $state->errors);
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation"><span class="nolink">' .
'\[ \[ \sin \left( x \right) \]</span></span> \), which can be typed in as follows: <code>sin(x)</code>',
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation"><span class="nolink">' .
'\[ \[ \sin \left( x \right) \]</span></span> \), which can be typed as <code>sin(x)</code>,' .
' would be correct.',
$el->get_teacher_answer_display($state->contentsmodified, $state->contentsdisplayed));
$this->assertEquals('<input type="text" name="stack1__ans1" id="stack1__ans1" size="16.5" ' .
'style="width: 13.6em" autocapitalize="none" spellcheck="false" class="algebraic-right" value="sin(x)" />',
Expand Down Expand Up @@ -1146,9 +1150,9 @@ public function test_validate_student_response_noununits() {
$this->assertEquals('', $state->errors);
// Note the unknown unit is not in roman here.
$this->assertEquals('\( \left[ a , \mathrm{m} , \mathrm{s} \right]\) ', $state->lvars);
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation"><span class="nolink">' .
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation"><span class="nolink">' .
'\[ \[ \frac{9.81\cdot a\cdot \mathrm{m}}{\mathrm{s}} \]</span></span> \), ' .
'which can be typed in as follows: <code>9.81*a*m/s</code>',
'which can be typed as <code>9.81*a*m/s</code>, would be correct.',
$el->get_teacher_answer_display($state->contentsmodified, $state->contentsdisplayed));
}

Expand Down Expand Up @@ -1590,9 +1594,10 @@ public function test_validate_student_response_ntuple() {
'\[ \left(1, 2\right) \]');
$this->assertEquals('', $state->note);

$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( \left(1, -1\right) \)</span></span>, which can be typed in as follows: '
. '<code>(1,-1)</code>', $el->get_teacher_answer_display('ntuple(1,-1)', '\left(1, -1\right)'));
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( \left(1, -1\right) \)</span></span>, which can be typed as '
. '<code>(1,-1)</code>, would be correct.',
$el->get_teacher_answer_display('ntuple(1,-1)', '\left(1, -1\right)'));
}

public function test_validate_student_response_ntuple_forbid() {
Expand Down Expand Up @@ -1741,9 +1746,9 @@ public function test_decimal_output_0() {
$this->assertEquals('You have used the full stop <code>.</code>, but you must use the comma <code>,</code> as a ' .
'decimal separator!',
$state->errors);
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( \{3{,}1415 ; 2{,}7100 \right \} \)</span></span>, which can be typed in as follows: '
. '<code>{3,1415;2,71}</code>',
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( \{3{,}1415 ; 2{,}7100 \right \} \)</span></span>, which can be typed as '
. '<code>{3,1415;2,71}</code>, would be correct.',
$el->get_teacher_answer_display('{3.1415,2.71}', '\{3{,}1415 ; 2{,}7100 \right \}'));
}

Expand All @@ -1761,9 +1766,9 @@ public function test_decimal_output_1() {
$this->assertEquals('<span class="stacksyntaxexample">{3.1415;2.71}</span>', $state->contentsdisplayed);
$this->assertEquals('You have used the full stop <code>.</code>, but you must use the comma ' .
'<code>,</code> as a decimal separator!', $state->errors);
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( \{3{,}1415 ; 2{,}7100 \right \} \)</span></span>, which can be typed in as follows: '
. '<code>{3,1415;2,71}</code>',
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( \{3{,}1415 ; 2{,}7100 \right \} \)</span></span>, which can be typed as '
. '<code>{3,1415;2,71}</code>, would be correct.',
$el->get_teacher_answer_display('{3.1415,2.71}', '\{3{,}1415 ; 2{,}7100 \right \}'));
}

Expand Down
12 changes: 6 additions & 6 deletions tests/input_equiv_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ public function test_validate_student_response_with_equiv() {

// The test below does not use the LaTeX of the teacher's answer.
// The test just confirms nounor in $val get converted to something the student should type in.
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">' .
'<span class="nolink">\( ### \)</span></span>, which can be typed in as follows: <br/>' .
'<code>x^2-5*x+6 = 0</code><br/><code>x = 2 or x = 3</code>',
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">' .
'<span class="nolink">\( ### \)</span></span>, which can be typed as <br/>' .
'<code>x^2-5*x+6 = 0</code><br/><code>x = 2 or x = 3</code>, would be correct.',
$el->get_teacher_answer_display($val, '###'));
}

Expand Down Expand Up @@ -774,9 +774,9 @@ public function test_validate_student_pm() {

// The test below does not use the LaTeX of the teacher's answer.
// The test just confirms #pm# in $val get converted to something the student should type in.
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">' .
'<span class="nolink">\( ### \)</span></span>, which can be typed in as follows: <br/>' .
'<code>(x-a)^2 = 4</code><br/><code>x-a = +-2</code><br/><code>x = a+-2</code>',
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">' .
'<span class="nolink">\( ### \)</span></span>, which can be typed as <br/>' .
'<code>(x-a)^2 = 4</code><br/><code>x-a = +-2</code><br/><code>x = a+-2</code>, would be correct.',
$el->get_teacher_answer_display($val, '###'));

$el->set_parameter('options', 'hideanswer');
Expand Down
5 changes: 3 additions & 2 deletions tests/input_singlechar_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public function test_validate_student_response_1() {
$el = stack_input_factory::make('singleChar', 'sans1', 'A');
$state = $el->validate_student_response(array('sans1' => 'a'), $options, 'A', new stack_cas_security());
$this->assertEquals(stack_input::SCORE, $state->status);
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( A \)</span></span>.', $el->get_teacher_answer_display('A', 'A'));
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">'
. '<span class="nolink">\( A \)</span></span> would be correct.',
$el->get_teacher_answer_display('A', 'A'));
}
}
9 changes: 5 additions & 4 deletions tests/input_string_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public function test_render_hello_world() {
.'style="width: 13.6em" autocapitalize="none" spellcheck="false" class="maxima-string" value="0" />',
$el->render(new stack_input_state(stack_input::VALID, array('0'), '', '', '', '', ''),
'stack1__ans1', false, null));
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation"><span class="nolink">' .
'\( \\mbox{Hello world} \)</span></span>, which can be typed in as follows: <code>Hello world</code>',
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation"><span class="nolink">' .
'\( \\mbox{Hello world} \)</span></span>, which can be typed as <code>Hello world</code>, ' .
'would be correct.',
$el->get_teacher_answer_display('"Hello world"', '\\mbox{Hello world}'));
}

Expand All @@ -71,9 +72,9 @@ public function test_validate_string_input() {
$this->assertEquals(stack_input::VALID, $state->status);
$this->assertEquals('"Hello world"', $state->contentsmodified);
$this->assertEquals('\[ \mbox{Hello world} \]', $state->contentsdisplayed);
$this->assertEquals('A correct answer is <span class="filter_mathjaxloader_equation">' .
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">' .
'<span class="nolink">\[ \[ \mbox{Hello world} \]</span></span> \), ' .
'which can be typed in as follows: <code>Hello world</code>',
'which can be typed as <code>Hello world</code>, would be correct.',
$el->get_teacher_answer_display($state->contentsmodified, $state->contentsdisplayed));
}

Expand Down
Loading

0 comments on commit 796a1e1

Please sign in to comment.