def feedback(response: TestCase, answer_key: TestCase): """Return a feedback structure that represents the success/error for a single testcase.""" grade = decimal.Decimal(0) status = None # Error messages if isinstance(response, ErrorTestCase): status = response.type # Correct response elif list(response) == list(answer_key): status = 'ok' grade = decimal.Decimal(1.0) # Presentation errors elif presentation_equal(response, answer_key): status = 'wrong-presentation' grade = decimal.Decimal(0.5) # Wrong answer elif isinstance(response, IoTestCase): status = 'wrong-answer' # Invalid else: raise ValueError('invalid testcase: \n%s' % response.format()) return Feedback(response, answer_key, grade=grade, status=status)
def feedback(response: TestCase, answer_key: TestCase): """Return a feedback structure that represents the success/error for a single testcase.""" grade = decimal.Decimal(0) status = None # Error messages if isinstance(response, ErrorTestCase): status = response.type # Correct response elif list(response) == list(answer_key): status = 'ok' grade = decimal.Decimal(1.0) # Presentation errors elif presentation_equal(response, answer_key): status = 'wrong-presentation' grade = decimal.Decimal(0.5) # Wrong answer elif isinstance(response, SimpleTestCase): status = 'wrong-answer' # Invalid else: raise ValueError('invalid testcase: \n%s' % response.format()) return Feedback(response, answer_key, grade=grade, status=status)