from pathlib import Path

import cv2
import numpy as np

from app.blur_engine import Box, blur_boxes, iou, smooth_boxes


def test_blur_changes_inside_box_only():
    img = np.zeros((80, 80, 3), dtype=np.uint8)
    img[20:60, 20:60] = 255
    out = blur_boxes(img, [Box(25, 25, 55, 55)], blur_strength=21, margin=0.0)
    assert out.shape == img.shape
    assert np.array_equal(out[:10, :10], img[:10, :10])


def test_iou():
    a = Box(0, 0, 10, 10)
    b = Box(5, 5, 15, 15)
    assert 0 < iou(a, b) < 1


def test_smooth_boxes_moves_towards_current():
    prev = [Box(0, 0, 100, 100)]
    cur = [Box(10, 10, 110, 110)]
    smoothed = smooth_boxes(cur, prev, alpha=0.5)
    assert smoothed[0].x1 == 5
    assert smoothed[0].y1 == 5
