MDL-46819 core_grades: Negative weights are changed to 0
[moodle.git] / grade / tests / behat / grade_natural_normalisation.feature
CommitLineData
11c93e28 1@core @core_grades
519429b2
AG
2Feature: We can use natural aggregation and weights will be normalised to a total of one hundred
3 In order to override weights
4 As a teacher
5 I need to add assessments to the gradebook.
6
7 Background:
8 Given the following "courses" exist:
9 | fullname | shortname | category | groupmode |
10 | Course 1 | C1 | 0 | 1 |
11 And the following "users" exist:
12 | username | firstname | lastname | email | idnumber |
13 | teacher1 | Teacher | 1 | teacher1@asd.com | t1 |
14 | student1 | Student | 1 | student1@asd.com | s1 |
15 And the following "course enrolments" exist:
16 | user | course | role |
17 | teacher1 | C1 | editingteacher |
18 | student1 | C1 | student |
19 And the following "grade categories" exist:
20 | fullname | course |
21 | Sub category 1 | C1 |
22 And the following "activities" exist:
23 | activity | course | idnumber | name | intro | grade |
24 | assign | C1 | a1 | Test assignment one | Submit something! | 300 |
25 | assign | C1 | a2 | Test assignment two | Submit something! | 100 |
26 | assign | C1 | a3 | Test assignment three | Submit something! | 150 |
27 | assign | C1 | a4 | Test assignment four | Submit nothing! | 150 |
28 And the following "activities" exist:
29 | activity | course | idnumber | name | intro | gradecategory | grade |
30 | assign | C1 | a5 | Test assignment five | Submit something! | Sub category 1 | 20 |
31 | assign | C1 | a6 | Test assignment six | Submit something! | Sub category 1 | 10 |
32 | assign | C1 | a7 | Test assignment seven | Submit nothing! | Sub category 1 | 15 |
33 And I log in as "teacher1"
34 And I follow "Course 1"
35 And I follow "Grades"
9f1088d4 36 And I set the field "Grade report" to "Categories and items"
2f15decb
MG
37
38 @javascript
39 Scenario: Setting all weights in a category to exactly one hundred in total.
40
41 And the field "Weight of Test assignment five" matches value "44.444"
42 And the field "Weight of Test assignment six" matches value "22.222"
43 And the field "Weight of Test assignment seven" matches value "33.333"
44 When I set the field "Override weight of Test assignment five" to "1"
45 And I set the field "Override weight of Test assignment six" to "1"
46 And I set the field "Override weight of Test assignment seven" to "1"
47 And I set the field "Weight of Test assignment five" to "30"
48 And I set the field "Weight of Test assignment six" to "50"
49 And I set the field "Weight of Test assignment seven" to "20"
50 And I press "Save changes"
51
52 Then I should not see "Your weights have been adjusted to total 100."
53 And the field "Weight of Test assignment five" matches value "30.0"
54 And the field "Weight of Test assignment six" matches value "50.0"
55 And the field "Weight of Test assignment seven" matches value "20.0"
56
57 @javascript
58 Scenario: Setting all weights in a category to less than one hundred is normalised.
59
60 When I set the field "Override weight of Test assignment five" to "1"
61 And I set the field "Override weight of Test assignment six" to "1"
62 And I set the field "Override weight of Test assignment seven" to "1"
63 And I set the field "Weight of Test assignment five" to "1"
64 And I set the field "Weight of Test assignment six" to "1"
65 And I set the field "Weight of Test assignment seven" to "2"
66 And I press "Save changes"
67
68 Then I should see "Your weights have been adjusted to total 100."
69 And the field "Weight of Test assignment five" matches value "25.0"
70 And the field "Weight of Test assignment six" matches value "25.0"
71 And the field "Weight of Test assignment seven" matches value "50.0"
72
73 @javascript
74 Scenario: Set one of the grade item weights to a figure over one hundred.
75
76 When I set the field "Override weight of Test assignment five" to "1"
77 And I set the field "Weight of Test assignment five" to "120"
78 And I press "Save changes"
79
80 Then I should see "Your weights have been adjusted to total 100."
81 And the field "Weight of Test assignment five" matches value "100.0"
82 And the field "Weight of Test assignment six" matches value "0.0"
83 And the field "Weight of Test assignment seven" matches value "0.0"
84
85 @javascript
86 Scenario: Setting several but not all grade item weights to over one hundred each.
87
88 When I set the field "Override weight of Test assignment five" to "1"
89 And I set the field "Override weight of Test assignment six" to "1"
90 And I set the field "Weight of Test assignment five" to "150"
91 And I set the field "Weight of Test assignment six" to "150"
92 And I press "Save changes"
93
94 Then I should see "Your weights have been adjusted to total 100."
95 And the field "Weight of Test assignment five" matches value "50.000"
96 And the field "Weight of Test assignment six" matches value "50.000"
97 And the field "Weight of Test assignment seven" matches value "0.0"
98
99 @javascript
100 Scenario: Grade items weights are normalised when all grade item weights are overridden (sum exactly 100). Extra credit is set to zero.
101
102 When I follow "Edit assign Test assignment seven"
103 And I set the field "Extra credit" to "1"
104 And I press "Save changes"
105 And the field "Weight of Test assignment five" matches value "66.667"
106 And the field "Weight of Test assignment six" matches value "33.333"
107 And the field "Weight of Test assignment seven" matches value "50.0"
108 And I set the field "Override weight of Test assignment five" to "1"
109 And I set the field "Override weight of Test assignment six" to "1"
110 And I set the field "Weight of Test assignment five" to "60"
111 And I set the field "Weight of Test assignment six" to "40"
112 And I press "Save changes"
113
11c93e28 114 Then I should see "Your weights have been adjusted to total 100."
2f15decb
MG
115 And the field "Weight of Test assignment five" matches value "60.000"
116 And the field "Weight of Test assignment six" matches value "40.000"
117 And the field "Weight of Test assignment seven" matches value "0.0"
118 And I follow "Reset weights of Sub category 1"
119 And the field "Weight of Test assignment five" matches value "66.667"
120 And the field "Weight of Test assignment six" matches value "33.333"
121 And the field "Weight of Test assignment seven" matches value "50.0"
122
123 @javascript
124 Scenario: Grade items weights are normalised when all grade item weights are overridden (sum over 100). Extra credit is set to zero.
125
126 When I follow "Edit assign Test assignment seven"
127 And I set the field "Extra credit" to "1"
128 And I press "Save changes"
129 And I set the field "Override weight of Test assignment five" to "1"
130 And I set the field "Override weight of Test assignment six" to "1"
131 And I set the field "Weight of Test assignment five" to "60"
132 And I set the field "Weight of Test assignment six" to "50"
133 And I press "Save changes"
134
135 Then I should see "Your weights have been adjusted to total 100."
136 And the field "Weight of Test assignment five" matches value "54.545"
137 And the field "Weight of Test assignment six" matches value "45.455"
138 And the field "Weight of Test assignment seven" matches value "0.0"
139 And I follow "Reset weights of Sub category 1"
140 And the field "Weight of Test assignment five" matches value "66.667"
141 And the field "Weight of Test assignment six" matches value "33.333"
142 And the field "Weight of Test assignment seven" matches value "50.0"
143
11c93e28
DW
144 @javascript
145 Scenario: Grade items weights are normalised when all grade item weights are overridden (sum under 100). Extra credit is set to zero.
146
147 When I follow "Edit assign Test assignment seven"
148 And I set the field "Extra credit" to "1"
149 And I press "Save changes"
150 And I set the field "Override weight of Test assignment five" to "1"
151 And I set the field "Override weight of Test assignment six" to "1"
152 And I set the field "Weight of Test assignment five" to "40"
153 And I set the field "Weight of Test assignment six" to "30"
154 And I press "Save changes"
155
156 Then I should see "Your weights have been adjusted to total 100."
157 And the field "Weight of Test assignment five" matches value "57.143"
158 And the field "Weight of Test assignment six" matches value "42.857"
159 And the field "Weight of Test assignment seven" matches value "0.0"
160 And I follow "Reset weights of Sub category 1"
161 And the field "Weight of Test assignment five" matches value "66.667"
162 And the field "Weight of Test assignment six" matches value "33.333"
163 And the field "Weight of Test assignment seven" matches value "50.0"
2f15decb
MG
164
165 @javascript
166 Scenario: Grade items weights are normalised when not all grade item weights are overridden. Extra credit is set respectful to non-overridden items.
167
168 When I follow "Edit assign Test assignment seven"
169 And I set the field "Extra credit" to "1"
170 And I press "Save changes"
171 And I set the field "Override weight of Test assignment five" to "1"
172 And I set the field "Weight of Test assignment five" to "40"
173 And I press "Save changes"
174
11c93e28 175 Then I should see "Your weights have been adjusted to total 100."
2f15decb
MG
176 And the field "Weight of Test assignment five" matches value "40.00"
177 And the field "Weight of Test assignment six" matches value "60.000"
178 And the field "Weight of Test assignment seven" matches value "90.0"
179 And I follow "Reset weights of Sub category 1"
180 And the field "Weight of Test assignment five" matches value "66.667"
181 And the field "Weight of Test assignment six" matches value "33.333"
182 And the field "Weight of Test assignment seven" matches value "50.0"
183
184 @javascript
185 Scenario: The extra credit grade item weight is overridden to a figure over one hundred and then
186 the grade item is set to normal.
187
188 When I follow "Edit assign Test assignment seven"
189 And I set the field "Extra credit" to "1"
190 And I press "Save changes"
191 And I set the field "Override weight of Test assignment seven" to "1"
192 And I set the field "Weight of Test assignment seven" to "105"
193 And I press "Save changes"
194 Then I should not see "Your weights have been adjusted to total 100."
195 And the field "Weight of Test assignment five" matches value "66.667"
196 And the field "Weight of Test assignment six" matches value "33.333"
197 And the field "Weight of Test assignment seven" matches value "105.0"
198 And I follow "Edit assign Test assignment seven"
199 And I set the field "Extra credit" to "0"
200 And I press "Save changes"
201 And I should see "Your weights have been adjusted to total 100."
202
11c93e28
DW
203 And the field "Weight of Test assignment five" matches value "0.0"
204 And the field "Weight of Test assignment six" matches value "0.0"
205 And the field "Weight of Test assignment seven" matches value "100.0"
2f15decb
MG
206
207 @javascript
208 Scenario: The extra credit grade item weight is overridden to a figure over one hundred and then
209 the grade category is reset.
210
211 When I follow "Edit assign Test assignment seven"
212 And I set the field "Extra credit" to "1"
213 And I press "Save changes"
214 And I set the field "Override weight of Test assignment seven" to "1"
215 And I set the field "Weight of Test assignment seven" to "105"
216 And I press "Save changes"
217
218 And I follow "Reset weights of Sub category 1"
219 And the field "Weight of Test assignment five" matches value "66.667"
220 And the field "Weight of Test assignment six" matches value "33.333"
221 And the field "Weight of Test assignment seven" matches value "50.0"
222
223 @javascript
224 Scenario: Two out of three grade items weights are overridden and one is not.
225 The overridden grade item weights total over one hundred.
226
227 Given I set the field "Override weight of Test assignment six" to "1"
228 And I set the field "Override weight of Test assignment seven" to "1"
229 And I set the field "Weight of Test assignment six" to "55"
230 And I set the field "Weight of Test assignment seven" to "65"
231 And I press "Save changes"
232 And I should see "Your weights have been adjusted to total 100."
233
234 Then the field "Weight of Test assignment five" matches value "0.0"
235 And the field "Weight of Test assignment six" matches value "45.833"
236 And the field "Weight of Test assignment seven" matches value "54.167"
f70da024
AG
237
238 @javascript
239 Scenario: With one grade item set as extra credit, when I reset the weights for a category they return to the natural weights.
240
241 When I follow "Edit assign Test assignment five"
242 And I set the field "Extra credit" to "1"
243 And I press "Save changes"
244 And I set the field "Override weight of Test assignment six" to "1"
245 And I set the field "Override weight of Test assignment seven" to "1"
246 And I set the field "Weight of Test assignment six" to "55"
247 And I set the field "Weight of Test assignment seven" to "40"
248 And I press "Save changes"
249 And I follow "Reset weights of Sub category 1"
250 Then the field "Weight of Test assignment five" matches value "80.0"
251 And the field "Weight of Test assignment six" matches value "40.0"
252 And the field "Weight of Test assignment seven" matches value "60.0"
0cf12217
AG
253
254 @javascript
255 Scenario: Overriding a grade item with a negative value results in the value being changed to zero.
256
257 When I set the field "Override weight of Test assignment five" to "1"
258 And I set the field "Weight of Test assignment five" to "-15"
259 And I press "Save changes"
260 Then the field "Weight of Test assignment five" matches value "0.0"
261 And the field "Weight of Test assignment six" matches value "40.0"
262 And the field "Weight of Test assignment seven" matches value "60.0"
263 And I set the field "Override weight of Test assignment six" to "1"
264 And I set the field "Weight of Test assignment six" to "-25"
265 And I press "Save changes"
266 Then the field "Weight of Test assignment six" matches value "0.0"
267 And the field "Weight of Test assignment seven" matches value "100.0"