Add test that cells() can be equal for different rotation states

This commit is contained in:
tali 2022-12-14 14:39:36 -05:00
parent 1dcf36ef6f
commit b3d9e3c476
1 changed files with 31 additions and 0 deletions

View File

@ -193,4 +193,35 @@ mod test {
assert_eq!(piece.loc.y, 1);
assert_eq!(piece.loc.r, Rot::E);
}
#[test]
fn test_srs_cells_eq() {
fn rotate(s: Shape, dir: input::Spin) -> Piece {
let mut piece = Piece::spawn(s);
input::rotate(&mut piece, Mat::EMPTY, dir).unwrap();
piece
}
for s in [Shape::S, Shape::Z, Shape::I] {
let cw = rotate(s, input::Spin::Cw);
let ccw = rotate(s, input::Spin::Ccw);
// rotation states differ
assert_ne!(cw.loc.r, ccw.loc.r, "shape={s:?}");
// cells() are equal after translating, since they occupy the same blocks
assert_eq!(cw.cells().translate(-1, 0), ccw.cells(), "shape={s:?}");
}
}
#[test]
fn test_o_cells_eq() {
fn cells(x: i16, y: i16, r: Rot) -> Cells<'static> {
Piece {
shape: Shape::O,
loc: Loc { x, y, r },
}
.cells()
}
assert_eq!(cells(0, 0, Rot::N), cells(0, 1, Rot::E));
assert_eq!(cells(0, 0, Rot::N), cells(1, 1, Rot::S));
assert_eq!(cells(0, 0, Rot::N), cells(1, 0, Rot::W));
}
}