import pandas as pd
from startup_app.engine import COLUMNS, geometry_contains, load_stores, ring_contains


def test_boundary_including_holes():
    outer = [[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]]
    hole = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]
    polygon = {"type": "Polygon", "coordinates": [outer, hole]}
    assert geometry_contains(3, 3, polygon)
    assert not geometry_contains(1.5, 1.5, polygon)
    assert not geometry_contains(5, 3, polygon)
    assert ring_contains(0, 2, outer)
    assert geometry_contains(3, 3, {"type": "MultiPolygon", "coordinates": [[outer, hole]]})


def test_data_cleaning_preserves_ids_and_reports_removals(tmp_path):
    base = {key: "테스트" for key in COLUMNS}
    base.update({"위도": 36.5, "경도": 127.2, "건물명": None, "상가업소번호": "0001"})
    rows = [base, base.copy(), {**base, "상가업소번호": "0002", "위도": None}, {**base, "상가업소번호": "0003", "경도": 128}]
    path = tmp_path / "stores.csv"
    pd.DataFrame(rows).to_csv(path, index=False)
    frame, audit = load_stores(path)
    assert frame["상가업소번호"].tolist() == ["0001"]
    assert frame["건물명"].tolist() == [""]
    assert audit == {"원본행": 4, "좌표ID오류제외": 2, "중복ID제외": 1, "사용행": 1}
def test_comparison_baseline_uses_other_categories_only():
    import numpy as np
    from startup_app.engine import 엔진
    predicted = 엔진.비례예측(np.array([10., 20.]), np.array([2., 4.]), np.array([5., 15.]))
    np.testing.assert_allclose(predicted, [1., 3.])


