public function test_check_answer()
 {
     $ques = ORM::factory('question', 10);
     $question = Question::factory($ques);
     $submitted = array(0 => array(0 => "s dasda s", 1 => "asd asd"), 1 => array(0 => "asd asdasdasd", 1 => "asda sasdasd"), 2 => array(0 => "dsf dsdfsdfsdf", 1 => "sa asasd assad"));
     $this->assertTrue($question->check_answer($submitted));
 }
Пример #2
0
 public function test_check_answer()
 {
     $ques = ORM::factory('question', 5);
     $question = Question::factory($ques);
     $submitted = 5;
     $this->assertTrue($question->check_answer($submitted));
 }
Пример #3
0
 public function test_process_hints()
 {
     $formdata = array('hint' => array('hint1', 'hint2', ''), 'sort_order' => array('1', '2', '3'), 'deduction' => array('3.2', '3.4', '5.6'));
     $question = Question::factory('choice');
     $hints = $question->process_hints($formdata);
     $this->assertEquals($hints, array(0 => array('hint' => 'hint1', 'sort_order' => 1, 'deduction' => 3.2), 1 => array('hint' => 'hint2', 'sort_order' => 2, 'deduction' => 3.4)));
 }
 public function test_check_answer()
 {
     $ques = ORM::factory('question', 8);
     $question = Question::factory($ques);
     $submitted = array('twelve', 'sixteen', 'twenty five', 'thirty five');
     $this->assertTrue($question->check_answer($submitted));
     $ques = ORM::factory('question', 7);
     $question = Question::factory($ques);
     $submitted = array('Router', 'Controller', 'Model', 'View');
     $this->assertTrue($question->check_answer($submitted));
 }
 public function test_check_answer()
 {
     // try to load a question of type choice
     $ques = ORM::factory('question', 2);
     $question = Question::factory($ques);
     $submitted = array(4);
     $this->assertTrue($question->check_answer($submitted));
     $ques = ORM::factory('question', 1);
     $question = Question::factory($ques);
     $submitted = array('echo', 'print_r');
     $this->assertTrue($question->check_answer($submitted));
 }
Пример #6
0
 /**
  * @param the exercise progress information stored in the Session
  */
 public function __construct($attempt_session)
 {
     $this->_exercise = ORM::factory('exercise', $attempt_session['exercise_id']);
     $questions = $attempt_session['questions'];
     foreach ($questions as $question_id => $marks) {
         $q = Question::factory((int) $question_id);
         $q->marks($marks);
         $this->_total_marks += $marks;
         $this->_questions[] = $q;
     }
     $this->questions_attempted($attempt_session['ques_attempted']);
     $this->_hints_taken = Arr::get($attempt_session, 'hints_taken', array());
     $this->_score = $this->calculate_score();
     $this->_num_correct = count(array_filter($this->_questions_results));
     $this->_num_incorrect = count($this->_questions) - $this->_num_correct;
 }
Пример #7
0
 public function action_ajax_test_submit()
 {
     $attempt_session = Session::instance()->get('exercise_attempt');
     $responses = $this->request->post('responses');
     $arr = array();
     if ($responses) {
         foreach ($responses as $response) {
             $question = Question::factory((int) $response['question_id']);
             $result = $question->check_answer($response['answer']);
             $arr[$response['question_id']] = array('answer' => $response['answer'], 'result' => $result);
         }
     }
     $exercise = ORM::factory('exercise', $this->request->post('exercise_id'));
     $questions = $exercise->questions();
     $attempt_session['ques_attempted'] = $arr;
     // save in the session
     Session::instance()->set('exercise_attempt', $attempt_session);
     $this->content = json_encode(array('status' => 1));
 }
Пример #8
0
 public function action_preview_overlay()
 {
     // incase the request is not an ajax request, redirect to the not_found page
     if (!$this->request->is_ajax()) {
         Request::current()->redirect('error/not_found');
     }
     $question_id = $this->request->param('id');
     $ques_obj = Question::factory((int) $question_id);
     $question_partial = $ques_obj->render_question(true);
     $this->content = $question_partial;
 }