|
Moodle
2.2.1
http://www.collinsharper.com
|
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 00017 00028 require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php'); 00029 00030 00037 class qtype_calculated_question_test extends UnitTestCase { 00038 public function test_is_complete_response() { 00039 $question = test_question_maker::make_question('calculated'); 00040 00041 $this->assertFalse($question->is_complete_response(array())); 00042 $this->assertTrue($question->is_complete_response(array('answer' => '0'))); 00043 $this->assertTrue($question->is_complete_response(array('answer' => 0))); 00044 $this->assertFalse($question->is_complete_response(array('answer' => 'test'))); 00045 } 00046 00047 public function test_is_gradable_response() { 00048 $question = test_question_maker::make_question('calculated'); 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' => 0))); 00053 $this->assertTrue($question->is_gradable_response(array('answer' => 'test'))); 00054 } 00055 00056 public function test_grading() { 00057 $question = test_question_maker::make_question('calculated'); 00058 $question->start_attempt(new question_attempt_step(), 1); 00059 $values = $question->vs->get_values(); 00060 00061 $this->assertEqual(array(0, question_state::$gradedwrong), 00062 $question->grade_response(array('answer' => $values['a'] - $values['b']))); 00063 $this->assertEqual(array(1, question_state::$gradedright), 00064 $question->grade_response(array('answer' => $values['a'] + $values['b']))); 00065 } 00066 00067 public function test_get_correct_response() { 00068 $question = test_question_maker::make_question('calculated'); 00069 $question->start_attempt(new question_attempt_step(), 1); 00070 $values = $question->vs->get_values(); 00071 00072 $this->assertEqual(array('answer' => $values['a'] + $values['b']), 00073 $question->get_correct_response()); 00074 } 00075 00076 public function test_get_question_summary() { 00077 $question = test_question_maker::make_question('calculated'); 00078 $question->start_attempt(new question_attempt_step(), 1); 00079 $values = $question->vs->get_values(); 00080 00081 $qsummary = $question->get_question_summary(); 00082 $this->assertEqual('What is ' . $values['a'] . ' + ' . $values['b'] . '?', $qsummary); 00083 } 00084 00085 public function test_summarise_response() { 00086 $question = test_question_maker::make_question('calculated'); 00087 $question->start_attempt(new question_attempt_step(), 1); 00088 $values = $question->vs->get_values(); 00089 00090 $this->assertEqual('3.1', $question->summarise_response(array('answer' => '3.1'))); 00091 } 00092 00093 public function test_classify_response() { 00094 $question = test_question_maker::make_question('calculated'); 00095 $question->start_attempt(new question_attempt_step(), 1); 00096 $values = $question->vs->get_values(); 00097 00098 $this->assertEqual(array( 00099 new question_classified_response(13, $values['a'] + $values['b'], 1.0)), 00100 $question->classify_response(array('answer' => $values['a'] + $values['b']))); 00101 $this->assertEqual(array( 00102 new question_classified_response(14, $values['a'] - $values['b'], 0.0)), 00103 $question->classify_response(array('answer' => $values['a'] - $values['b']))); 00104 $this->assertEqual(array( 00105 new question_classified_response(17, 7 * $values['a'], 0.0)), 00106 $question->classify_response(array('answer' => 7 * $values['a']))); 00107 $this->assertEqual(array( 00108 question_classified_response::no_response()), 00109 $question->classify_response(array('answer' => ''))); 00110 } 00111 00112 public function test_classify_response_no_star() { 00113 $question = test_question_maker::make_question('calculated'); 00114 unset($question->answers[17]); 00115 $question->start_attempt(new question_attempt_step(), 1); 00116 $values = $question->vs->get_values(); 00117 00118 $this->assertEqual(array( 00119 new question_classified_response(13, $values['a'] + $values['b'], 1.0)), 00120 $question->classify_response(array('answer' => $values['a'] + $values['b']))); 00121 $this->assertEqual(array( 00122 new question_classified_response(14, $values['a'] - $values['b'], 0.0)), 00123 $question->classify_response(array('answer' => $values['a'] - $values['b']))); 00124 $this->assertEqual(array( 00125 new question_classified_response(0, 7 * $values['a'], 0.0)), 00126 $question->classify_response(array('answer' => 7 * $values['a']))); 00127 $this->assertEqual(array( 00128 question_classified_response::no_response()), 00129 $question->classify_response(array('answer' => ''))); 00130 } 00131 00132 public function test_get_variants_selection_seed_q_not_synchronised() { 00133 $question = test_question_maker::make_question('calculated'); 00134 $this->assertEqual($question->stamp, $question->get_variants_selection_seed()); 00135 } 00136 00137 public function test_get_variants_selection_seed_q_synchronised_datasets_not() { 00138 $question = test_question_maker::make_question('calculated'); 00139 $question->synchronised = true; 00140 $this->assertEqual($question->stamp, $question->get_variants_selection_seed()); 00141 } 00142 00143 public function test_get_variants_selection_seed_q_synchronised() { 00144 $question = test_question_maker::make_question('calculated'); 00145 $question->synchronised = true; 00146 $question->datasetloader->set_are_synchronised($question->category, true); 00147 $this->assertEqual('category' . $question->category, 00148 $question->get_variants_selection_seed()); 00149 } 00150 }