"""AIFlow Math Ink 0.5의 모델 독립적 그리딩 계약을 검증한다.""" from PIL import Image from aiflow_math_ink_05 import ( GridConfig, Stroke, build_formula_grids, parse_writing_events, render_grid_images, ) def test_fraction_bar_joins_numerator_and_denominator() -> None: """필요 변수: 분자·분수선·분모 획. 작동 원리: 구조선이 세 획을 한 셀로 묶는지 검증한다.""" strokes = [ Stroke(0, ((24, 20), (36, 20))), Stroke(1, ((10, 42), (60, 42))), Stroke(2, ((24, 64), (36, 64))), ] grids = build_formula_grids(strokes) assert len(grids) == 1 assert grids[0].stroke_ids == (0, 1, 2) def test_distant_rows_remain_separate() -> None: """필요 변수: 멀리 떨어진 두 행. 작동 원리: 행 사이 연결 조건이 없으면 두 셀을 유지한다.""" strokes = [ Stroke(0, ((10, 20), (40, 20))), Stroke(1, ((10, 180), (40, 180))), ] grids = build_formula_grids(strokes) assert len(grids) == 2 def test_parser_enforces_total_point_cap() -> None: """필요 변수: 작은 점 상한과 두 획 payload. 작동 원리: 상한을 넘는 획을 받지 않는지 검증한다.""" payload = [ {"stroke_id": 0, "points": [{"x": 0, "y": 0}, {"x": 1, "y": 1}]}, {"stroke_id": 1, "points": [{"x": 2, "y": 2}, {"x": 3, "y": 3}]}, ] strokes = parse_writing_events(payload, GridConfig(max_total_points=2)) assert [stroke.stroke_id for stroke in strokes] == [0] def test_renderer_returns_one_rgb_image_per_grid() -> None: """필요 변수: 캔버스·두 행. 작동 원리: 각 셀에 대응하는 RGB 이미지가 생성되는지 검증한다.""" strokes = [ Stroke(0, ((10, 20), (40, 20))), Stroke(1, ((10, 180), (40, 180))), ] grids = build_formula_grids(strokes) images = render_grid_images(Image.new("RGB", (100, 220), "white"), strokes, grids) assert len(images) == len(grids) == 2 assert all(image.mode == "RGB" for image in images)