From 8d75a40475c39f4108fbbce259f6eae7a2649630 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Sat, 23 Aug 2025 13:27:39 -0500 Subject: [PATCH] Add unit tests for transposition --- src/card.rs | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/src/card.rs b/src/card.rs index 73b82fc..84704bf 100644 --- a/src/card.rs +++ b/src/card.rs @@ -619,14 +619,97 @@ mod test { assert_eq!(result, expected); } + /// Test transposition on column 1 #[test] fn transpose_vertical() { - todo!(); + let left_shape = Card { + cells: OCTAGON, + ..Default::default() + }; + + // It's a small NW triangle. + let right_shape = Card { + #[rustfmt::skip] + cells: [ + Cell::Filled, Cell::Empty, Cell::Empty, + Cell::SE, Cell::Empty, Cell::NW, + Cell::Empty, Cell::NW, Cell::Filled, + ], + ..Default::default() + }; + + let expected_left = Card { + #[rustfmt::skip] + cells: [ + Cell::Filled, Cell::Filled, Cell::NE, + Cell::SE, Cell::Filled, Cell::Filled, + Cell::Empty, Cell::Filled, Cell::SE, + ], + ..Default::default() + }; + + let expected_right = Card { + #[rustfmt::skip] + cells: [ + Cell::NW, Cell::Empty, Cell::Empty, + Cell::Filled, Cell::Empty, Cell::NW, + Cell::SW, Cell::NW, Cell::Filled, + ], + ..Default::default() + }; + + let (res_left, res_right) = left_shape.transpose( + right_shape, + TransposeSelection::Column(TransposeIndex::First), + ); + assert_eq!(res_left, expected_left); + assert_eq!(res_right, expected_right); } + /// Test transposition on row 3 #[test] fn transpose_horizontal() { - todo!(); + let left_shape = Card { + cells: OCTAGON, + ..Default::default() + }; + + let right_shape = Card { + #[rustfmt::skip] + cells: [ + Cell::Filled, Cell::Empty, Cell::Empty, + Cell::SE, Cell::Empty, Cell::NW, + Cell::Empty, Cell::NW, Cell::Filled, + ], + ..Default::default() + }; + + let expected_left = Card { + #[rustfmt::skip] + cells: [ + Cell::NW, Cell::Filled, Cell::NE, + Cell::Filled, Cell::Filled, Cell::Filled, + Cell::Empty, Cell::NW, Cell::Filled, + ], + ..Default::default() + }; + + let expected_right = Card { + #[rustfmt::skip] + cells: [ + Cell::Filled, Cell::Empty, Cell::Empty, + Cell::SE, Cell::Empty, Cell::NW, + Cell::SW, Cell::Filled, Cell::SE, + ], + ..Default::default() + }; + + let (res_left, res_right) = left_shape.transpose( + right_shape, + TransposeSelection::Row(TransposeIndex::Third), + ); + assert_eq!(res_left, expected_left); + assert_eq!(res_right, expected_right); } #[test]