Ejemplo n.º 1
0
 public function get_valid($cs, $val)
 {
     if (is_array($cs)) {
         $s1 = array();
         foreach ($cs as $s) {
             $s1[] = new stack_cas_casstring($s);
         }
     } else {
         $s1 = null;
     }
     $at1 = new stack_cas_session($s1);
     $this->assertEquals($val, $at1->get_valid());
 }
Ejemplo n.º 2
0
 private function validate()
 {
     if (empty($this->raw) or '' == trim($this->raw)) {
         $this->valid = true;
         return true;
     }
     // CAS keyval may not contain @ or $.
     if (strpos($this->raw, '@') !== false || strpos($this->raw, '$') !== false) {
         $this->errors = stack_string('illegalcaschars');
         $this->valid = false;
         return false;
     }
     // Subtle one: must protect things inside strings before we explode.
     $str = $this->raw;
     $strings = stack_utils::all_substring_strings($str);
     foreach ($strings as $key => $string) {
         $str = str_replace('"' . $string . '"', '[STR:' . $key . ']', $str);
     }
     $str = str_replace("\n", ';', $str);
     $str = stack_utils::remove_comments($str);
     $str = str_replace(';', "\n", $str);
     $kvarray = explode("\n", $str);
     foreach ($strings as $key => $string) {
         foreach ($kvarray as $kkey => $kstr) {
             $kvarray[$kkey] = str_replace('[STR:' . $key . ']', '"' . $string . '"', $kstr);
         }
     }
     // 23/4/12 - significant changes to the way keyvals are interpreted.  Use Maxima assignmentsm i.e. x:2.
     $errors = '';
     $valid = true;
     $vars = array();
     foreach ($kvarray as $kvs) {
         $kvs = trim($kvs);
         if ('' != $kvs) {
             $cs = new stack_cas_casstring($kvs);
             $cs->get_valid($this->security, $this->syntax, $this->insertstars);
             $vars[] = $cs;
         }
     }
     $this->session->add_vars($vars);
     $this->valid = $this->session->get_valid();
     $this->errors = $this->session->get_errors();
 }
 public function test_do_test_3()
 {
     // Nontrivial use of the feeback variables.
     // Error in authoring ends up in loop.   STACK should bail.
     $options = new stack_options();
     $seed = 12345;
     $questionvars = new stack_cas_keyval('n:3; p:(x+1)^n; ta:p;', $options, $seed, 't');
     // Feeback variables.
     $cstrings = array('sa1:sans', 'sa2:expand(sans)');
     foreach ($cstrings as $s) {
         $cs = new stack_cas_casstring($s);
         $cs->get_valid('t');
         $s1[] = $cs;
     }
     $feedbackvars = new stack_cas_session($s1, $options, $seed);
     $feedbackvars->get_valid();
     // Define the tree itself.
     $sans = new stack_cas_casstring('sa1');
     $sans->get_valid('t');
     $tans = new stack_cas_casstring('ta');
     $tans->get_valid('t');
     $node = new stack_potentialresponse_node($sans, $tans, 'AlgEquiv', '', true);
     $node->add_branch(0, '=', 0, '', -1, 'Test 1 false. Look: \\[@(sa1)^2@ \\neq @(sa2)^2@\\]', FORMAT_HTML, '1-0-0');
     $node->add_branch(1, '=', 1, '', 1, 'Test 1 true. ', FORMAT_HTML, '1-0-1');
     $potentialresponses[] = $node;
     $sans = new stack_cas_casstring('sa2');
     $sans->get_valid('t');
     $tans = new stack_cas_casstring('ta');
     $tans->get_valid('t');
     $node = new stack_potentialresponse_node($sans, $tans, 'FacForm', 'x', true);
     $node->add_branch(0, '-', 0.7, '', 0, 'Test 2 false.', FORMAT_HTML, '1-1-0');
     $node->add_branch(1, '+', 1, '', 3, 'Test 2 true', FORMAT_HTML, '1-1-1');
     $potentialresponses[] = $node;
     $tree = new stack_potentialresponse_tree('', '', true, 5, $feedbackvars, $potentialresponses, 0);
     // Some data from students.
     $answers = array('sans' => '(x+1)^3');
     $result = $tree->evaluate_response($questionvars->get_session(), $options, $answers, $seed);
     $this->assertTrue($result->valid);
     $this->assertEquals('', $result->errors);
     $this->assertEquals(0.3, $result->score);
     $this->assertEquals(0, $result->penalty);
     $this->assertEquals(2, count($result->feedback));
     $this->assertEquals('Test 1 true.', $result->feedback[0]->feedback);
     $this->assertEquals('Test 2 false.', $result->feedback[1]->feedback);
     $this->assertEquals(array('1-0-1', 'ATFacForm_notfactored.', '1-1-0', '[PRT-CIRCULARITY]=0'), $result->answernotes);
     $this->assertEquals(array('sa1', 'ta'), $tree->get_required_variables(array('sa1', 'sa3', 'ta', 'ssa1', 'a1', 't')));
 }
Ejemplo n.º 4
0
 public function test_disp_mult_cross()
 {
     $a2 = array('make_multsgn("cross")', 'b:x*y');
     $s2 = array();
     foreach ($a2 as $s) {
         $cs = new stack_cas_casstring($s);
         $cs->get_valid('t');
         $s2[] = $cs;
     }
     $cs2 = new stack_cas_session($s2, null, 0);
     $this->assertTrue($cs2->get_valid());
     $at1 = new stack_cas_text('@b@', $cs2, 0, 't');
     $this->assertTrue($at1->get_valid());
     $at1->get_display_castext();
     $this->assertEquals($at1->get_display_castext(), '\\(x\\times y\\)');
 }
 public function test_exception_2()
 {
     $this->setExpectedException('stack_exception');
     $at1 = new stack_cas_session(array(), null, false);
     $at1->get_valid();
 }