/** * Validate the fields for a given PRT node. * @param array $errors the error so far. This array is added to and returned. * @param array $fromform the submitted data to validate. * @param string $prtname the name of the PRT to validate. * @param string $nodekey the name of the node to validate. * @return array the update $errors array. */ protected function validate_prt_node($errors, $fromform, $prtname, $nodekey, $fixingdollars) { $nodegroup = $prtname . 'node[' . $nodekey . ']'; $errors = $this->validate_cas_string($errors, $fromform[$prtname . 'sans'][$nodekey], $nodegroup, $prtname . 'sans' . $nodekey, 'sansrequired'); $errors = $this->validate_cas_string($errors, $fromform[$prtname . 'tans'][$nodekey], $nodegroup, $prtname . 'tans' . $nodekey, 'tansrequired'); $answertest = new stack_ans_test_controller($fromform[$prtname . 'answertest'][$nodekey]); if ($answertest->required_atoptions()) { $opt = trim($fromform[$prtname . 'testoptions'][$nodekey]); if ('' === trim($opt)) { $errors[$nodegroup][] = stack_string('testoptionsrequired'); } else { if (strlen($opt > 255)) { $errors[$nodegroup][] = stack_string('testoptionsinvalid', stack_string('strlengtherror')); } else { // TODO capture this for later execution. list($valid, $message) = $answertest->validate_atoptions($opt); if (!$valid) { $errors[$nodegroup][] = stack_string('testoptionsinvalid', $message); } } } } foreach (array('true', 'false') as $branch) { $branchgroup = $prtname . 'nodewhen' . $branch . '[' . $nodekey . ']'; $score = $fromform[$prtname . $branch . 'score'][$nodekey]; if (!is_numeric($score) || $score < 0 || $score > 1) { $errors[$branchgroup][] = stack_string('scoreerror'); } $penalty = $fromform[$prtname . $branch . 'penalty'][$nodekey]; if ('' != $penalty && (!is_numeric($penalty) || $penalty < 0 || $penalty > 1)) { $errors[$branchgroup][] = stack_string('penaltyerror2'); } $answernote = $fromform[$prtname . $branch . 'answernote'][$nodekey]; if ('' == $answernote) { $errors[$branchgroup][] = stack_string('answernoterequired'); } else { if (strstr($answernote, '|') !== false) { $errors[$branchgroup][] = stack_string('answernote_err'); foreach ($fromform[$prtname . $branch . 'answernote'] as $key => $strin) { if ('' == trim($strin)) { $interror[$prtname . 'nodewhen' . $branch . '[' . $key . ']'][] = stack_string('answernoterequired'); } else { if (strstr($strin, '|') !== false) { $nodename = $key + 1; $interror[$prtname . 'nodewhen' . $branch . '[' . $key . ']'][] = stack_string('answernote_err'); } } } } } $errors = $this->validate_cas_text($errors, $fromform[$prtname . $branch . 'feedback'][$nodekey]['text'], $prtname . $branch . 'feedback[' . $nodekey . ']', $fixingdollars); } return $errors; }
public static function run_test($test) { $anst = new stack_ans_test_controller($test->name, $test->studentanswer, $test->teacheranswer, new stack_options(), $test->options); // The false clause is useful for developers to track down which test case is breaking Maxima. if (true) { $result = $anst->do_test(); // This actually executes the answer test in the CAS. $errors = $anst->get_at_errors(); $rawmark = $anst->get_at_mark(); $feedback = $anst->get_at_feedback(); $ansnote = $anst->get_at_answernote(); } else { $feedback = 'AT' . $test->name . '(' . $test->studentanswer . ',' . $test->teacheranswer . ');'; $result = true; // This actually executes the answer test in the CAS. $errors = ''; $rawmark = 0; $ansnote = ''; } $passed = false; if ($rawmark === $test->expectedscore) { $passed = true; } // The test failed, and we expected it to fail. if ($errors === 'TEST_FAILED') { if (-1 === $test->expectedscore) { $passed = true; } else { $passed = false; } } // These tests are all expected to fail, so we make them all pass. if (-2 === $test->expectedscore) { $passed = true; } return array($passed, $errors, $rawmark, $feedback, $ansnote); }
public function process_atoptions() { $at = new stack_ans_test_controller($this->answertest, '', '', null, ''); return $at->process_atoptions(); }