feat: add where are more items problem

This commit is contained in:
AlanSilvaaa
2026-05-26 09:58:49 -04:00
parent 494ff27c06
commit 801cdee331
8 changed files with 244 additions and 4 deletions

View File

@@ -11,7 +11,7 @@ class JoinPicturesWithQuantityEndpointTest(unittest.TestCase):
def test_creates_problem(self) -> None:
response = self.client.post(
"/math/1_grade/join_pictures_with_quantity",
"/math/grade_1/join_pictures_with_quantity",
json={
"available_pictures": [
{
@@ -37,7 +37,7 @@ class JoinPicturesWithQuantityEndpointTest(unittest.TestCase):
def test_returns_bad_request_for_too_few_pictures(self) -> None:
response = self.client.post(
"/math/1_grade/join_pictures_with_quantity",
"/math/grade_1/join_pictures_with_quantity",
json={
"available_pictures": [
{

View File

@@ -0,0 +1,72 @@
import unittest
from fastapi.testclient import TestClient
from app.main import create_app
class WhereAreMoreItemsEndpointTest(unittest.TestCase):
def setUp(self) -> None:
self.client = TestClient(create_app())
def test_creates_problem(self) -> None:
response = self.client.post(
"/math/grade_1/where_are_more_items",
json={
"available_pictures": [
{
"id": f"picture-{index}",
"name": f"Picture {index}",
"image_path": f"/images/{index}.png",
}
for index in range(6)
],
"seed": 1,
},
)
self.assertEqual(response.status_code, 200)
problem = response.json()
self.assertEqual(problem["instructions"], "Marca dónde hay más.")
self.assertEqual(len(problem["comparisons"]), 3)
for comparison in problem["comparisons"]:
left_group = comparison["left_group"]
right_group = comparison["right_group"]
self.assertEqual(left_group["side"], "left")
self.assertEqual(right_group["side"], "right")
self.assertNotEqual(left_group["quantity"], right_group["quantity"])
self.assertIn("picture", left_group)
self.assertIn("picture", right_group)
expected_answer_side = (
"left"
if left_group["quantity"] > right_group["quantity"]
else "right"
)
self.assertEqual(comparison["answer_side"], expected_answer_side)
def test_returns_bad_request_for_too_few_figures(self) -> None:
response = self.client.post(
"/math/grade_1/where_are_more_items",
json={
"available_pictures": [
{
"id": "picture-1",
"name": "Picture 1",
"image_path": "/images/1.png",
}
]
},
)
self.assertEqual(response.status_code, 400)
self.assertEqual(
response.json(),
{"detail": "available_pictures must contain at least 2 pictures"},
)
if __name__ == "__main__":
unittest.main()