Spaces:
Running on Zero
Running on Zero
Download test_geometry.py from Dekonstruktio/Scale: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/Dekonstruktio/Scale/resolve/main/test_geometry.py
- Command line
-
hf download hf://spaces/Dekonstruktio/Scale/test_geometry.py
-
curl -L -o test_geometry.py https://huggingface.co/spaces/Dekonstruktio/Scale/resolve/main/test_geometry.py
1.32 kB
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parent)) | |
| import numpy as np | |
| import pytest | |
| from geometry import output_size, padded_size, tile_coordinates | |
| def test_tiles_cover_every_pixel_without_stretching(width, height): | |
| pw, ph = padded_size(width, height) | |
| coverage = np.zeros((ph // 8, pw // 8), dtype=np.uint8) | |
| coords = tile_coordinates(ph // 8, pw // 8, 64, 64, 8) | |
| assert coords | |
| for y,x in coords: | |
| assert x % 2 == y % 2 == 0 | |
| assert coverage[y:y+64,x:x+64].shape == (64,64) | |
| coverage[y:y+64,x:x+64] += 1 | |
| assert coverage.min() > 0 | |
| def test_exact_output_dimensions(width,height,size,expected): | |
| assert output_size(width,height,size) == expected | |
| def test_rejects_oversized_output(): | |
| with pytest.raises(ValueError): | |
| output_size(4096,4096,'4×') | |
| def test_final_tiles_are_anchored_at_border(): | |
| coords = tile_coordinates(256,256,64,64,8) | |
| assert coords[-1] == (192,192) | |
| assert len(coords) == 25 | |