// SPDX-License-Identifier: MIT //! Saved pictures follow the cart's rotation field (the reference's tests/test_picture.py). //! //! The direction was decided by looking at Klax (right) and Centipede (Proto) (left) on //! the reference board (its docs/validation.md "Saved pictures follow the cart's rotation"); //! these tests pin it so a reversed turn fails here. use lynx::picture::{rotate, HEIGHT, WIDTH}; fn marked() -> Vec { let mut rgb = vec![0u8; WIDTH * HEIGHT * 3]; rgb[0..3].copy_from_slice(&[0xFF, 0, 0]); // top-left red let end = 3 * (WIDTH - 1); rgb[end..end + 3].copy_from_slice(&[0, 0xFF, 0]); // top-right green rgb } fn at(rgb: &[u8], width: usize, x: usize, y: usize) -> &[u8] { &rgb[3 * (y * width + x)..3 * (y * width + x) + 3] } #[test] fn none_is_unchanged() { let rgb = marked(); assert_eq!(rotate(&rgb, "none", WIDTH, HEIGHT), (rgb, WIDTH, HEIGHT)); } #[test] fn right_is_a_quarter_turn_clockwise() { let (out, w, h) = rotate(&marked(), "right", WIDTH, HEIGHT); assert_eq!((w, h), (HEIGHT, WIDTH)); assert_eq!(at(&out, w, w - 1, 0), [0xFF, 0, 0]); // top-left went to top-right assert_eq!(at(&out, w, w - 1, h - 1), [0, 0xFF, 0]); // top-right went to bottom-right } #[test] fn left_is_a_quarter_turn_anticlockwise() { let (out, w, h) = rotate(&marked(), "left", WIDTH, HEIGHT); assert_eq!((w, h), (HEIGHT, WIDTH)); assert_eq!(at(&out, w, 0, h - 1), [0xFF, 0, 0]); // top-left went to bottom-left assert_eq!(at(&out, w, 0, 0), [0, 0xFF, 0]); // top-right went to top-left }