*
* @package qtype
* @subpackage gapselect
- * @copyright 2011 The Open University
+ * @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
+global $CFG;
-require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
-require_once($CFG->dirroot . '/question/type/gapselect/simpletest/helper.php');
+require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
+require_once($CFG->dirroot . '/question/type/gapselect/tests/helper.php');
/**
* Unit tests for the select missing words question definition class.
*
- * @copyright 2009 The Open University
+ * @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @group qtype_gapselect
*/
-class qtype_gapselect_question_test extends UnitTestCase {
+class qtype_gapselect_question_test extends basic_testcase {
public function test_get_question_summary() {
$gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
- $this->assertEqual('The [[1]] brown [[2]] jumped over the [[3]] dog.; ' .
+ $this->assertEquals('The [[1]] brown [[2]] jumped over the [[3]] dog.; ' .
'[[1]] -> {quick / slow}; [[2]] -> {fox / dog}; [[3]] -> {lazy / assiduous}',
$gapselect->get_question_summary());
}
public function test_get_question_summary_maths() {
$gapselect = qtype_gapselect_test_helper::make_a_maths_gapselect_question();
- $this->assertEqual('Fill in the operators to make this equation work: ' .
+ $this->assertEquals('Fill in the operators to make this equation work: ' .
'7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3; [[1]] -> {+ / - / * / /}',
$gapselect->get_question_summary());
}
$gapselect->shufflechoices = false;
$gapselect->start_attempt(new question_attempt_step(), 1);
- $this->assertEqual('{quick} {fox} {lazy}',
+ $this->assertEquals('{quick} {fox} {lazy}',
$gapselect->summarise_response(array('p1' => '1', 'p2' => '1', 'p3' => '1')));
}
$gapselect->shufflechoices = false;
$gapselect->start_attempt(new question_attempt_step(), 1);
- $this->assertEqual('{+} {-} {+} {-}', $gapselect->summarise_response(
+ $this->assertEquals('{+} {-} {+} {-}', $gapselect->summarise_response(
array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
}
public function test_get_random_guess_score() {
$gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
- $this->assertEqual(0.5, $gapselect->get_random_guess_score());
+ $this->assertEquals(0.5, $gapselect->get_random_guess_score());
}
public function test_get_random_guess_score_maths() {
$gapselect = qtype_gapselect_test_helper::make_a_maths_gapselect_question();
- $this->assertEqual(0.25, $gapselect->get_random_guess_score());
+ $this->assertEquals(0.25, $gapselect->get_random_guess_score());
}
public function test_get_right_choice_for() {
$gapselect->shufflechoices = false;
$gapselect->start_attempt(new question_attempt_step(), 1);
- $this->assertEqual(1, $gapselect->get_right_choice_for(1));
- $this->assertEqual(1, $gapselect->get_right_choice_for(2));
+ $this->assertEquals(1, $gapselect->get_right_choice_for(1));
+ $this->assertEquals(1, $gapselect->get_right_choice_for(2));
}
public function test_get_right_choice_for_maths() {
$gapselect->shufflechoices = false;
$gapselect->start_attempt(new question_attempt_step(), 1);
- $this->assertEqual(1, $gapselect->get_right_choice_for(1));
- $this->assertEqual(2, $gapselect->get_right_choice_for(2));
+ $this->assertEquals(1, $gapselect->get_right_choice_for(1));
+ $this->assertEquals(2, $gapselect->get_right_choice_for(2));
}
public function test_clear_wrong_from_response() {
$gapselect->start_attempt(new question_attempt_step(), 1);
$initialresponse = array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1');
- $this->assertEqual(array('p1' => '1', 'p2' => '0', 'p3' => '1', 'p4' => '0'),
+ $this->assertEquals(array('p1' => '1', 'p2' => '0', 'p3' => '1', 'p4' => '0'),
$gapselect->clear_wrong_from_response($initialresponse));
}
$gapselect->shufflechoices = false;
$gapselect->start_attempt(new question_attempt_step(), 1);
- $this->assertEqual(array(2, 3),
+ $this->assertEquals(array(2, 3),
$gapselect->get_num_parts_right(array('p1' => '1', 'p2' => '1', 'p3' => '2')));
- $this->assertEqual(array(3, 3),
+ $this->assertEquals(array(3, 3),
$gapselect->get_num_parts_right(array('p1' => '1', 'p2' => '1', 'p3' => '1')));
}
$gapselect->shufflechoices = false;
$gapselect->start_attempt(new question_attempt_step(), 1);
- $this->assertEqual(array(2, 4), $gapselect->get_num_parts_right(
+ $this->assertEquals(array(2, 4), $gapselect->get_num_parts_right(
array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
}
$gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
$gapselect->start_attempt(new question_attempt_step(), 1);
- $this->assertEqual(array('p1' => PARAM_INT, 'p2' => PARAM_INT, 'p3' => PARAM_INT),
+ $this->assertEquals(array('p1' => PARAM_INT, 'p2' => PARAM_INT, 'p3' => PARAM_INT),
$gapselect->get_expected_data());
}
$gapselect->shufflechoices = false;
$gapselect->start_attempt(new question_attempt_step(), 1);
- $this->assertEqual(array('p1' => '1', 'p2' => '1', 'p3' => '1'),
+ $this->assertEquals(array('p1' => '1', 'p2' => '1', 'p3' => '1'),
$gapselect->get_correct_response());
}
$gapselect->shufflechoices = false;
$gapselect->start_attempt(new question_attempt_step(), 1);
- $this->assertEqual(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2'),
+ $this->assertEquals(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2'),
$gapselect->get_correct_response());
}
$gapselect->shufflechoices = false;
$gapselect->start_attempt(new question_attempt_step(), 1);
- $this->assertEqual(array(1, question_state::$gradedright),
+ $this->assertEquals(array(1, question_state::$gradedright),
$gapselect->grade_response(array('p1' => '1', 'p2' => '1', 'p3' => '1')));
- $this->assertEqual(array(1/3, question_state::$gradedpartial),
+ $this->assertEquals(array(1/3, question_state::$gradedpartial),
$gapselect->grade_response(array('p1' => '1')));
- $this->assertEqual(array(0, question_state::$gradedwrong),
+ $this->assertEquals(array(0, question_state::$gradedwrong),
$gapselect->grade_response(array('p1' => '2', 'p2' => '2', 'p3' => '2')));
}
$gapselect->shufflechoices = false;
$gapselect->start_attempt(new question_attempt_step(), 1);
- $this->assertEqual(array(1, question_state::$gradedright), $gapselect->grade_response(
+ $this->assertEquals(array(1, question_state::$gradedright), $gapselect->grade_response(
array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
- $this->assertEqual(array(0.5, question_state::$gradedpartial), $gapselect->grade_response(
+ $this->assertEquals(array(0.5, question_state::$gradedpartial), $gapselect->grade_response(
array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
- $this->assertEqual(array(0, question_state::$gradedwrong), $gapselect->grade_response(
+ $this->assertEquals(array(0, question_state::$gradedwrong), $gapselect->grade_response(
array('p1' => '0', 'p2' => '1', 'p3' => '2', 'p4' => '1')));
}
$gapselect->shufflechoices = false;
$gapselect->start_attempt(new question_attempt_step(), 1);
- $this->assertEqual(array(
+ $this->assertEquals(array(
1 => new question_classified_response(1, 'quick', 1/3),
2 => new question_classified_response(2, 'dog', 0),
3 => new question_classified_response(1, 'lazy', 1/3),
), $gapselect->classify_response(array('p1' => '1', 'p2' => '2', 'p3' => '1')));
- $this->assertEqual(array(
+ $this->assertEquals(array(
1 => question_classified_response::no_response(),
2 => new question_classified_response(1, 'fox', 1/3),
3 => new question_classified_response(2, 'assiduous', 0),
*
* @package qtype
* @subpackage gapselect
- * @copyright 2011 The Open University
+ * @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
+global $CFG;
-require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
-require_once($CFG->dirroot . '/question/type/gapselect/simpletest/helper.php');
+require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
+require_once($CFG->dirroot . '/question/type/gapselect/tests/helper.php');
/**
* Unit tests for the select missing words question definition class.
*
- * @copyright 2011 The Open University
+ * @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @group qtype_gapselect
*/
-class qtype_gapselect_test extends UnitTestCase {
+class qtype_gapselect_test extends question_testcase {
/** @var qtype_gapselect instance of the question type class to test. */
protected $qtype;
- public function setUp() {
+ protected function setUp() {
$this->qtype = question_bank::get_qtype('gapselect');;
}
- public function tearDown() {
+ protected function tearDown() {
$this->qtype = null;
}
public function assert_same_xml($expectedxml, $xml) {
- $this->assertEqual(str_replace("\r\n", "\n", $expectedxml),
+ $this->assertEquals(str_replace("\r\n", "\n", $expectedxml),
str_replace("\r\n", "\n", $xml));
}
$gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.';
$gapselect->qtype = 'gapselect';
+ $gapselect->options = new stdClass();
$gapselect->options->shuffleanswers = true;
test_question_maker::set_standard_combined_feedback_fields($gapselect->options);
}
public function test_name() {
- $this->assertEqual($this->qtype->name(), 'gapselect');
+ $this->assertEquals($this->qtype->name(), 'gapselect');
}
public function test_can_analyse_responses() {
$q = $this->qtype->make_question($qdata);
- $this->assertEqual($expected, $q);
+ $this->assertEquals($expected, $q);
}
public function test_get_random_guess_score() {
$q = $this->get_test_question_data();
- $this->assertWithinMargin(0.5, $this->qtype->get_random_guess_score($q), 0.0000001);
+ $this->assertEquals(0.5, $this->qtype->get_random_guess_score($q), '', 0.0000001);
}
public function test_get_possible_responses() {
$q = $this->get_test_question_data();
- $this->assertEqual(array(
+ $this->assertEquals(array(
1 => array(
1 => new question_possible_response('quick', 1/3),
2 => new question_possible_response('slow', 0),
'format' => FORMAT_MOODLE, 'files' => array()));
$expectedq->hintshownumcorrect = array(true, true);
$expectedq->hintclearwrong = array(false, true);
- $this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
- $this->assertEqual($expectedq->hint, $q->hint);
+ $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
+ $this->assertEquals($expectedq->hint, $q->hint);
}
public function test_xml_export() {
$qdata->penalty = 0.3333333;
$qdata->hidden = 0;
+ $qdata->options = new stdClass();
$qdata->options->shuffleanswers = 1;
$qdata->options->correctfeedback = '<p>Your answer is correct.</p>';
$qdata->options->correctfeedbackformat = FORMAT_MOODLE;