- chunk_name: Reject float/bool indices like JavaScript (Number.isInteger) - parse_chunk_name: Use fullmatch instead of match($) to reject strings with trailing newlines - Add invalidIndices fixture cases to catch these edge cases in both languages Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
import json
|
|
from pathlib import Path
|
|
|
|
from leonida.coords import SLICE, chunk_name, parse_chunk_name, pixel_to_world, slice_tiles, tile_for_world
|
|
|
|
# Derselbe Beispielsatz wie tests/coords.test.js — JavaScript und Python dürfen nicht auseinanderlaufen.
|
|
NAMES = json.loads((Path(__file__).resolve().parents[3] / "tests/fixtures/chunk-names.json").read_text())
|
|
|
|
def test_tile_of_vice_beach():
|
|
assert tile_for_world(1409.4, 2803.2) == (53, 69)
|
|
|
|
def test_slice_covers_expected_grid():
|
|
tiles = slice_tiles()
|
|
assert len(tiles) == 144
|
|
assert min(c for _, c in tiles) == 60 and max(c for _, c in tiles) == 71
|
|
assert min(r for r, _ in tiles) == 54 and max(r for r, _ in tiles) == 65
|
|
|
|
def test_pixel_origin_is_slice_corner():
|
|
# Pixel (0,0) des beschnittenen Mosaiks ist die Nordwest-Ecke des Ausschnitts.
|
|
assert pixel_to_world(0, 0) == (SLICE["x0"], SLICE["y1"])
|
|
assert pixel_to_world(2999, 2999) == (SLICE["x0"] + 2999, SLICE["y1"] - 2999)
|
|
|
|
|
|
def test_chunk_names_match_the_shared_examples():
|
|
for name, i, j in NAMES["pairs"]:
|
|
assert chunk_name(i, j) == name
|
|
assert parse_chunk_name(name) == (i, j)
|
|
|
|
|
|
def test_chunk_names_accept_lowercase():
|
|
for name, i, j in NAMES["lowercase"]:
|
|
assert parse_chunk_name(name) == (i, j)
|
|
|
|
|
|
def test_chunk_names_reject_everything_outside_a1_to_l12():
|
|
for name in NAMES["invalid"]:
|
|
assert parse_chunk_name(name) is None
|
|
assert chunk_name(12, 0) is None
|
|
assert chunk_name(0, -1) is None
|
|
|
|
|
|
def test_chunk_names_round_trip_for_all_144_chunks():
|
|
for i in range(12):
|
|
for j in range(12):
|
|
assert parse_chunk_name(chunk_name(i, j)) == (i, j)
|
|
|
|
|
|
def test_chunk_names_reject_invalid_index_types():
|
|
for i, j in NAMES["invalidIndices"]:
|
|
assert chunk_name(i, j) is None
|