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)
|