Add unit tests for Card floor merging

Do some quick checks to make sure the merging function works the way we
expect. This also records how some edge cases will be handled, such as
merging two triangles.
This commit is contained in:
2025-08-22 18:59:00 -05:00
committed by Patrick Gelvin
parent 6bbc31304e
commit b3b8d1a814

View File

@@ -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());
}
}