public function test_get_possible_responses()
 {
     $q = new stdClass();
     $q->id = 1;
     $q->options->trueanswer = 1;
     $q->options->falseanswer = 2;
     $q->options->answers[1] = (object) array('fraction' => 1);
     $q->options->answers[2] = (object) array('fraction' => 0);
     $this->assertEqual(array($q->id => array(0 => new question_possible_response(get_string('false', 'qtype_truefalse'), 0), 1 => new question_possible_response(get_string('true', 'qtype_truefalse'), 1), null => question_possible_response::no_response())), $this->qtype->get_possible_responses($q));
 }
Esempio n. 2
0
    public function get_possible_responses($questiondata) {
        $responses = array();

        $unit = $this->get_default_numerical_unit($questiondata);

        $starfound = false;
        foreach ($questiondata->options->answers as $aid => $answer) {
            $responseclass = $answer->answer;

            if ($responseclass === '*') {
                $starfound = true;
            } else {
                $responseclass = $this->add_unit($questiondata, $responseclass, $unit);

                $ans = new qtype_numerical_answer($answer->id, $answer->answer, $answer->fraction,
                        $answer->feedback, $answer->feedbackformat, $answer->tolerance);
                list($min, $max) = $ans->get_tolerance_interval();
                $responseclass .= " ($min..$max)";
            }

            $responses[$aid] = new question_possible_response($responseclass,
                    $answer->fraction);
        }

        if (!$starfound) {
            $responses[0] = new question_possible_response(
                    get_string('didnotmatchanyanswer', 'question'), 0);
        }

        $responses[null] = question_possible_response::no_response();

        return array($questiondata->id => $responses);
    }
    public function test_get_possible_responses_no_star() {
        $q = test_question_maker::get_question_data('calculated');
        unset($q->options->answers[17]);

        $this->assertEqual(array(
            $q->id => array(
                13 => new question_possible_response(
                        $this->get_possible_response('{a} + {b}', 0.001, 'nominal'), 1),
                14 => new question_possible_response(
                        $this->get_possible_response('{a} - {b}', 0.001, 'nominal'), 0),
                0  => new question_possible_response(
                        get_string('didnotmatchanyanswer', 'question'), 0),
                null => question_possible_response::no_response()
            ),
        ), $this->qtype->get_possible_responses($q));
    }
 public function test_get_possible_responses_no_star()
 {
     $q = test_question_maker::get_question_data('shortanswer', 'frogonly');
     $this->assertEquals(array($q->id => array(13 => new question_possible_response('frog', 1), 0 => new question_possible_response(get_string('didnotmatchanyanswer', 'question'), 0), null => question_possible_response::no_response())), $this->qtype->get_possible_responses($q));
 }
Esempio n. 5
0
    public function get_possible_responses($questiondata) {
        $responses = array();

        $unit = $this->get_default_numerical_unit($questiondata);

        foreach ($questiondata->options->answers as $aid => $answer) {
            $responseclass = $answer->answer;

            if ($responseclass != '*') {
                $responseclass = $this->add_unit($questiondata, $responseclass, $unit);

                $ans = new qtype_numerical_answer($answer->id, $answer->answer, $answer->fraction,
                        $answer->feedback, $answer->feedbackformat, $answer->tolerance);
                list($min, $max) = $ans->get_tolerance_interval();
                $responseclass .= " ($min..$max)";
            }

            $responses[$aid] = new question_possible_response($responseclass,
                    $answer->fraction);
        }
        $responses[null] = question_possible_response::no_response();

        return array($questiondata->id => $responses);
    }
Esempio n. 6
0
 public function get_possible_responses($questiondata)
 {
     $responses = array();
     $starfound = false;
     foreach ($questiondata->options->answers as $aid => $answer) {
         $responses[$aid] = new question_possible_response($answer->answer, $answer->fraction);
         if ($answer->answer === '*') {
             $starfound = true;
         }
     }
     if (!$starfound) {
         $responses[0] = new question_possible_response(get_string('didnotmatchanyanswer', 'question'), 0);
     }
     $responses[null] = question_possible_response::no_response();
     return array($questiondata->id => $responses);
 }
 public function test_get_possible_responses()
 {
     $q = $this->get_test_question_data();
     $this->assertEquals(array(14 => array(14 => new question_possible_response('frog: amphibian', 1 / 3), 15 => new question_possible_response('frog: mammal', 0), 17 => new question_possible_response('frog: insect', 0), null => question_possible_response::no_response()), 15 => array(14 => new question_possible_response('cat: amphibian', 0), 15 => new question_possible_response('cat: mammal', 1 / 3), 17 => new question_possible_response('cat: insect', 0), null => question_possible_response::no_response()), 16 => array(14 => new question_possible_response('newt: amphibian', 1 / 3), 15 => new question_possible_response('newt: mammal', 0), 17 => new question_possible_response('newt: insect', 0), null => question_possible_response::no_response())), $this->qtype->get_possible_responses($q));
 }
Esempio n. 8
0
    public function get_possible_responses($questiondata) {
        if ($questiondata->options->single) {
            $responses = array();

            foreach ($questiondata->options->answers as $aid => $answer) {
                $responses[$aid] = new question_possible_response($answer->answer,
                        $answer->fraction);
            }

            $responses[null] = question_possible_response::no_response();
            return array($questiondata->id => $responses);
        } else {
            $parts = array();

            foreach ($questiondata->options->answers as $aid => $answer) {
                $parts[$aid] = array($aid =>
                        new question_possible_response($answer->answer, $answer->fraction));
            }

            return $parts;
        }
    }
 public function get_possible_responses($questiondata)
 {
     $responses = array();
     $question = $this->make_question($questiondata);
     foreach ($question->correctresponse as $position => $answerid) {
         $responses[] = $position . ': ' . $question->answers[$answerid]->answer;
     }
     $responses = array(0 => question_possible_response::no_response(), 1 => implode(', ', $responses));
     return;
 }
Esempio n. 10
0
    public function test_get_possible_responses_single() {
        $q = $this->get_test_question_data();
        $responses = $this->qtype->get_possible_responses($q);

        $this->assertEquals(array(
            $q->id => array(
                1 => new question_possible_response('frog', 1),
                2 => new question_possible_response('toad', 0),
                null => question_possible_response::no_response(),
            )), $this->qtype->get_possible_responses($q));
    }
Esempio n. 11
0
 public function get_possible_responses($questiondata)
 {
     return array($questiondata->id => array(0 => new question_possible_response(get_string('false', 'qtype_truefalse'), $questiondata->options->answers[$questiondata->options->falseanswer]->fraction), 1 => new question_possible_response(get_string('true', 'qtype_truefalse'), $questiondata->options->answers[$questiondata->options->trueanswer]->fraction), null => question_possible_response::no_response()));
 }
 public function test_get_possible_responses()
 {
     $q = $this->get_test_question_data();
     $this->assertEquals(array(1 => array(1 => new question_possible_response('quick', 1 / 3), 2 => new question_possible_response('slow', 0), null => question_possible_response::no_response()), 2 => array(1 => new question_possible_response('fox', 1 / 3), 2 => new question_possible_response('dog', 0), null => question_possible_response::no_response()), 3 => array(1 => new question_possible_response('lazy', 1 / 3), 2 => new question_possible_response('assiduous', 0), null => question_possible_response::no_response())), $this->qtype->get_possible_responses($q));
 }
 public function get_possible_responses($questiondata)
 {
     $question = $this->make_question($questiondata);
     $parts = array();
     foreach ($question->places as $place => $group) {
         $choices = array();
         foreach ($question->choices[$group] as $i => $choice) {
             $choices[$i] = new question_possible_response(html_to_text($choice->text, 0, false), ($question->rightchoices[$place] == $i) / count($question->places));
         }
         $choices[null] = question_possible_response::no_response();
         $parts[$place] = $choices;
     }
     return $parts;
 }
Esempio n. 14
0
    public function test_get_possible_responses_no_star() {
        $q = $this->get_test_question_data();
        unset($q->options->answers[14]);

        $this->assertEqual(array(
            $q->id => array(
                13 => new question_possible_response('42 m (41.5..42.5)', 1),
                0 => new question_possible_response(
                        get_string('didnotmatchanyanswer', 'question'), 0),
                null => question_possible_response::no_response()
            ),
        ), $this->qtype->get_possible_responses($q));
    }
Esempio n. 15
0
    public function get_possible_responses($questiondata) {
        if ($questiondata->options->single) {
            $responses = array();

            foreach ($questiondata->options->answers as $aid => $answer) {
                $responses[$aid] = new question_possible_response(html_to_text(format_text(
                        $answer->answer, $answer->answerformat, array('noclean' => true)),
                        0, false), $answer->fraction);
            }

            $responses[null] = question_possible_response::no_response();
            return array($questiondata->id => $responses);
        } else {
            $parts = array();

            foreach ($questiondata->options->answers as $aid => $answer) {
                $parts[$aid] = array($aid =>
                        new question_possible_response(html_to_text(format_text(
                        $answer->answer, $answer->answerformat, array('noclean' => true)),
                        0, false), $answer->fraction));
            }

            return $parts;
        }
    }
 public function test_get_possible_responses()
 {
     $q = $this->get_test_question_data();
     $this->assertEqual(array($q->id => array(13 => new question_possible_response('42 m (41.5..42.5)', 1), 14 => new question_possible_response('*', 0.1), null => question_possible_response::no_response())), $this->qtype->get_possible_responses($q));
 }
Esempio n. 17
0
 public function get_possible_responses($questiondata)
 {
     $parts = array();
     $q = $this->make_question($questiondata);
     foreach ($q->prts as $index => $prt) {
         foreach ($prt->get_nodes_summary() as $nodeid => $choices) {
             $parts[$index . '-' . $nodeid] = array($choices->falsenote => new question_possible_response($choices->falsenote, $choices->falsescore * $prt->get_value()), $choices->truenote => new question_possible_response($choices->truenote, $choices->truescore * $prt->get_value()), null => question_possible_response::no_response());
         }
     }
     return $parts;
 }
Esempio n. 18
0
    public function get_possible_responses($questiondata) {
        $subqs = array();

        $q = $this->make_question($questiondata);

        foreach ($q->stems as $stemid => $stem) {

            $responses = array();
            foreach ($q->choices as $choiceid => $choice) {
                $responses[$choiceid] = new question_possible_response(
                        $q->html_to_text($stem, $q->stemformat[$stemid]) . ': ' . $choice,
                        ($choiceid == $q->right[$stemid]) / count($q->stems));
            }
            $responses[null] = question_possible_response::no_response();

            $subqs[$stemid] = $responses;
        }

        return $subqs;
    }
Esempio n. 19
0
 public function get_possible_responses($questiondata)
 {
     $question = $this->make_question($questiondata);
     $parts = array();
     foreach ($question->places as $placeno => $place) {
         $choices = array();
         foreach ($question->choices[$place->group] as $i => $choice) {
             $correct = $question->rightchoices[$placeno] == $i;
             $choices[$choice->no] = new question_possible_response($choice->summarise(), $correct ? 1 : 0);
         }
         $choices[null] = question_possible_response::no_response();
         $parts[$placeno] = $choices;
     }
     return $parts;
 }
Esempio n. 20
0
 public function get_possible_responses($questiondata)
 {
     $responses = array();
     $virtualqtype = $this->get_virtual_qtype();
     $unit = $virtualqtype->get_default_numerical_unit($questiondata);
     $tolerancetypes = $this->tolerance_types();
     $starfound = false;
     foreach ($questiondata->options->answers as $aid => $answer) {
         $responseclass = $answer->answer;
         if ($responseclass === '*') {
             $starfound = true;
         } else {
             $a = new stdClass();
             $a->answer = $virtualqtype->add_unit($questiondata, $responseclass, $unit);
             $a->tolerance = $answer->tolerance;
             $a->tolerancetype = $tolerancetypes[$answer->tolerancetype];
             $responseclass = get_string('answerwithtolerance', 'qtype_calculated', $a);
         }
         $responses[$aid] = new question_possible_response($responseclass, $answer->fraction);
     }
     if (!$starfound) {
         $responses[0] = new question_possible_response(get_string('didnotmatchanyanswer', 'question'), 0);
     }
     $responses[null] = question_possible_response::no_response();
     return array($questiondata->id => $responses);
 }
 public function test_get_possible_responses_test3()
 {
     $qdata = test_question_maker::get_question_data('stack', 'test3');
     $expected = array('odd-0' => array('odd-0-0' => new question_possible_response('odd-0-0', 0), 'odd-0-1' => new question_possible_response('odd-0-1', 0.25), null => question_possible_response::no_response()), 'even-0' => array('even-0-0' => new question_possible_response('even-0-0', 0), 'even-0-1' => new question_possible_response('even-0-1', 0.25), null => question_possible_response::no_response()), 'oddeven-0' => array('oddeven-0-0' => new question_possible_response('oddeven-0-0', 0), 'oddeven-0-1' => new question_possible_response('oddeven-0-1', 0.125), null => question_possible_response::no_response()), 'oddeven-1' => array('oddeven-1-0' => new question_possible_response('oddeven-1-0', 0), 'oddeven-1-1' => new question_possible_response('oddeven-1-1', 0.125), null => question_possible_response::no_response()), 'unique-0' => array('unique-0-0' => new question_possible_response('unique-0-0', 0), 'unique-0-1' => new question_possible_response('unique-0-1', 0.25), null => question_possible_response::no_response()));
     $this->assertEquals($expected, $this->qtype->get_possible_responses($qdata));
 }