Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions in2lambda/api/response_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def _grade_params(self) -> Optional[dict[str, Any]]:
"""The parameters sent to the evaluation function."""
return self.grade_params

def _serial(self, value: Any) -> Any:
"""An answer or test payload as Lambda Feedback stores it."""
return value


@dataclass(kw_only=True)
class _Maths(ResponseArea):
Expand Down Expand Up @@ -185,6 +189,14 @@ class Boolean(ResponseArea):
response_type: ClassVar[str] = "BOOLEAN"
answer: bool = False

# Lambda Feedback stores the answer, and sends the response, as 1 or 0, and
# isExactEqual compares them as strings.
def _serial(self, value: Any) -> Any:
return int(value) if isinstance(value, bool) else value

def _grade_params(self) -> Optional[dict[str, Any]]:
return {"type": "str", **(self.grade_params or {})}


@dataclass(kw_only=True)
class MultipleChoice(ResponseArea):
Expand Down
4 changes: 2 additions & 2 deletions in2lambda/json_convert/json_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _response_area_to_json(area: ResponseArea, order: int) -> dict[str, Any]:
"tests": [
{
"id": test.id,
"payload": test.payload,
"payload": area._serial(test.payload),
"expectedResponse": {"isCorrect": test.is_correct},
}
for test in area.tests
Expand All @@ -80,7 +80,7 @@ def _response_area_to_json(area: ResponseArea, order: int) -> dict[str, Any]:
"response": {
"responseInput": {
"responseType": area.response_type,
"answer": area.answer,
"answer": area._serial(area.answer),
"config": area._config(),
}
},
Expand Down
10 changes: 10 additions & 0 deletions tests/test_boolean.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""A Boolean area is written as Lambda Feedback's own teacher test sends it."""

from in2lambda.api.response_area import Boolean
from in2lambda.json_convert.json_convert import _response_area_to_json


def test_a_boolean_answer_is_written_as_a_number_compared_as_a_string() -> None:
area = _response_area_to_json(Boolean(answer=True), 0)
assert area["response"]["responseInput"]["answer"] == 1
assert area["gradeParams"] == {"type": "str"}
Loading