import unittest from math_problems_structure.grade_1 import subtract_with_image_reference class SubtractWithImageReferenceTest(unittest.TestCase): def setUp(self) -> None: self.figure = { "id": "fish", "name": "Fish", "image_path": "/images/fish.png", } def test_creates_subtraction_problem(self) -> None: problem = subtract_with_image_reference( object_name="peces", initial_quantity=5, removed_quantity=2, actor_name="Diego", figure=self.figure, ) self.assertEqual(problem["title"], "¿Cuántos quedan?") self.assertEqual( problem["question"], "Hay 5 peces. Diego sacó 2 peces. ¿Cuántos peces quedan?", ) self.assertEqual(problem["object_name"], "peces") self.assertEqual(problem["actor_name"], "Diego") self.assertEqual(problem["figure"], self.figure) self.assertEqual( problem["remaining_group"], {"label": "quedan", "quantity": 3, "picture": self.figure}, ) self.assertEqual( problem["subtracted_group"], {"label": "sacó", "quantity": 2, "picture": self.figure}, ) self.assertEqual( problem["equation"], { "initial_quantity": 5, "removed_quantity": 2, "remaining_quantity": 3, "symbol": "-", "equals_symbol": "=", }, ) def test_allows_zero_remaining_figures(self) -> None: problem = subtract_with_image_reference( object_name="peces", initial_quantity=2, removed_quantity=2, figure=self.figure, ) self.assertEqual(problem["equation"]["remaining_quantity"], 0) self.assertEqual(problem["remaining_group"]["quantity"], 0) self.assertEqual(problem["subtracted_group"]["quantity"], 2) def test_raises_when_removed_quantity_is_too_large(self) -> None: with self.assertRaisesRegex( ValueError, "removed_quantity must be less than or equal to initial_quantity", ): subtract_with_image_reference( object_name="peces", initial_quantity=2, removed_quantity=5, figure=self.figure, ) if __name__ == "__main__": unittest.main()