/** * Creates the string which Maxima will execute * * @return string */ private function construct_maxima_command() { // Ensure that every command has a valid key. $casoptions = $this->options->get_cas_commands(); $csnames = $casoptions['names']; $csvars = $casoptions['commands']; $cascommands = ''; $caspreamble = ''; $cascommands .= ', print("-1=[ error= ["), cte("__stackmaximaversion",errcatch(__stackmaximaversion:stackmaximaversion)) '; $i = 0; foreach ($this->session as $cs) { if ('' == $cs->get_key()) { $label = 'dumvar' . $i; } else { $label = $cs->get_key(); } // Replace any ?'s with a safe value. $cmd = str_replace('?', 'QMCHAR', $cs->get_casstring()); // Strip off any []s at the end of a variable name. // These are used to assign elements of lists and matrices, but this breaks Maxima's block command. if (false === strpos($label, '[')) { $cleanlabel = $label; } else { $cleanlabel = substr($label, 0, strpos($label, '[')); } // Now we do special things if we have a command to re-order expressions. if (false !== strpos($cmd, 'ordergreat') || false !== strpos($cmd, 'orderless')) { // These commands must be in a separate block, and must only appear once. $caspreamble = $cmd . "\$\n"; $cmd = '0'; } $csnames .= ", {$cleanlabel}"; $cascommands .= ", print(\"{$i}=[ error= [\"), cte(\"{$label}\",errcatch({$label}:{$cmd})) "; $i++; } $cass = $caspreamble; $cass .= 'cab:block([ RANDOM_SEED'; $cass .= $csnames; $cass .= '], stack_randseed('; $cass .= $this->seed . ')' . $csvars; $cass .= ", print(\"[TimeStamp= [ {$this->seed} ], Locals= [ \") "; $cass .= $cascommands; $cass .= ", print(\"] ]\") , return(true) ); \n "; return $cass; }
public function test_matrix_eigenvalues() { $cs = array('A:matrix([7,1,3],[5,-3,4],[5,3,-4])', 'E:first(eigenvalues(A))', 'dt:determinant(A)'); foreach ($cs as $s) { $s1[] = new stack_cas_casstring($s); } $options = new stack_options(); $options->set_option('matrixparens', '('); $at1 = new stack_cas_session($s1, $options, 0); $this->assertEquals('[1-sqrt(66),sqrt(66)+1,-2]', $at1->get_value_key('E')); $this->assertEquals('130', $at1->get_value_key('dt')); $this->assertEquals('\\left(\\begin{array}{ccc} 7 & 1 & 3 \\\\ 5 & -3 & 4 \\\\ 5 & 3 & -4 \\end{array}\\right)', $at1->get_display_key('A')); }
$settings->add(new admin_setting_configcheckbox('qtype_stack/casdebugging', get_string('settingcasdebugging', 'qtype_stack'), get_string('settingcasdebugging_desc', 'qtype_stack'), 0)); // Options for maths display. $settings->add(new admin_setting_heading('mathsdisplayheading', get_string('settingsmathsdisplayheading', 'qtype_stack'), '')); $settings->add(new admin_setting_configcheckbox('qtype_stack/ajaxvalidation', get_string('settingajaxvalidation', 'qtype_stack'), get_string('settingajaxvalidation_desc', 'qtype_stack'), 1)); $settings->add(new qtype_stack_admin_setting_maths_display_method('qtype_stack/mathsdisplay', get_string('settingmathsdisplay', 'qtype_stack'), get_string('settingmathsdisplay_desc', 'qtype_stack'), 'mathjax', null)); $settings->add(new admin_setting_configcheckbox('qtype_stack/replacedollars', get_string('settingreplacedollars', 'qtype_stack'), get_string('settingreplacedollars_desc', 'qtype_stack'), false)); // Options for new inputs. $settings->add(new admin_setting_heading('inputoptionsheading', get_string('settingdefaultinputoptions', 'qtype_stack'), get_string('settingdefaultinputoptions_desc', 'qtype_stack'))); $settings->add(new qtype_stack_admin_setting_input_types('qtype_stack/inputtype', get_string('inputtype', 'qtype_stack'), get_string('inputtype_help', 'qtype_stack'), 'algebraic', null)); $settings->add(new admin_setting_configtext('qtype_stack/inputboxsize', get_string('boxsize', 'qtype_stack'), get_string('boxsize_help', 'qtype_stack'), '15', PARAM_INT)); $settings->add(new admin_setting_configselect('qtype_stack/inputstrictsyntax', get_string('strictsyntax', 'qtype_stack'), get_string('strictsyntax_help', 'qtype_stack'), '1', stack_options::get_yes_no_options())); $settings->add(new admin_setting_configselect('qtype_stack/inputinsertstars', get_string('insertstars', 'qtype_stack'), get_string('insertstars_help', 'qtype_stack'), '0', stack_options::get_insert_star_options())); $settings->add(new admin_setting_configtext('qtype_stack/inputforbidwords', get_string('forbidwords', 'qtype_stack'), get_string('forbidwords_help', 'qtype_stack'), '', PARAM_RAW)); $settings->add(new admin_setting_configselect('qtype_stack/inputforbidfloat', get_string('forbidfloat', 'qtype_stack'), get_string('forbidfloat_help', 'qtype_stack'), '1', stack_options::get_yes_no_options())); $settings->add(new admin_setting_configselect('qtype_stack/inputrequirelowestterms', get_string('requirelowestterms', 'qtype_stack'), get_string('requirelowestterms_help', 'qtype_stack'), '0', stack_options::get_yes_no_options())); $settings->add(new admin_setting_configselect('qtype_stack/inputcheckanswertype', get_string('checkanswertype', 'qtype_stack'), get_string('checkanswertype_help', 'qtype_stack'), '0', stack_options::get_yes_no_options())); $settings->add(new admin_setting_configselect('qtype_stack/inputmustverify', get_string('mustverify', 'qtype_stack'), get_string('mustverify_help', 'qtype_stack'), '1', stack_options::get_yes_no_options())); $settings->add(new admin_setting_configselect('qtype_stack/inputshowvalidation', get_string('showvalidation', 'qtype_stack'), get_string('showvalidation_help', 'qtype_stack'), '1', stack_options::get_showvalidation_options())); // Options for new questions. $settings->add(new admin_setting_heading('questionoptionsheading', get_string('settingdefaultquestionoptions', 'qtype_stack'), get_string('settingdefaultquestionoptions_desc', 'qtype_stack'))); $settings->add(new admin_setting_configselect('qtype_stack/questionsimplify', get_string('questionsimplify', 'qtype_stack'), get_string('autosimplify_help', 'qtype_stack'), '1', stack_options::get_yes_no_options())); $settings->add(new admin_setting_configselect('qtype_stack/assumepositive', get_string('assumepositive', 'qtype_stack'), get_string('assumepositive_help', 'qtype_stack'), '0', stack_options::get_yes_no_options())); $settings->add(new admin_setting_configtextarea('qtype_stack/prtcorrect', get_string('prtcorrectfeedback', 'qtype_stack'), '', get_string('defaultprtcorrectfeedback', 'qtype_stack'), PARAM_RAW, 60, 3)); $settings->add(new admin_setting_configtextarea('qtype_stack/prtpartiallycorrect', get_string('prtpartiallycorrectfeedback', 'qtype_stack'), '', get_string('defaultprtpartiallycorrectfeedback', 'qtype_stack'), PARAM_RAW, 60, 3)); $settings->add(new admin_setting_configtextarea('qtype_stack/prtincorrect', get_string('prtincorrectfeedback', 'qtype_stack'), '', get_string('defaultprtincorrectfeedback', 'qtype_stack'), PARAM_RAW, 60, 3)); $settings->add(new admin_setting_configselect('qtype_stack/multiplicationsign', get_string('multiplicationsign', 'qtype_stack'), get_string('multiplicationsign_help', 'qtype_stack'), 'dot', stack_options::get_multiplication_sign_options())); $settings->add(new admin_setting_configselect('qtype_stack/sqrtsign', get_string('sqrtsign', 'qtype_stack'), get_string('sqrtsign_help', 'qtype_stack'), '1', stack_options::get_yes_no_options())); $settings->add(new admin_setting_configselect('qtype_stack/complexno', get_string('complexno', 'qtype_stack'), get_string('complexno_help', 'qtype_stack'), 'i', stack_options::get_complex_no_options())); $settings->add(new admin_setting_configselect('qtype_stack/inversetrig', get_string('inversetrig', 'qtype_stack'), get_string('inversetrig_help', 'qtype_stack'), 'cos-1', stack_options::get_inverse_trig_options())); $settings->add(new admin_setting_configselect('qtype_stack/matrixparens', get_string('matrixparens', 'qtype_stack'), get_string('matrixparens_help', 'qtype_stack'), '[', stack_options::get_matrix_parens_options()));
/** * Add the form fields for a given input element to the form. * @param string $inputname the input name. * @param MoodleQuickForm $mform the form being assembled. * @param int $counts the number of times this input and its validation appears in the questiontext. */ protected function definition_input($inputname, MoodleQuickForm $mform, $counts) { $mform->addElement('header', $inputname . 'header', stack_string('inputheading', $inputname)); if ($counts[self::INPUTS] == 0 && $counts[self::VALIDATIONS] == 0) { $mform->addElement('static', $inputname . 'warning', '', stack_string('inputwillberemoved', $inputname)); $mform->addElement('advcheckbox', $inputname . 'deleteconfirm', '', stack_string('inputremovedconfirm')); $mform->setDefault($inputname . 'deleteconfirm', 0); $mform->setExpanded($inputname . 'header'); } $mform->addElement('select', $inputname . 'type', stack_string('inputtype'), $this->typechoices); $mform->setDefault($inputname . 'type', $this->stackconfig->inputtype); $mform->addHelpButton($inputname . 'type', 'inputtype', 'qtype_stack'); $mform->addElement('text', $inputname . 'modelans', stack_string('teachersanswer'), array('size' => 20)); $mform->setType($inputname . 'modelans', PARAM_RAW); $mform->addHelpButton($inputname . 'modelans', 'teachersanswer', 'qtype_stack'); // We don't make modelans a required field in the formslib sense, because // That stops the input sections collapsing by default. Instead, we enforce // that it is non-blank in the server-side validation. $mform->addElement('text', $inputname . 'boxsize', stack_string('boxsize'), array('size' => 3)); $mform->setDefault($inputname . 'boxsize', $this->stackconfig->inputboxsize); $mform->setType($inputname . 'boxsize', PARAM_INT); $mform->addHelpButton($inputname . 'boxsize', 'boxsize', 'qtype_stack'); $mform->addElement('selectyesno', $inputname . 'strictsyntax', stack_string('strictsyntax')); $mform->setDefault($inputname . 'strictsyntax', $this->stackconfig->inputstrictsyntax); $mform->addHelpButton($inputname . 'strictsyntax', 'strictsyntax', 'qtype_stack'); $mform->addElement('select', $inputname . 'insertstars', stack_string('insertstars'), stack_options::get_insert_star_options()); $mform->setDefault($inputname . 'insertstars', $this->stackconfig->inputinsertstars); $mform->addHelpButton($inputname . 'insertstars', 'insertstars', 'qtype_stack'); $mform->addElement('text', $inputname . 'syntaxhint', stack_string('syntaxhint'), array('size' => 20)); $mform->setType($inputname . 'syntaxhint', PARAM_RAW); $mform->addHelpButton($inputname . 'syntaxhint', 'syntaxhint', 'qtype_stack'); $mform->addElement('text', $inputname . 'forbidwords', stack_string('forbidwords'), array('size' => 20)); $mform->setType($inputname . 'forbidwords', PARAM_RAW); $mform->setDefault($inputname . 'forbidwords', $this->stackconfig->inputforbidwords); $mform->addHelpButton($inputname . 'forbidwords', 'forbidwords', 'qtype_stack'); $mform->addElement('text', $inputname . 'allowwords', stack_string('allowwords'), array('size' => 20)); $mform->setType($inputname . 'allowwords', PARAM_RAW); $mform->setDefault($inputname . 'allowwords', ''); $mform->addHelpButton($inputname . 'allowwords', 'allowwords', 'qtype_stack'); $mform->addElement('selectyesno', $inputname . 'forbidfloat', stack_string('forbidfloat')); $mform->setDefault($inputname . 'forbidfloat', $this->stackconfig->inputforbidfloat); $mform->addHelpButton($inputname . 'forbidfloat', 'forbidfloat', 'qtype_stack'); $mform->addElement('selectyesno', $inputname . 'requirelowestterms', stack_string('requirelowestterms')); $mform->setDefault($inputname . 'requirelowestterms', $this->stackconfig->inputrequirelowestterms); $mform->addHelpButton($inputname . 'requirelowestterms', 'requirelowestterms', 'qtype_stack'); $mform->addElement('selectyesno', $inputname . 'checkanswertype', stack_string('checkanswertype')); $mform->setDefault($inputname . 'checkanswertype', $this->stackconfig->inputcheckanswertype); $mform->addHelpButton($inputname . 'checkanswertype', 'checkanswertype', 'qtype_stack'); $mform->addElement('selectyesno', $inputname . 'mustverify', stack_string('mustverify')); $mform->setDefault($inputname . 'mustverify', $this->stackconfig->inputmustverify); $mform->addHelpButton($inputname . 'mustverify', 'mustverify', 'qtype_stack'); $mform->addElement('select', $inputname . 'showvalidation', stack_string('showvalidation'), stack_options::get_showvalidation_options()); $mform->setDefault($inputname . 'showvalidation', $this->stackconfig->inputshowvalidation); $mform->addHelpButton($inputname . 'showvalidation', 'showvalidation', 'qtype_stack'); $mform->addElement('text', $inputname . 'options', stack_string('inputextraoptions'), array('size' => 20)); $mform->setType($inputname . 'options', PARAM_RAW); $mform->addHelpButton($inputname . 'options', 'inputextraoptions', 'qtype_stack'); }
public function test_assignmatrixelements_p2() { // Assign a value to matrix entries. $cs = array('A:matrix([1,2],[1,1])', 'A[1,2]:3'); foreach ($cs as $s) { $cs = new stack_cas_casstring($s); $cs->get_valid('t'); $s1[] = $cs; } $options = new stack_options(); $options->set_option('matrixparens', ''); $at1 = new stack_cas_session($s1, $options, 0); $at1 = new stack_cas_text("@A@", $at1, 0); $at1->get_display_castext(); $this->assertEquals('\\(\\begin{array}{cc} 1 & 3 \\\\ 1 & 1 \\end{array}\\)', $at1->get_display_castext()); }
public static function run_test($test) { // Note: What we would really like to do is the following. // $el = stack_input_factory::make('algebraic', 'sans1', 'x'); // $el->set_parameter('insertStars', 1); // $el->set_parameter('strictSyntax', false); // $el->set_parameter('sameType', false); // $cs = $el->validate_student_response($test->rawstring); // However, we want to pull apart the bits to expose where the various errors occur. $cs = new stack_cas_casstring($test->rawstring); $cs->get_valid('s', false, 1); $cs->set_cas_validation_casstring('sans1', true, true, false, null); $phpvalid = $cs->get_valid(); if ($phpvalid) { // Trim off stack_validate_typeless([..], true, true). $phpcasstring = $cs->get_casstring(); $phpcasstring = substr($phpcasstring, 25); $phpcasstring = substr($phpcasstring, 0, strlen($phpcasstring) - 12); $outputphpcasstring = $phpcasstring; } else { $phpcasstring = ''; $outputphpcasstring = 'N/A...'; } $errors = $cs->get_errors(); $passed = true; if ('php_true' === $test->phpvalid) { $expected = true; } else { $expected = false; } if ($phpvalid != $expected) { $passed = false; $errors .= ' ' . stack_string('phpvalidatemismatch'); } if ($phpvalid && $phpcasstring != $test->phpcasstring) { $passed = false; $errors .= ' ' . stack_maxima_format_casstring($phpcasstring) . ' \\(\\neq \\) ' . stack_maxima_format_casstring($test->phpcasstring); } $casvalid = ''; $caserrors = ''; $casvalue = ''; $casdisplay = ''; if ($cs->get_valid()) { $options = new stack_options(); $options->set_option('simplify', false); $session = new stack_cas_session(array($cs), $options, 0); $session->instantiate(); $session = $session->get_session(); $cs = $session[0]; $caserrors = stack_maxima_translate($cs->get_errors()); $casvalue = stack_maxima_format_casstring($cs->get_value()); if ('cas_true' == $test->casvalid) { $casexpected = true; } else { $casexpected = false; } if ('' == $cs->get_value()) { $casvalid = false; } else { $casvalid = true; } if ($casexpected != $casvalid) { $passed = false; $caserrors .= ' ' . stack_string('casvalidatemismatch'); } $casdisplay = $cs->get_display(); } $answernote = $cs->get_answernote(); if ($answernote != $test->ansnotes) { $passed = false; $errors .= ' ' . stack_string('ansnotemismatch'); } return array($passed, $phpvalid, $phpcasstring, $errors, $casvalid, $caserrors, $casdisplay, $casvalue, $answernote); }
$simp = optional_param('simp', '', PARAM_RAW); // Always fix dollars in this script. // Very useful for converting existing text for use elswhere in Moodle, such as in pages of text. $string = stack_maths::replace_dollars($string); // Sort out simplification. if ('on' == $simp) { $simp = true; } else { $simp = false; } // Initially simplification should be on. if (!$vars and !$string) { $simp = true; } if ($string) { $options = new stack_options(); $options->set_site_defaults(); $options->set_option('simplify', $simp); $session = new stack_cas_session(null, $options); if ($vars) { $keyvals = new stack_cas_keyval($vars, $options, 0, 't'); $session = $keyvals->get_session(); $varerrs = $keyvals->get_errors(); } if (!$varerrs) { $ct = new stack_cas_text($string, $session, 0, 't'); $displaytext = $ct->get_display_castext(); $errs = $ct->get_errors(); $debuginfo = $ct->get_debuginfo(); } }
public function test_set_exception_5() { $opts = new stack_options(); $this->setExpectedException('stack_exception'); $opts->set_option('display', 'latex'); }