Skip to content

Commit

Permalink
Fix bug with castext within dropdown input, and add testcase for prev…
Browse files Browse the repository at this point in the history
…ious commit.
  • Loading branch information
sangwinc committed Dec 12, 2024
1 parent f294e8f commit 7ad0204
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion stack/input/dropdown/dropdown.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ public function adapt_to_model_answer($teacheranswer) {
}
if ($ddlvalues[$key]['correct']) {
if (substr($display, 0, 9) === '["%root",') {
$tmp = castext2_parser_utils::unpack_maxima_strings($display);
$tmp = castext2_parser_utils::string_to_list($display, true);
$tmp = castext2_parser_utils::unpack_maxima_strings($tmp);
$holder = new castext2_placeholder_holder();
$correctanswerdisplay[] = castext2_parser_utils::postprocess_parsed($tmp, null, $holder);
} else {
Expand Down
17 changes: 17 additions & 0 deletions tests/input_dropdown_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,21 @@ public function test_decimals() {
$expected = 'A correct answer is: <code>3,1415</code>';
$this->assertEquals($expected, $el->get_teacher_answer_display(false, false));
}

public function test_validate_student_response_castext() {
$options = new stack_options();
$ta = '[[1+x^2,false],[1-x^2,false],' .
'["1+x^3",true,["%root","Hello world ",["smlt","\\({x^3}\\)"]]]]';
$el = stack_input_factory::make('dropdown', 'ans1', $ta, $options, ['options' => '']);
$el->adapt_to_model_answer($ta);
$state = $el->validate_student_response(['ans1' => '2'], $options, '2', new stack_cas_security());
$this->assertEquals(stack_input::SCORE, $state->status);

$ta = '[[1+x^2,true],[1-x^2,false],' .
'["1+x^3",false,["%root","Hello world ",["smlt","\\({x^3}\\)"]]]]';
$el = stack_input_factory::make('dropdown', 'ans1', $ta, $options, ['options' => '']);
$el->adapt_to_model_answer($ta);
$state = $el->validate_student_response(['ans1' => '2'], $options, '2', new stack_cas_security());
$this->assertEquals(stack_input::SCORE, $state->status);
}
}

0 comments on commit 7ad0204

Please sign in to comment.