Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/type/truefalse/simpletest/testquestion.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
00030 
00031 
00038 class qtype_truefalse_question_test extends UnitTestCase {
00039     public function test_is_complete_response() {
00040         $question = test_question_maker::make_question('truefalse', 'true');
00041 
00042         $this->assertFalse($question->is_complete_response(array()));
00043         $this->assertTrue($question->is_complete_response(array('answer' => 0)));
00044         $this->assertTrue($question->is_complete_response(array('answer' => 1)));
00045     }
00046 
00047     public function test_is_gradable_response() {
00048         $question = test_question_maker::make_question('truefalse', 'true');
00049 
00050         $this->assertFalse($question->is_gradable_response(array()));
00051         $this->assertTrue($question->is_gradable_response(array('answer' => 0)));
00052         $this->assertTrue($question->is_gradable_response(array('answer' => 1)));
00053     }
00054 
00055     public function test_grading() {
00056         $question = test_question_maker::make_question('truefalse', 'true');
00057 
00058         $this->assertEqual(array(0, question_state::$gradedwrong),
00059                 $question->grade_response(array('answer' => 0)));
00060         $this->assertEqual(array(1, question_state::$gradedright),
00061                 $question->grade_response(array('answer' => 1)));
00062     }
00063 
00064     public function test_get_correct_response() {
00065         $question = test_question_maker::make_question('truefalse', 'true');
00066 
00067         // true
00068         $this->assertIdentical(array('answer' => 1),
00069                 $question->get_correct_response());
00070 
00071         // false
00072         $question->rightanswer = false;
00073         $this->assertIdentical(array('answer' => 0),
00074                 $question->get_correct_response());
00075     }
00076 
00077     public function test_get_question_summary() {
00078         $tf = test_question_maker::make_question('truefalse', 'true');
00079         $qsummary = $tf->get_question_summary();
00080         $this->assertEqual('The answer is true.', $qsummary);
00081     }
00082 
00083     public function test_summarise_response() {
00084         $tf = test_question_maker::make_question('truefalse', 'true');
00085 
00086         $this->assertEqual(get_string('false', 'qtype_truefalse'),
00087                 $tf->summarise_response(array('answer' => '0')));
00088 
00089         $this->assertEqual(get_string('true', 'qtype_truefalse'),
00090                 $tf->summarise_response(array('answer' => '1')));
00091     }
00092 
00093     public function test_classify_response() {
00094         $tf = test_question_maker::make_question('truefalse', 'true');
00095         $tf->start_attempt(new question_attempt_step(), 1);
00096 
00097         $this->assertEqual(array(
00098                 $tf->id => new question_classified_response(
00099                         0, get_string('false', 'qtype_truefalse'), 0.0)),
00100                 $tf->classify_response(array('answer' => '0')));
00101         $this->assertEqual(array(
00102                 $tf->id => new question_classified_response(
00103                         1, get_string('true', 'qtype_truefalse'), 1.0)),
00104                 $tf->classify_response(array('answer' => '1')));
00105         $this->assertEqual(array(
00106                 $tf->id => question_classified_response::no_response()),
00107                 $tf->classify_response(array()));
00108     }
00109 }
 All Data Structures Namespaces Files Functions Variables Enumerations