File size: 2,076 Bytes
b9c7f6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""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)