~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to question/type/calculated/tests/question_test.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
    }
68
68
 
69
69
    public function test_get_correct_response() {
 
70
        // Testing with 3.0 + 0.1416.
 
71
        $question = test_question_maker::make_question('calculated');
 
72
        $question->start_attempt(new question_attempt_step(), 3);
 
73
        $values = $question->vs->get_values();
 
74
        $this->assertSame(array('answer' => '3.01' ), $question->get_correct_response());
 
75
        foreach ($question->answers as $answer) {
 
76
            $answer->correctanswerlength = 2;
 
77
            $answer->correctanswerformat = 2;
 
78
        }
 
79
        $this->assertSame(array('answer' => '3.0' ), $question->get_correct_response());
 
80
 
 
81
        // Testing with 1.0 + 5.0.
70
82
        $question = test_question_maker::make_question('calculated');
71
83
        $question->start_attempt(new question_attempt_step(), 1);
72
84
        $values = $question->vs->get_values();
 
85
        $this->assertSame(array('answer' => '6.00' ), $question->get_correct_response());
73
86
 
74
 
        $this->assertEquals(array('answer' => $values['a'] + $values['b']),
 
87
        foreach ($question->answers as $answer) {
 
88
            $answer->correctanswerlength = 2;
 
89
            $answer->correctanswerformat = 2;
 
90
        }
 
91
        $this->assertSame(array('answer' => '6.0' ),
75
92
                $question->get_correct_response());
 
93
        // Testing with 31.0 + 0.01416 .
 
94
        $question = test_question_maker::make_question('calculated');
 
95
        $question->start_attempt(new question_attempt_step(), 4);
 
96
        $values = $question->vs->get_values();
 
97
        $this->assertSame(array('answer' => '31.01' ), $question->get_correct_response());
 
98
 
 
99
        foreach ($question->answers as $answer) {
 
100
            $answer->correctanswerlength = 3;
 
101
            $answer->correctanswerformat = 2;
 
102
        }
 
103
        $this->assertSame(array('answer' => '31.0' ), $question->get_correct_response());
 
104
 
76
105
    }
77
106
 
78
107
    public function test_get_question_summary() {