Files
math-problems-structure/tests/test_where_are_more_items.py

58 lines
1.8 KiB
Python

import unittest
from math_problems_structure.grade_1 import where_are_more_items
class WhereAreMoreItemsTest(unittest.TestCase):
def test_creates_problem(self) -> None:
problem = where_are_more_items(
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(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_raises_for_too_few_figures(self) -> None:
with self.assertRaisesRegex(
ValueError,
"available_pictures must contain at least 2 pictures",
):
where_are_more_items(
available_pictures=[
{
"id": "picture-1",
"name": "Picture 1",
"image_path": "/images/1.png",
}
]
)
if __name__ == "__main__":
unittest.main()