diff --git a/src/card.rs b/src/card.rs index 1340851..531206a 100644 --- a/src/card.rs +++ b/src/card.rs @@ -191,21 +191,61 @@ mod test { assert!(extra_doors.is_none()); } - /// Merging two corner cells together results in the upper cell coming through. + /// Merging two triangular [`Cell`]s should prefer the top-most one, *unless* + /// they are opposites. See test [`merge_opposite_triangles()`]. #[test] fn merge_triangle_and_triangle() { - todo!(); + let mut top = Card::default(); + top.cells[0] = Cell::NW; + + let mut bottom = Card::default(); + bottom.cells[0] = Cell::NE; + + let expected = top.clone(); + + let (stacked, doors) = bottom.merge(top); + assert_eq!(stacked, expected); + assert!(doors.is_none()); } /// Merging a filled cell with anything should result in [`Cell::Filled`]. #[test] fn merge_triangle_and_filled() { - todo!(); + let filled = Card { + cells: FULL_SQUARE, + ..Default::default() + }; + let triangle = Card { + cells: NW_TRIANGLE, + ..Default::default() + }; + + let expected = filled.clone(); + + // Check the merge in both directions. + let result_fill_over_tri = triangle.merge(filled); + let result_tri_over_fill = filled.merge(triangle); + + assert_eq!(expected, result_fill_over_tri.0); + assert_eq!(expected, result_tri_over_fill.0); + assert!(result_fill_over_tri.1.is_none()); + assert!(result_tri_over_fill.1.is_none()); } /// Merging a NW and SE cell should result in a single [`Cell::Filled`]. #[test] fn merge_opposite_triangles() { - todo!(); + let mut top = Card::default(); + top.cells[0] = Cell::NW; + + let mut bottom = Card::default(); + bottom.cells[0] = Cell::SE; + + let mut expected = Card::default(); + expected.cells[0] = Cell::Filled; + + let (stacked, doors) = bottom.merge(top); + assert_eq!(stacked, expected); + assert!(doors.is_none()); } }