Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 66... Línea 66...
66
        $this->allocator    = null;
66
        $this->allocator    = null;
67
        $this->workshop     = null;
67
        $this->workshop     = null;
68
        parent::tearDown();
68
        parent::tearDown();
69
    }
69
    }
Línea 70... Línea 70...
70
 
70
 
71
    public function test_self_allocation_empty_values() {
71
    public function test_self_allocation_empty_values(): void {
72
        // fixture setup & exercise SUT & verify
72
        // fixture setup & exercise SUT & verify
73
        $this->assertEquals(array(), $this->allocator->self_allocation());
73
        $this->assertEquals(array(), $this->allocator->self_allocation());
Línea 74... Línea 74...
74
    }
74
    }
75
 
75
 
76
    public function test_self_allocation_equal_user_groups() {
76
    public function test_self_allocation_equal_user_groups(): void {
77
        // fixture setup
77
        // fixture setup
78
        $authors    = array(0 => array_fill_keys(array(4, 6, 10), new \stdClass()));
78
        $authors    = array(0 => array_fill_keys(array(4, 6, 10), new \stdClass()));
79
        $reviewers  = array(0 => array_fill_keys(array(4, 6, 10), new \stdClass()));
79
        $reviewers  = array(0 => array_fill_keys(array(4, 6, 10), new \stdClass()));
80
        // exercise SUT
80
        // exercise SUT
81
        $newallocations = $this->allocator->self_allocation($authors, $reviewers);
81
        $newallocations = $this->allocator->self_allocation($authors, $reviewers);
82
        // verify
82
        // verify
Línea 83... Línea 83...
83
        $this->assertEquals(array(array(4 => 4), array(6 => 6), array(10 => 10)), $newallocations);
83
        $this->assertEquals(array(array(4 => 4), array(6 => 6), array(10 => 10)), $newallocations);
84
    }
84
    }
85
 
85
 
86
    public function test_self_allocation_different_user_groups() {
86
    public function test_self_allocation_different_user_groups(): void {
87
        // fixture setup
87
        // fixture setup
88
        $authors    = array(0 => array_fill_keys(array(1, 4, 5, 10, 13), new \stdClass()));
88
        $authors    = array(0 => array_fill_keys(array(1, 4, 5, 10, 13), new \stdClass()));
89
        $reviewers  = array(0 => array_fill_keys(array(4, 7, 10), new \stdClass()));
89
        $reviewers  = array(0 => array_fill_keys(array(4, 7, 10), new \stdClass()));
90
        // exercise SUT
90
        // exercise SUT
91
        $newallocations = $this->allocator->self_allocation($authors, $reviewers);
91
        $newallocations = $this->allocator->self_allocation($authors, $reviewers);
Línea 92... Línea 92...
92
        // verify
92
        // verify
93
        $this->assertEquals(array(array(4 => 4), array(10 => 10)), $newallocations);
93
        $this->assertEquals(array(array(4 => 4), array(10 => 10)), $newallocations);
94
    }
94
    }
95
 
95
 
96
    public function test_self_allocation_skip_existing() {
96
    public function test_self_allocation_skip_existing(): void {
97
        // fixture setup
97
        // fixture setup
98
        $authors        = array(0 => array_fill_keys(array(3, 4, 10), new \stdClass()));
98
        $authors        = array(0 => array_fill_keys(array(3, 4, 10), new \stdClass()));
99
        $reviewers      = array(0 => array_fill_keys(array(3, 4, 10), new \stdClass()));
99
        $reviewers      = array(0 => array_fill_keys(array(3, 4, 10), new \stdClass()));
100
        $assessments    = array(23 => (object)array('authorid' => 3, 'reviewerid' => 3));
100
        $assessments    = array(23 => (object)array('authorid' => 3, 'reviewerid' => 3));
101
        // exercise SUT
101
        // exercise SUT
Línea 102... Línea 102...
102
        $newallocations = $this->allocator->self_allocation($authors, $reviewers, $assessments);
102
        $newallocations = $this->allocator->self_allocation($authors, $reviewers, $assessments);
103
        // verify
103
        // verify
104
        $this->assertEquals(array(array(4 => 4), array(10 => 10)), $newallocations);
104
        $this->assertEquals(array(array(4 => 4), array(10 => 10)), $newallocations);
105
    }
105
    }
106
 
106
 
107
    public function test_get_author_ids() {
107
    public function test_get_author_ids(): void {
Línea 108... Línea 108...
108
        // fixture setup
108
        // fixture setup
109
        $newallocations = array(array(1 => 3), array(2 => 1), array(3 => 1));
109
        $newallocations = array(array(1 => 3), array(2 => 1), array(3 => 1));
110
        // exercise SUT & verify
110
        // exercise SUT & verify
111
        $this->assertEquals(array(3, 1), $this->allocator->get_author_ids($newallocations));
111
        $this->assertEquals(array(3, 1), $this->allocator->get_author_ids($newallocations));
112
    }
112
    }
113
 
113
 
Línea 124... Línea 124...
124
            23 => (object)array('id' => 676, 'authorid' => 23),
124
            23 => (object)array('id' => 676, 'authorid' => 23),
125
            56 => (object)array('id' => 121, 'authorid' => 56),
125
            56 => (object)array('id' => 121, 'authorid' => 56),
126
        ), $submissions);
126
        ), $submissions);
127
    }
127
    }
Línea 128... Línea 128...
128
 
128
 
129
    public function test_index_submissions_by_authors_duplicate_author() {
129
    public function test_index_submissions_by_authors_duplicate_author(): void {
130
        // fixture setup
130
        // fixture setup
131
        $submissions = array(
131
        $submissions = array(
132
            14 => (object)array('id' => 676, 'authorid' => 3),
132
            14 => (object)array('id' => 676, 'authorid' => 3),
133
            87 => (object)array('id' => 121, 'authorid' => 3),
133
            87 => (object)array('id' => 121, 'authorid' => 3),
134
        );
134
        );
135
        // exercise SUT
135
        // exercise SUT
136
        $this->expectException(\moodle_exception::class);
136
        $this->expectException(\moodle_exception::class);
137
        $submissions = $this->allocator->index_submissions_by_authors($submissions);
137
        $submissions = $this->allocator->index_submissions_by_authors($submissions);
Línea 138... Línea 138...
138
    }
138
    }
139
 
139
 
140
    public function test_get_unique_allocations() {
140
    public function test_get_unique_allocations(): void {
141
        // fixture setup
141
        // fixture setup
142
        $newallocations = array(array(4 => 5), array(6 => 6), array(1 => 16), array(4 => 5), array(16 => 1));
142
        $newallocations = array(array(4 => 5), array(6 => 6), array(1 => 16), array(4 => 5), array(16 => 1));
143
        // exercise SUT
143
        // exercise SUT
144
        $newallocations = $this->allocator->get_unique_allocations($newallocations);
144
        $newallocations = $this->allocator->get_unique_allocations($newallocations);
145
        // verify
145
        // verify
Línea 146... Línea 146...
146
        $this->assertEquals(array(array(4 => 5), array(6 => 6), array(1 => 16), array(16 => 1)), $newallocations);
146
        $this->assertEquals(array(array(4 => 5), array(6 => 6), array(1 => 16), array(16 => 1)), $newallocations);
147
    }
147
    }
148
 
148
 
149
    public function test_get_unkept_assessments_no_keep_selfassessments() {
149
    public function test_get_unkept_assessments_no_keep_selfassessments(): void {
150
        // fixture setup
150
        // fixture setup
151
        $assessments = array(
151
        $assessments = array(
Línea 159... Línea 159...
159
        // verify
159
        // verify
160
        // we want to keep $assessments[45] because it has been re-allocated
160
        // we want to keep $assessments[45] because it has been re-allocated
161
        $this->assertEquals(array(23, 12), $delassessments);
161
        $this->assertEquals(array(23, 12), $delassessments);
162
    }
162
    }
Línea 163... Línea 163...
163
 
163
 
164
    public function test_get_unkept_assessments_keep_selfassessments() {
164
    public function test_get_unkept_assessments_keep_selfassessments(): void {
165
        // fixture setup
165
        // fixture setup
166
        $assessments = array(
166
        $assessments = array(
167
            23 => (object)array('authorid' => 3, 'reviewerid' => 3),
167
            23 => (object)array('authorid' => 3, 'reviewerid' => 3),
168
            45 => (object)array('authorid' => 5, 'reviewerid' => 11),
168
            45 => (object)array('authorid' => 5, 'reviewerid' => 11),
Línea 178... Línea 178...
178
    }
178
    }
Línea 179... Línea 179...
179
 
179
 
180
    /**
180
    /**
181
     * Aggregates assessment info per author and per reviewer
181
     * Aggregates assessment info per author and per reviewer
182
     */
182
     */
183
    public function test_convert_assessments_to_links() {
183
    public function test_convert_assessments_to_links(): void {
184
        // fixture setup
184
        // fixture setup
185
        $assessments = array(
185
        $assessments = array(
186
            23 => (object)array('authorid' => 3, 'reviewerid' => 3),
186
            23 => (object)array('authorid' => 3, 'reviewerid' => 3),
187
            45 => (object)array('authorid' => 5, 'reviewerid' => 11),
187
            45 => (object)array('authorid' => 5, 'reviewerid' => 11),
Línea 195... Línea 195...
195
    }
195
    }
Línea 196... Línea 196...
196
 
196
 
197
    /**
197
    /**
198
     * Trivial case
198
     * Trivial case
199
     */
199
     */
200
    public function test_convert_assessments_to_links_empty() {
200
    public function test_convert_assessments_to_links_empty(): void {
201
        // fixture setup
201
        // fixture setup
202
        $assessments = array();
202
        $assessments = array();
203
        // exercise SUT
203
        // exercise SUT
204
        list($authorlinks, $reviewerlinks) = $this->allocator->convert_assessments_to_links($assessments);
204
        list($authorlinks, $reviewerlinks) = $this->allocator->convert_assessments_to_links($assessments);
Línea 208... Línea 208...
208
    }
208
    }
Línea 209... Línea 209...
209
 
209
 
210
    /**
210
    /**
211
     * If there is a single element with the lowest workload, it should be chosen
211
     * If there is a single element with the lowest workload, it should be chosen
212
     */
212
     */
213
    public function test_get_element_with_lowest_workload_deterministic() {
213
    public function test_get_element_with_lowest_workload_deterministic(): void {
214
        // fixture setup
214
        // fixture setup
215
        $workload = array(4 => 6, 9 => 1, 10 => 2);
215
        $workload = array(4 => 6, 9 => 1, 10 => 2);
216
        // exercise SUT
216
        // exercise SUT
217
        $chosen = $this->allocator->get_element_with_lowest_workload($workload);
217
        $chosen = $this->allocator->get_element_with_lowest_workload($workload);
Línea 220... Línea 220...
220
    }
220
    }
Línea 221... Línea 221...
221
 
221
 
222
    /**
222
    /**
223
     * If there are no elements available, must return false
223
     * If there are no elements available, must return false
224
     */
224
     */
225
    public function test_get_element_with_lowest_workload_impossible() {
225
    public function test_get_element_with_lowest_workload_impossible(): void {
226
        // fixture setup
226
        // fixture setup
227
        $workload = array();
227
        $workload = array();
228
        // exercise SUT
228
        // exercise SUT
229
        $chosen = $this->allocator->get_element_with_lowest_workload($workload);
229
        $chosen = $this->allocator->get_element_with_lowest_workload($workload);
Línea 232... Línea 232...
232
    }
232
    }
Línea 233... Línea 233...
233
 
233
 
234
    /**
234
    /**
235
     * If there are several elements with the lowest workload, one of them should be chosen randomly
235
     * If there are several elements with the lowest workload, one of them should be chosen randomly
236
     */
236
     */
237
    public function test_get_element_with_lowest_workload_random() {
237
    public function test_get_element_with_lowest_workload_random(): void {
238
        // fixture setup
238
        // fixture setup
239
        $workload = array(4 => 6, 9 => 2, 10 => 2);
239
        $workload = array(4 => 6, 9 => 2, 10 => 2);
240
        // exercise SUT
240
        // exercise SUT
241
        $elements = $this->allocator->get_element_with_lowest_workload($workload);
241
        $elements = $this->allocator->get_element_with_lowest_workload($workload);
Línea 260... Línea 260...
260
    /**
260
    /**
261
     * Floats should be rounded before they are compared
261
     * Floats should be rounded before they are compared
262
     *
262
     *
263
     * This should test
263
     * This should test
264
     */
264
     */
265
    public function test_get_element_with_lowest_workload_random_floats() {
265
    public function test_get_element_with_lowest_workload_random_floats(): void {
266
        // fixture setup
266
        // fixture setup
267
        $workload = array(1 => 1/13, 2 => 0.0769230769231); // should be considered as the same value
267
        $workload = array(1 => 1/13, 2 => 0.0769230769231); // should be considered as the same value
268
        // exercise SUT
268
        // exercise SUT
269
        $elements = $this->allocator->get_element_with_lowest_workload($workload);
269
        $elements = $this->allocator->get_element_with_lowest_workload($workload);
270
        // verify
270
        // verify
Línea 283... Línea 283...
283
    }
283
    }
Línea 284... Línea 284...
284
 
284
 
285
    /**
285
    /**
286
     * Filter new assessments so they do not contain existing
286
     * Filter new assessments so they do not contain existing
287
     */
287
     */
288
    public function test_filter_current_assessments() {
288
    public function test_filter_current_assessments(): void {
289
        // fixture setup
289
        // fixture setup
290
        $newallocations = array(array(3 => 5), array(11 => 5), array(2 => 9), array(3 => 5));
290
        $newallocations = array(array(3 => 5), array(11 => 5), array(2 => 9), array(3 => 5));
291
        $assessments = array(
291
        $assessments = array(
292
            23 => (object)array('authorid' => 3, 'reviewerid' => 3),
292
            23 => (object)array('authorid' => 3, 'reviewerid' => 3),