diff --git a/tests/test_analyzer.py b/tests/test_analyzer.py index 944a65e..264dfbe 100644 --- a/tests/test_analyzer.py +++ b/tests/test_analyzer.py @@ -49,21 +49,42 @@ def test_normal_image_is_neither(tmp_path): from analyzer import find_duplicates +def make_gradient_image(tmp_path, name="gradient.jpg"): + from PIL import Image + img = Image.new("L", (100, 100)) + pixels = img.load() + for y in range(100): + for x in range(100): + pixels[x, y] = x * 255 // 100 + p = tmp_path / name + img.convert("RGB").save(p) + return str(p) + + +def make_diagonal_image(tmp_path, name="diagonal.jpg"): + from PIL import Image + img = Image.new("L", (100, 100)) + pixels = img.load() + for y in range(100): + for x in range(100): + pixels[x, y] = 255 if x > y else 0 + p = tmp_path / name + img.convert("RGB").save(p) + return str(p) + + def test_identical_images_are_duplicates(tmp_path): - p1 = make_test_image(tmp_path, color=(100, 150, 200)) + p1 = make_gradient_image(tmp_path, "img1.jpg") import shutil p2 = tmp_path / "copy.jpg" shutil.copy(p1, p2) - groups = find_duplicates([p1, str(p2)], threshold=0) + groups = find_duplicates([p1, str(p2)], threshold=8) assert len(groups) == 1 assert len(groups[0]) == 2 def test_different_images_are_not_duplicates(tmp_path): - from PIL import Image - p1 = make_test_image(tmp_path, color=(0, 0, 0)) - img = Image.new("RGB", (100, 100), color=(255, 0, 0)) - p2 = tmp_path / "red.jpg" - img.save(p2) - groups = find_duplicates([p1, str(p2)], threshold=0) + p1 = make_gradient_image(tmp_path, "gradient.jpg") + p2 = make_diagonal_image(tmp_path, "diagonal.jpg") + groups = find_duplicates([p1, p2], threshold=8) assert len(groups) == 0