Add tests for en-passant validation
All checks were successful
ci/woodpecker/push/check Pipeline was successful
All checks were successful
ci/woodpecker/push/check Pipeline was successful
This commit is contained in:
parent
385629b3a9
commit
1f52bb9346
|
@ -588,6 +588,56 @@ mod test {
|
|||
assert_eq!(res.err().unwrap(), InvalidError::InvalidCastlingRights);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_en_passant() {
|
||||
let mut builder = ChessBoardBuilder::new();
|
||||
builder[Square::E1] = Some((Piece::King, Color::White));
|
||||
builder[Square::E8] = Some((Piece::King, Color::Black));
|
||||
builder[Square::A5] = Some((Piece::Pawn, Color::Black));
|
||||
builder.with_en_passant(Square::A6);
|
||||
TryInto::<ChessBoard>::try_into(builder).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_en_passant_not_empty() {
|
||||
let res = {
|
||||
let mut builder = ChessBoardBuilder::new();
|
||||
builder[Square::E1] = Some((Piece::King, Color::White));
|
||||
builder[Square::E8] = Some((Piece::King, Color::Black));
|
||||
builder[Square::A6] = Some((Piece::Rook, Color::Black));
|
||||
builder[Square::A5] = Some((Piece::Pawn, Color::Black));
|
||||
builder.with_en_passant(Square::A6);
|
||||
TryInto::<ChessBoard>::try_into(builder)
|
||||
};
|
||||
assert_eq!(res.err().unwrap(), InvalidError::InvalidEnPassant);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_en_passant_not_behind_pawn() {
|
||||
let res = {
|
||||
let mut builder = ChessBoardBuilder::new();
|
||||
builder[Square::E1] = Some((Piece::King, Color::White));
|
||||
builder[Square::E8] = Some((Piece::King, Color::Black));
|
||||
builder[Square::A5] = Some((Piece::Rook, Color::Black));
|
||||
builder.with_en_passant(Square::A6);
|
||||
TryInto::<ChessBoard>::try_into(builder)
|
||||
};
|
||||
assert_eq!(res.err().unwrap(), InvalidError::InvalidEnPassant);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_en_passant_incorrect_rank() {
|
||||
let res = {
|
||||
let mut builder = ChessBoardBuilder::new();
|
||||
builder[Square::E1] = Some((Piece::King, Color::White));
|
||||
builder[Square::E8] = Some((Piece::King, Color::Black));
|
||||
builder[Square::A4] = Some((Piece::Pawn, Color::Black));
|
||||
builder.with_en_passant(Square::A5);
|
||||
TryInto::<ChessBoard>::try_into(builder)
|
||||
};
|
||||
assert_eq!(res.err().unwrap(), InvalidError::InvalidEnPassant);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_kings_next_to_each_other() {
|
||||
let res = {
|
||||
|
|
Loading…
Reference in a new issue