When checking a function definition of lambda function, prepare has_equal_x for checking the call of a user-defined function. Args: callstr (str): call string that specifies how the function should be called, e.g. `f(1, a = 2)`. ``check_call()`` will replace ``f`` with th
(state, callstr, argstr=None, expand_msg=None)
| 285 | |
| 286 | |
| 287 | def check_call(state, callstr, argstr=None, expand_msg=None): |
| 288 | """When checking a function definition of lambda function, |
| 289 | prepare has_equal_x for checking the call of a user-defined function. |
| 290 | |
| 291 | Args: |
| 292 | callstr (str): call string that specifies how the function should be called, e.g. `f(1, a = 2)`. |
| 293 | ``check_call()`` will replace ``f`` with the function/lambda you're targeting. |
| 294 | argstr (str): If specified, this overrides the way the function call is refered to in the expand message. |
| 295 | expand_msg (str): If specified, this overrides any messages that are prepended by previous SCT chains. |
| 296 | state (State): state object that is chained from. |
| 297 | |
| 298 | :Example: |
| 299 | |
| 300 | Student and solution code:: |
| 301 | |
| 302 | def my_power(x): |
| 303 | print("calculating sqrt...") |
| 304 | return(x * x) |
| 305 | |
| 306 | SCT:: |
| 307 | |
| 308 | Ex().check_function_def('my_power').multi( |
| 309 | check_call("f(3)").has_equal_value() |
| 310 | check_call("f(3)").has_equal_output() |
| 311 | ) |
| 312 | """ |
| 313 | |
| 314 | state.assert_is( |
| 315 | ["function_defs", "lambda_functions"], |
| 316 | "check_call", |
| 317 | ["check_function_def", "check_lambda_function"], |
| 318 | ) |
| 319 | |
| 320 | if expand_msg is None: |
| 321 | expand_msg = "To verify it, we reran {{argstr}}. " |
| 322 | |
| 323 | stu_part, _argstr = build_call(callstr, state.student_parts["node"]) |
| 324 | sol_part, _ = build_call(callstr, state.solution_parts["node"]) |
| 325 | |
| 326 | append_message = FeedbackComponent(expand_msg, {"argstr": argstr or _argstr}) |
| 327 | child = part_to_child(stu_part, sol_part, append_message, state) |
| 328 | |
| 329 | return child |