Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 53... Línea 53...
53
 
53
 
54
    protected function tearDown(): void {
54
    protected function tearDown(): void {
55
        $this->qa = null;
55
        $this->qa = null;
Línea 56... Línea 56...
56
    }
56
    }
57
 
57
 
58
    public function test_get_step_before_start() {
58
    public function test_get_step_before_start(): void {
59
        $this->expectException(\moodle_exception::class);
59
        $this->expectException(\moodle_exception::class);
Línea 60... Línea 60...
60
        $step = $this->qa->get_step(-1);
60
        $step = $this->qa->get_step(-1);
61
    }
61
    }
62
 
62
 
63
    public function test_get_step_at_start() {
63
    public function test_get_step_at_start(): void {
Línea 64... Línea 64...
64
        $step = $this->qa->get_step(0);
64
        $step = $this->qa->get_step(0);
65
        $this->assertEquals(0, $step->get_qt_var('i'));
65
        $this->assertEquals(0, $step->get_qt_var('i'));
66
    }
66
    }
67
 
67
 
Línea 68... Línea 68...
68
    public function test_get_step_at_end() {
68
    public function test_get_step_at_end(): void {
69
        $step = $this->qa->get_step(2);
69
        $step = $this->qa->get_step(2);
70
        $this->assertEquals(2, $step->get_qt_var('i'));
70
        $this->assertEquals(2, $step->get_qt_var('i'));
71
    }
71
    }
Línea 72... Línea 72...
72
 
72
 
73
    public function test_get_step_past_end() {
73
    public function test_get_step_past_end(): void {
74
        $this->expectException(\moodle_exception::class);
74
        $this->expectException(\moodle_exception::class);
Línea 75... Línea 75...
75
        $step = $this->qa->get_step(3);
75
        $step = $this->qa->get_step(3);
76
    }
76
    }
77
 
77
 
78
    public function test_get_num_steps() {
78
    public function test_get_num_steps(): void {
Línea 79... Línea 79...
79
        $this->assertEquals(3, $this->qa->get_num_steps());
79
        $this->assertEquals(3, $this->qa->get_num_steps());
80
    }
80
    }
81
 
81
 
Línea 82... Línea 82...
82
    public function test_get_last_step() {
82
    public function test_get_last_step(): void {
83
        $step = $this->qa->get_last_step();
83
        $step = $this->qa->get_last_step();
84
        $this->assertEquals(2, $step->get_qt_var('i'));
84
        $this->assertEquals(2, $step->get_qt_var('i'));
85
    }
85
    }
Línea 86... Línea 86...
86
 
86
 
87
    public function test_get_last_qt_var_there1() {
87
    public function test_get_last_qt_var_there1(): void {
88
        $this->assertEquals(2, $this->qa->get_last_qt_var('i'));
88
        $this->assertEquals(2, $this->qa->get_last_qt_var('i'));
Línea 89... Línea 89...
89
    }
89
    }
90
 
90
 
91
    public function test_get_last_qt_var_there2() {
91
    public function test_get_last_qt_var_there2(): void {
Línea 92... Línea 92...
92
        $this->qa->get_step(0)->set_qt_var('_x', 'a value');
92
        $this->qa->get_step(0)->set_qt_var('_x', 'a value');
93
        $this->assertEquals('a value', $this->qa->get_last_qt_var('_x'));
93
        $this->assertEquals('a value', $this->qa->get_last_qt_var('_x'));
94
    }
94
    }
Línea 95... Línea 95...
95
 
95
 
96
    public function test_get_last_qt_var_missing() {
96
    public function test_get_last_qt_var_missing(): void {
97
        $this->assertNull($this->qa->get_last_qt_var('notthere'));
97
        $this->assertNull($this->qa->get_last_qt_var('notthere'));
98
    }
98
    }
Línea 99... Línea 99...
99
 
99
 
100
    public function test_get_last_qt_var_missing_default() {
100
    public function test_get_last_qt_var_missing_default(): void {
101
        $this->assertEquals('default', $this->qa->get_last_qt_var('notthere', 'default'));
101
        $this->assertEquals('default', $this->qa->get_last_qt_var('notthere', 'default'));
102
    }
102
    }
103
 
103
 
Línea 104... Línea 104...
104
    public function test_get_last_behaviour_var_missing() {
104
    public function test_get_last_behaviour_var_missing(): void {
105
        $this->assertNull($this->qa->get_last_qt_var('notthere'));
105
        $this->assertNull($this->qa->get_last_qt_var('notthere'));
106
    }
106
    }
107
 
107
 
108
    public function test_get_last_behaviour_var_there() {
108
    public function test_get_last_behaviour_var_there(): void {
109
        $this->qa->get_step(1)->set_behaviour_var('_x', 'a value');
109
        $this->qa->get_step(1)->set_behaviour_var('_x', 'a value');
Línea 110... Línea 110...
110
        $this->assertEquals('a value', '' . $this->qa->get_last_behaviour_var('_x'));
110
        $this->assertEquals('a value', '' . $this->qa->get_last_behaviour_var('_x'));
111
    }
111
    }
112
 
112
 
113
    public function test_get_state_gets_state_of_last() {
113
    public function test_get_state_gets_state_of_last(): void {
114
        $this->qa->get_step(2)->set_state(question_state::$gradedright);
114
        $this->qa->get_step(2)->set_state(question_state::$gradedright);
Línea 115... Línea 115...
115
        $this->qa->get_step(1)->set_state(question_state::$gradedwrong);
115
        $this->qa->get_step(1)->set_state(question_state::$gradedwrong);
116
        $this->assertEquals(question_state::$gradedright, $this->qa->get_state());
116
        $this->assertEquals(question_state::$gradedright, $this->qa->get_state());
117
    }
117
    }
Línea 118... Línea 118...
118
 
118
 
119
    public function test_get_mark_gets_mark_of_last() {
119
    public function test_get_mark_gets_mark_of_last(): void {
120
        $this->assertEquals(2, $this->qa->get_max_mark());
120
        $this->assertEquals(2, $this->qa->get_max_mark());
121
        $this->qa->get_step(2)->set_fraction(0.5);
121
        $this->qa->get_step(2)->set_fraction(0.5);
Línea 122... Línea 122...
122
        $this->qa->get_step(1)->set_fraction(0.1);
122
        $this->qa->get_step(1)->set_fraction(0.1);
123
        $this->assertEquals(1, $this->qa->get_mark());
123
        $this->assertEquals(1, $this->qa->get_mark());
124
    }
124
    }
Línea 125... Línea 125...
125
 
125
 
126
    public function test_get_fraction_gets_fraction_of_last() {
126
    public function test_get_fraction_gets_fraction_of_last(): void {
127
        $this->qa->get_step(2)->set_fraction(0.5);
127
        $this->qa->get_step(2)->set_fraction(0.5);
128
        $this->qa->get_step(1)->set_fraction(0.1);
128
        $this->qa->get_step(1)->set_fraction(0.1);
Línea 129... Línea 129...
129
        $this->assertEquals(0.5, $this->qa->get_fraction());
129
        $this->assertEquals(0.5, $this->qa->get_fraction());
130
    }
130
    }
131
 
131
 
132
    public function test_get_fraction_returns_null_if_none() {
132
    public function test_get_fraction_returns_null_if_none(): void {
133
        $this->assertNull($this->qa->get_fraction());
133
        $this->assertNull($this->qa->get_fraction());
Línea 134... Línea 134...
134
    }
134
    }
135
 
135
 
136
    public function test_format_mark() {
136
    public function test_format_mark(): void {
137
        $this->qa->get_step(2)->set_fraction(0.5);
137
        $this->qa->get_step(2)->set_fraction(0.5);
Línea 138... Línea 138...
138
        $this->assertEquals('1.00', $this->qa->format_mark(2));
138
        $this->assertEquals('1.00', $this->qa->format_mark(2));
139
    }
139
    }
140
 
140
 
141
    public function test_format_max_mark() {
141
    public function test_format_max_mark(): void {
142
        $this->assertEquals('2.0000000', $this->qa->format_max_mark(7));
142
        $this->assertEquals('2.0000000', $this->qa->format_max_mark(7));
Línea 197... Línea 197...
197
     * @param float $maxmark marks for the question attempt.
197
     * @param float $maxmark marks for the question attempt.
198
     * @param string|null $currentmark submitted mark.
198
     * @param string|null $currentmark submitted mark.
199
     * @param string $expectederror expected error, if any.
199
     * @param string $expectederror expected error, if any.
200
     */
200
     */
201
    public function test_validate_manual_mark(float $minfraction, float $maxfraction,
201
    public function test_validate_manual_mark(float $minfraction, float $maxfraction,
202
            float $maxmark, ?string $currentmark, string $expectederror) {
202
            float $maxmark, ?string $currentmark, string $expectederror): void {
203
        $this->qa->set_min_fraction($minfraction);
203
        $this->qa->set_min_fraction($minfraction);
204
        $this->qa->set_max_fraction($maxfraction);
204
        $this->qa->set_max_fraction($maxfraction);
205
        $this->qa->set_max_mark($maxmark);
205
        $this->qa->set_max_mark($maxmark);
206
        $this->assertSame($expectederror, $this->qa->validate_manual_mark($currentmark));
206
        $this->assertSame($expectederror, $this->qa->validate_manual_mark($currentmark));
207
    }
207
    }