use super::parser::{BoardParser, BoardPrinter, BoardResizer};
use crate::Tessellation;
pub struct TriobanBoardParser {}
impl BoardParser for TriobanBoardParser {}
impl BoardPrinter for TriobanBoardParser {}
impl BoardResizer for TriobanBoardParser {
const TESSELLATION: Tessellation = Tessellation::Trioban;
}
#[cfg(test)]
mod tests {
use super::super::*;
mod test_rotation {
use super::*;
#[rustfmt::skip]
#[test]
fn it_rotates_every_cell_to_its_computed_position() -> Result<(), BoardSyntaxError> {
const WIDTH: usize = 4;
const HEIGHT: usize = 2;
let expectations: [((usize, usize), (usize, usize)); 8] = [
((0, 0), (3, 0)), ((1, 0), (3, 1)), ((2, 0), (4, 1)), ((3, 0), (4, 2)),
((0, 1), (1, 1)), ((1, 1), (2, 1)), ((2, 1), (2, 2)), ((3, 1), (3, 2)),
];
for ((x, y), wanted) in expectations {
let mut tiles = [TileKind::Floor; WIDTH * HEIGHT];
tiles[y * WIDTH + x] = TileKind::Wall;
let mut board =
GameBoard::parsed_from_tiles(&tiles, WIDTH, HEIGHT, Tessellation::Trioban)?;
board.rotate(Rotation::Clockwise);
assert_eq!((board.width(), board.height()), (5, 3));
assert_eq!(
board.iter().find(|(_, tile)| *tile == TileKind::Wall).map(|(at, _)| at),
Some(wanted),
"the cell at ({x}, {y})"
);
}
Ok(())
}
}
}