@@ -129,7 +129,7 @@ def evaluate(event: JsonType) -> Response:
129
129
130
130
result = evaluation_function (body ["response" ], body ["answer" ], params )
131
131
132
- if "cases" in params and len (params ["cases" ]) > 0 :
132
+ if result [ "is_correct" ] is False and "cases" in params and len (params ["cases" ]) > 0 :
133
133
match , warnings = get_case_feedback (
134
134
body ["response" ], params , params ["cases" ]
135
135
)
@@ -170,7 +170,10 @@ def get_case_feedback(
170
170
issues encountered when evaluating each case against the student's
171
171
response.
172
172
"""
173
- matches , feedback , warnings = evaluate_all_cases (response , params , cases )
173
+ # NOTE: Previous behaviour, where all cases are evaluated but only the feedback
174
+ # for the first case is returned can be restored by changing the line below to:
175
+ # matches, feedback, warnings = evaluate_all_cases(response, params, cases)
176
+ matches , feedback , warnings = find_first_matching_case (response , params , cases )
174
177
175
178
if not matches :
176
179
return None , warnings
@@ -198,6 +201,38 @@ def get_case_feedback(
198
201
199
202
return match , warnings
200
203
204
+ def find_first_matching_case (
205
+ response : Any ,
206
+ params : Dict ,
207
+ cases : List [Dict ],
208
+ ) -> Tuple [List [int ], List [str ], List [CaseWarning ]]:
209
+ """Evaluates cases until it finds matching one.
210
+
211
+ Args:
212
+ response (Any): The student's response.
213
+ params (Dict): The params of the evaluation function.
214
+ cases (List[Dict]): A list of cases to check against.
215
+
216
+ Returns:
217
+ Tuple[List[int], List[str], List[CaseWarning]]: Returns a list of
218
+ indices of cases that match a student's response, a list of feedback
219
+ strings from each case, and a list of issues encountered when
220
+ evaluating cases against the student's response.
221
+ """
222
+ matches , feedback , warnings = [], [], []
223
+
224
+ for index , case in enumerate (cases ):
225
+ result = evaluate_case (response , params , case , index )
226
+
227
+ if result .warning is not None :
228
+ warnings .append (result .warning )
229
+
230
+ if result .is_correct :
231
+ matches .append (index )
232
+ feedback .append (result .feedback )
233
+ break
234
+
235
+ return matches , feedback , warnings
201
236
202
237
def evaluate_all_cases (
203
238
response : Any ,
0 commit comments