Use 'ChessBoardBuilder' in validation tests
The various tests for overlapping can't be triggered with the builder API, so those have stayed unchanged.
This commit is contained in:
parent
1cf05b5f55
commit
a676094dc1
|
@ -634,238 +634,95 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_multiple_kings() {
|
fn invalid_multiple_kings() {
|
||||||
let position = ChessBoard {
|
let res = {
|
||||||
piece_occupancy: [
|
let mut builder = ChessBoardBuilder::new();
|
||||||
// King
|
builder[Square::E1] = Some((Piece::King, Color::White));
|
||||||
Square::E1 | Square::E2 | Square::E7 | Square::E8,
|
builder[Square::E2] = Some((Piece::King, Color::White));
|
||||||
// Queen
|
builder[Square::E7] = Some((Piece::King, Color::Black));
|
||||||
Bitboard::EMPTY,
|
builder[Square::E8] = Some((Piece::King, Color::Black));
|
||||||
// Rook
|
TryInto::<ChessBoard>::try_into(builder)
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Bishop
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Knight
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Pawn
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
],
|
|
||||||
color_occupancy: [Square::E1 | Square::E2, Square::E7 | Square::E8],
|
|
||||||
combined_occupancy: Square::E1 | Square::E2 | Square::E7 | Square::E8,
|
|
||||||
castle_rights: [CastleRights::NoSide; 2],
|
|
||||||
en_passant: None,
|
|
||||||
half_move_clock: 0,
|
|
||||||
total_plies: 0,
|
|
||||||
side: Color::White,
|
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(res.err().unwrap(), InvalidError::TooManyPieces);
|
||||||
position.validate().err().unwrap(),
|
|
||||||
InvalidError::TooManyPieces,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_castling_rights_no_rooks() {
|
fn invalid_castling_rights_no_rooks() {
|
||||||
let position = ChessBoard {
|
let res = {
|
||||||
piece_occupancy: [
|
let mut builder = ChessBoardBuilder::new();
|
||||||
// King
|
builder[Square::E1] = Some((Piece::King, Color::White));
|
||||||
Square::E1 | Square::E8,
|
builder[Square::E8] = Some((Piece::King, Color::Black));
|
||||||
// Queen
|
builder.with_castle_rights(CastleRights::BothSides, Color::White);
|
||||||
Bitboard::EMPTY,
|
TryInto::<ChessBoard>::try_into(builder)
|
||||||
// Rook
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Bishop
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Knight
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Pawn
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
],
|
|
||||||
color_occupancy: [Square::E1.into_bitboard(), Square::E8.into_bitboard()],
|
|
||||||
combined_occupancy: Square::E1 | Square::E8,
|
|
||||||
castle_rights: [CastleRights::BothSides; 2],
|
|
||||||
en_passant: None,
|
|
||||||
half_move_clock: 0,
|
|
||||||
total_plies: 0,
|
|
||||||
side: Color::White,
|
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(res.err().unwrap(), InvalidError::InvalidCastlingRights);
|
||||||
position.validate().err().unwrap(),
|
|
||||||
InvalidError::InvalidCastlingRights,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_castling_rights_moved_king() {
|
fn invalid_castling_rights_moved_king() {
|
||||||
let position = ChessBoard {
|
let res = {
|
||||||
piece_occupancy: [
|
let mut builder = ChessBoardBuilder::new();
|
||||||
// King
|
builder[Square::E2] = Some((Piece::King, Color::White));
|
||||||
Square::E2 | Square::E7,
|
builder[Square::A1] = Some((Piece::Rook, Color::White));
|
||||||
// Queen
|
builder[Square::H1] = Some((Piece::Rook, Color::White));
|
||||||
Bitboard::EMPTY,
|
builder[Square::E7] = Some((Piece::King, Color::Black));
|
||||||
// Rook
|
builder[Square::A8] = Some((Piece::Rook, Color::Black));
|
||||||
Square::A1 | Square::A8 | Square::H1 | Square::H8,
|
builder[Square::H8] = Some((Piece::Rook, Color::Black));
|
||||||
// Bishop
|
builder.with_castle_rights(CastleRights::BothSides, Color::White);
|
||||||
Bitboard::EMPTY,
|
TryInto::<ChessBoard>::try_into(builder)
|
||||||
// Knight
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Pawn
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
],
|
|
||||||
color_occupancy: [
|
|
||||||
Square::A1 | Square::E2 | Square::H1,
|
|
||||||
Square::A8 | Square::E7 | Square::H8,
|
|
||||||
],
|
|
||||||
combined_occupancy: Square::A1
|
|
||||||
| Square::A8
|
|
||||||
| Square::E2
|
|
||||||
| Square::E7
|
|
||||||
| Square::H1
|
|
||||||
| Square::H8,
|
|
||||||
castle_rights: [CastleRights::BothSides; 2],
|
|
||||||
en_passant: None,
|
|
||||||
half_move_clock: 0,
|
|
||||||
total_plies: 0,
|
|
||||||
side: Color::White,
|
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(res.err().unwrap(), InvalidError::InvalidCastlingRights);
|
||||||
position.validate().err().unwrap(),
|
|
||||||
InvalidError::InvalidCastlingRights,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_kings_next_to_each_other() {
|
fn invalid_kings_next_to_each_other() {
|
||||||
let position = ChessBoard {
|
let res = {
|
||||||
piece_occupancy: [
|
let mut builder = ChessBoardBuilder::new();
|
||||||
// King
|
builder[Square::E1] = Some((Piece::King, Color::White));
|
||||||
Square::E2 | Square::E3,
|
builder[Square::E2] = Some((Piece::King, Color::Black));
|
||||||
// Queen
|
TryInto::<ChessBoard>::try_into(builder)
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Rook
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Bishop
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Knight
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Pawn
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
],
|
|
||||||
color_occupancy: [Square::E2.into_bitboard(), Square::E3.into_bitboard()],
|
|
||||||
combined_occupancy: Square::E2 | Square::E3,
|
|
||||||
castle_rights: [CastleRights::NoSide; 2],
|
|
||||||
en_passant: None,
|
|
||||||
half_move_clock: 0,
|
|
||||||
total_plies: 0,
|
|
||||||
side: Color::White,
|
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(res.err().unwrap(), InvalidError::NeighbouringKings);
|
||||||
position.validate().err().unwrap(),
|
|
||||||
InvalidError::NeighbouringKings,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_opponent_in_check() {
|
fn invalid_opponent_in_check() {
|
||||||
let position = ChessBoard {
|
let res = {
|
||||||
piece_occupancy: [
|
let mut builder = ChessBoardBuilder::new();
|
||||||
// King
|
builder[Square::E1] = Some((Piece::King, Color::White));
|
||||||
Square::E1 | Square::E8,
|
builder[Square::E7] = Some((Piece::Queen, Color::White));
|
||||||
// Queen
|
builder[Square::E8] = Some((Piece::King, Color::Black));
|
||||||
Square::E7.into_bitboard(),
|
TryInto::<ChessBoard>::try_into(builder)
|
||||||
// Rook
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Bishop
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Knight
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Pawn
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
],
|
|
||||||
color_occupancy: [Square::E1 | Square::E7, Square::E8.into_bitboard()],
|
|
||||||
combined_occupancy: Square::E1 | Square::E7 | Square::E8,
|
|
||||||
castle_rights: [CastleRights::NoSide; 2],
|
|
||||||
en_passant: None,
|
|
||||||
half_move_clock: 0,
|
|
||||||
total_plies: 0,
|
|
||||||
side: Color::White,
|
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(res.err().unwrap(), InvalidError::OpponentInCheck);
|
||||||
position.validate().err().unwrap(),
|
|
||||||
InvalidError::OpponentInCheck,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_pawn_on_first_rank() {
|
fn invalid_pawn_on_first_rank() {
|
||||||
let position = ChessBoard {
|
let res = {
|
||||||
piece_occupancy: [
|
let mut builder = ChessBoardBuilder::new();
|
||||||
// King
|
builder[Square::H1] = Some((Piece::King, Color::White));
|
||||||
Square::H1 | Square::H8,
|
builder[Square::A1] = Some((Piece::Pawn, Color::White));
|
||||||
// Queen
|
builder[Square::H8] = Some((Piece::King, Color::Black));
|
||||||
Bitboard::EMPTY,
|
TryInto::<ChessBoard>::try_into(builder)
|
||||||
// Rook
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Bishop
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Knight
|
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Pawn
|
|
||||||
Square::A1.into_bitboard(),
|
|
||||||
],
|
|
||||||
color_occupancy: [Square::A1 | Square::H1, Square::H8.into_bitboard()],
|
|
||||||
combined_occupancy: Square::A1 | Square::H1 | Square::H8,
|
|
||||||
castle_rights: [CastleRights::NoSide; 2],
|
|
||||||
en_passant: None,
|
|
||||||
half_move_clock: 0,
|
|
||||||
total_plies: 0,
|
|
||||||
side: Color::White,
|
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(res.err().unwrap(), InvalidError::InvalidPawnPosition);
|
||||||
position.validate().err().unwrap(),
|
|
||||||
InvalidError::InvalidPawnPosition,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_too_many_pieces() {
|
fn invalid_too_many_pieces() {
|
||||||
let position = ChessBoard {
|
let res = {
|
||||||
piece_occupancy: [
|
let mut builder = ChessBoardBuilder::new();
|
||||||
// King
|
builder[Square::H1] = Some((Piece::King, Color::White));
|
||||||
Square::H1 | Square::H8,
|
builder[Square::H8] = Some((Piece::King, Color::Black));
|
||||||
// Queen
|
for square in (File::B.into_bitboard() | File::C.into_bitboard()).into_iter() {
|
||||||
Bitboard::EMPTY,
|
builder[square] = Some((Piece::Pawn, Color::White));
|
||||||
// Rook
|
}
|
||||||
Bitboard::EMPTY,
|
for square in (File::F.into_bitboard() | File::G.into_bitboard()).into_iter() {
|
||||||
// Bishop
|
builder[square] = Some((Piece::Pawn, Color::Black));
|
||||||
Bitboard::EMPTY,
|
}
|
||||||
// Knight
|
TryInto::<ChessBoard>::try_into(builder)
|
||||||
Bitboard::EMPTY,
|
|
||||||
// Pawn
|
|
||||||
File::B.into_bitboard()
|
|
||||||
| File::C.into_bitboard()
|
|
||||||
| File::D.into_bitboard()
|
|
||||||
| File::E.into_bitboard(),
|
|
||||||
],
|
|
||||||
color_occupancy: [
|
|
||||||
File::B.into_bitboard() | File::C.into_bitboard() | Square::H1,
|
|
||||||
File::D.into_bitboard() | File::E.into_bitboard() | Square::H8,
|
|
||||||
],
|
|
||||||
combined_occupancy: File::B.into_bitboard()
|
|
||||||
| File::C.into_bitboard()
|
|
||||||
| File::D.into_bitboard()
|
|
||||||
| File::E.into_bitboard()
|
|
||||||
| Square::H1
|
|
||||||
| Square::H8,
|
|
||||||
castle_rights: [CastleRights::NoSide; 2],
|
|
||||||
en_passant: None,
|
|
||||||
half_move_clock: 0,
|
|
||||||
total_plies: 0,
|
|
||||||
side: Color::White,
|
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(res.err().unwrap(), InvalidError::TooManyPieces);
|
||||||
position.validate().err().unwrap(),
|
|
||||||
InvalidError::TooManyPieces,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue