# SPDX-License-Identifier: MIT """Saved pictures follow the cart's rotation field (lynx_python.picture). The direction was decided by looking at Klax (right) and Centipede (Proto) (left) on this board (docs/validation.md "Saved pictures follow the cart's rotation"); these tests pin it so a reversed turn fails here. """ from lynx_python.picture import HEIGHT, WIDTH, rotate def _marked() -> bytes: rgb = bytearray(WIDTH * HEIGHT * 3) rgb[0:3] = b"\xff\x00\x00" # top-left red end = 3 * (WIDTH - 1) rgb[end : end + 3] = b"\x00\xff\x00" # top-right green return bytes(rgb) def _at(rgb: bytes, width: int, x: int, y: int) -> bytes: return rgb[3 * (y * width + x) : 3 * (y * width + x) + 3] def test_none_is_unchanged() -> None: rgb = _marked() assert rotate(rgb, "none") == (rgb, WIDTH, HEIGHT) def test_right_is_a_quarter_turn_clockwise() -> None: out, w, h = rotate(_marked(), "right") assert (w, h) == (HEIGHT, WIDTH) assert _at(out, w, w - 1, 0) == b"\xff\x00\x00" # top-left went to top-right assert _at(out, w, w - 1, h - 1) == b"\x00\xff\x00" # top-right went to bottom-right def test_left_is_a_quarter_turn_anticlockwise() -> None: out, w, h = rotate(_marked(), "left") assert (w, h) == (HEIGHT, WIDTH) assert _at(out, w, 0, h - 1) == b"\xff\x00\x00" # top-left went to bottom-left assert _at(out, w, 0, 0) == b"\x00\xff\x00" # top-right went to top-left