Skip to content

Commit

Permalink
MDL-20636 truefalse qtype clean up other unit tests to use the new wa…
Browse files Browse the repository at this point in the history
…y of making test tf questions.
  • Loading branch information
timhunt committed May 27, 2011
1 parent 188e174 commit a4c9829
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 48 deletions.
8 changes: 4 additions & 4 deletions question/behaviour/deferredcbm/simpletest/testwalkthrough.php
Expand Up @@ -41,7 +41,7 @@ class qbehaviour_deferredcbm_walkthrough_test extends qbehaviour_walkthrough_tes
public function test_deferred_cbm_truefalse_high_certainty() {

// Create a true-false question with correct answer true.
$tf = test_question_maker::make_a_truefalse_question();
$tf = test_question_maker::make_question('truefalse', 'true');
$this->start_attempt_at_question($tf, 'deferredcbm', 2);

// Verify.
Expand Down Expand Up @@ -116,7 +116,7 @@ public function test_deferred_cbm_truefalse_high_certainty() {
public function test_deferred_cbm_truefalse_low_certainty() {

// Create a true-false question with correct answer true.
$tf = test_question_maker::make_a_truefalse_question();
$tf = test_question_maker::make_question('truefalse', 'true');
$this->start_attempt_at_question($tf, 'deferredcbm', 2);

// Verify.
Expand Down Expand Up @@ -153,7 +153,7 @@ public function test_deferred_cbm_truefalse_low_certainty() {
public function test_deferred_cbm_truefalse_default_certainty() {

// Create a true-false question with correct answer true.
$tf = test_question_maker::make_a_truefalse_question();
$tf = test_question_maker::make_question('truefalse', 'true');
$this->start_attempt_at_question($tf, 'deferredcbm', 2);

// Verify.
Expand Down Expand Up @@ -249,7 +249,7 @@ public function test_deferredcbm_resume_multichoice_single() {
public function test_deferred_cbm_truefalse_no_certainty_feedback_when_not_answered() {

// Create a true-false question with correct answer true.
$tf = test_question_maker::make_a_truefalse_question();
$tf = test_question_maker::make_question('truefalse', 'true');
$this->start_attempt_at_question($tf, 'deferredcbm', 2);

// Verify.
Expand Down
Expand Up @@ -41,7 +41,7 @@ class qbehaviour_deferredfeedback_walkthrough_test extends qbehaviour_walkthroug
public function test_deferredfeedback_feedback_truefalse() {

// Create a true-false question with correct answer true.
$tf = test_question_maker::make_a_truefalse_question();
$tf = test_question_maker::make_question('truefalse', 'true');
$this->start_attempt_at_question($tf, 'deferredfeedback', 2);

// Check the initial state.
Expand Down
Expand Up @@ -268,7 +268,7 @@ public function test_immediatecbm_feedback_multichoice_wrong_on_finish() {
public function test_immediatecbm_cbm_truefalse_no_certainty_feedback_when_not_answered() {

// Create a true-false question with correct answer true.
$tf = test_question_maker::make_a_truefalse_question();
$tf = test_question_maker::make_question('truefalse', 'true');
$this->start_attempt_at_question($tf, 'deferredcbm', 2);

// Verify.
Expand Down
Expand Up @@ -108,7 +108,7 @@ public function test_manual_graded_essay() {
public function test_manual_graded_truefalse() {

// Create a true-false question with correct answer true.
$tf = test_question_maker::make_a_truefalse_question();
$tf = test_question_maker::make_question('truefalse', 'true');
$this->start_attempt_at_question($tf, 'manualgraded', 2);

// Check the initial state.
Expand Down
Expand Up @@ -39,21 +39,21 @@
*/
class qbehaviour_missing_test extends UnitTestCase {
public function test_missing_cannot_start() {
$qa = new question_attempt(test_question_maker::make_a_truefalse_question(), 0);
$qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0);
$behaviour = new qbehaviour_missing($qa, 'deferredfeedback');
$this->expectException();
$behaviour->init_first_step(new question_attempt_step(array()), 1);
}

public function test_missing_cannot_process() {
$qa = new question_attempt(test_question_maker::make_a_truefalse_question(), 0);
$qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0);
$behaviour = new qbehaviour_missing($qa, 'deferredfeedback');
$this->expectException();
$behaviour->process_action(new question_attempt_pending_step(array()));
}

public function test_missing_cannot_get_min_grade() {
$qa = new question_attempt(test_question_maker::make_a_truefalse_question(), 0);
$qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0);
$behaviour = new qbehaviour_missing($qa, 'deferredfeedback');
$this->expectException();
$behaviour->get_min_fraction();
Expand All @@ -74,7 +74,7 @@ public function test_render_missing() {
1256233790, 2, 1, 'complete', 0.50, 1256233705, 1, 'choice0', '1'),
));

$question = test_question_maker::make_a_truefalse_question();
$question = test_question_maker::make_question('truefalse', 'true');
$question->id = -1;

question_bank::start_unit_test();
Expand Down
25 changes: 0 additions & 25 deletions question/engine/simpletest/helpers.php
Expand Up @@ -164,31 +164,6 @@ public static function make_question($qtype, $which = null) {
return $helper->$method();
}

/**
* Makes a truefalse question with correct answer true, defaultmark 1.
* @return qtype_truefalse_question
*/
public static function make_a_truefalse_question() {
question_bank::load_question_definition_classes('truefalse');
$tf = new qtype_truefalse_question();
self::initialise_a_question($tf);
$tf->name = 'True/false question';
$tf->questiontext = 'The answer is true.';
$tf->generalfeedback = 'You should have selected true.';
$tf->penalty = 1;
$tf->qtype = question_bank::get_qtype('truefalse');

$tf->rightanswer = true;
$tf->truefeedback = 'This is the right answer.';
$tf->falsefeedback = 'This is the wrong answer.';
$tf->truefeedbackformat = FORMAT_HTML;
$tf->falsefeedbackformat = FORMAT_HTML;
$tf->trueanswerid = 13;
$tf->falseanswerid = 14;

return $tf;
}

/**
* Makes a multichoice question with choices 'A', 'B' and 'C' shuffled. 'A'
* is correct, defaultmark 1.
Expand Down
2 changes: 1 addition & 1 deletion question/engine/simpletest/testquestionattempt.php
Expand Up @@ -277,7 +277,7 @@ public function test_load() {
array(8, 1, 123, 1, 1, 'deferredfeedback', -1, 1, 2.0000000, 0.0000000, 0, '', '', '', 1256233790, 6, 5, 'mangrpartial', 0.5000000, 1256233790, 1, '-maxmark', '2'),
));

$question = test_question_maker::make_a_truefalse_question();
$question = test_question_maker::make_question('truefalse', 'true');
$question->id = -1;

question_bank::start_unit_test();
Expand Down
8 changes: 4 additions & 4 deletions question/engine/simpletest/testquestionusagebyactivity.php
Expand Up @@ -72,7 +72,7 @@ public function test_create_usage_and_add_question() {
$context = get_context_instance(CONTEXT_SYSTEM);
$quba = question_engine::make_questions_usage_by_activity('unit_test', $context);
$quba->set_preferred_behaviour('deferredfeedback');
$tf = test_question_maker::make_a_truefalse_question();
$tf = test_question_maker::make_question('truefalse', 'true');
$slot = $quba->add_question($tf);

// Verify.
Expand All @@ -88,7 +88,7 @@ public function test_get_question() {
$quba = question_engine::make_questions_usage_by_activity('unit_test',
get_context_instance(CONTEXT_SYSTEM));
$quba->set_preferred_behaviour('deferredfeedback');
$tf = test_question_maker::make_a_truefalse_question();
$tf = test_question_maker::make_question('truefalse', 'true');
$slot = $quba->add_question($tf);

// Exercise SUT and verify.
Expand All @@ -100,7 +100,7 @@ public function test_get_question() {

public function test_extract_responses() {
// Start a deferred feedback attempt with CBM and add the question to it.
$tf = test_question_maker::make_a_truefalse_question();
$tf = test_question_maker::make_question('truefalse', 'true');
$quba = question_engine::make_questions_usage_by_activity('unit_test',
get_context_instance(CONTEXT_SYSTEM));
$quba->set_preferred_behaviour('deferredcbm');
Expand All @@ -126,7 +126,7 @@ public function test_extract_responses() {

public function test_access_out_of_sequence_throws_exception() {
// Start a deferred feedback attempt with CBM and add the question to it.
$tf = test_question_maker::make_a_truefalse_question();
$tf = test_question_maker::make_question('truefalse', 'true');
$quba = question_engine::make_questions_usage_by_activity('unit_test',
get_context_instance(CONTEXT_SYSTEM));
$quba->set_preferred_behaviour('deferredcbm');
Expand Down
14 changes: 7 additions & 7 deletions question/type/truefalse/simpletest/testquestion.php
Expand Up @@ -37,23 +37,23 @@
*/
class qtype_truefalse_question_test extends UnitTestCase {
public function test_is_complete_response() {
$question = test_question_maker::make_a_truefalse_question();
$question = test_question_maker::make_question('truefalse', 'true');

$this->assertFalse($question->is_complete_response(array()));
$this->assertTrue($question->is_complete_response(array('answer' => 0)));
$this->assertTrue($question->is_complete_response(array('answer' => 1)));
}

public function test_is_gradable_response() {
$question = test_question_maker::make_a_truefalse_question();
$question = test_question_maker::make_question('truefalse', 'true');

$this->assertFalse($question->is_gradable_response(array()));
$this->assertTrue($question->is_gradable_response(array('answer' => 0)));
$this->assertTrue($question->is_gradable_response(array('answer' => 1)));
}

public function test_grading() {
$question = test_question_maker::make_a_truefalse_question();
$question = test_question_maker::make_question('truefalse', 'true');

$this->assertEqual(array(0, question_state::$gradedwrong),
$question->grade_response(array('answer' => 0)));
Expand All @@ -62,7 +62,7 @@ public function test_grading() {
}

public function test_get_correct_response() {
$question = test_question_maker::make_a_truefalse_question();
$question = test_question_maker::make_question('truefalse', 'true');

// true
$this->assertIdentical(array('answer' => 1),
Expand All @@ -75,13 +75,13 @@ public function test_get_correct_response() {
}

public function test_get_question_summary() {
$tf = test_question_maker::make_a_truefalse_question();
$tf = test_question_maker::make_question('truefalse', 'true');
$qsummary = $tf->get_question_summary();
$this->assertEqual('The answer is true.', $qsummary);
}

public function test_summarise_response() {
$tf = test_question_maker::make_a_truefalse_question();
$tf = test_question_maker::make_question('truefalse', 'true');

$this->assertEqual(get_string('false', 'qtype_truefalse'),
$tf->summarise_response(array('answer' => '0')));
Expand All @@ -91,7 +91,7 @@ public function test_summarise_response() {
}

public function test_classify_response() {
$tf = test_question_maker::make_a_truefalse_question();
$tf = test_question_maker::make_question('truefalse', 'true');
$tf->start_attempt(new question_attempt_step(), 1);

$this->assertEqual(array(
Expand Down

0 comments on commit a4c9829

Please sign in to comment.