Use 'ChessBoardBuilder' in more validation tests

This commit is contained in:
Bruno BELANYI 2024-04-03 20:07:50 +01:00
parent 388c26f4ac
commit 6f161d067d

View file

@ -463,28 +463,13 @@ mod test {
#[test] #[test]
fn invalid_overlapping_pieces() { fn invalid_overlapping_pieces() {
let position = ChessBoard { let position = {
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 let mut board: ChessBoard = builder.try_into().unwrap();
Square::E1 | Square::E8, *board.piece_occupancy_mut(Piece::Queen) |= Square::E1.into_bitboard();
// Rook board
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::NoSide; 2],
en_passant: None,
half_move_clock: 0,
total_plies: 0,
side: Color::White,
}; };
assert_eq!( assert_eq!(
position.validate().err().unwrap(), position.validate().err().unwrap(),
@ -494,28 +479,13 @@ mod test {
#[test] #[test]
fn invalid_overlapping_colors() { fn invalid_overlapping_colors() {
let position = ChessBoard { let position = {
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 let mut board: ChessBoard = builder.try_into().unwrap();
Bitboard::EMPTY, *board.color_occupancy_mut(Color::White) |= Square::E8.into_bitboard();
// Rook board
Bitboard::EMPTY,
// Bishop
Bitboard::EMPTY,
// Knight
Bitboard::EMPTY,
// Pawn
Bitboard::EMPTY,
],
color_occupancy: [Square::E1 | Square::E8, Square::E1 | Square::E8],
combined_occupancy: Square::E1 | Square::E8,
castle_rights: [CastleRights::NoSide; 2],
en_passant: None,
half_move_clock: 0,
total_plies: 0,
side: Color::White,
}; };
assert_eq!( assert_eq!(
position.validate().err().unwrap(), position.validate().err().unwrap(),
@ -525,28 +495,13 @@ mod test {
#[test] #[test]
fn invalid_combined_does_not_equal_pieces() { fn invalid_combined_does_not_equal_pieces() {
let position = ChessBoard { let position = {
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 let mut board: ChessBoard = builder.try_into().unwrap();
Bitboard::EMPTY, *board.piece_occupancy_mut(Piece::Pawn) |= Square::E2.into_bitboard();
// Rook board
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.into_bitboard(),
castle_rights: [CastleRights::NoSide; 2],
en_passant: None,
half_move_clock: 0,
total_plies: 0,
side: Color::White,
}; };
assert_eq!( assert_eq!(
position.validate().err().unwrap(), position.validate().err().unwrap(),
@ -556,28 +511,13 @@ mod test {
#[test] #[test]
fn invalid_combined_does_not_equal_colors() { fn invalid_combined_does_not_equal_colors() {
let position = ChessBoard { let position = {
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 let mut board: ChessBoard = builder.try_into().unwrap();
Bitboard::EMPTY, *board.color_occupancy_mut(Color::Black) |= Square::E2.into_bitboard();
// Rook board
Bitboard::EMPTY,
// Bishop
Bitboard::EMPTY,
// Knight
Bitboard::EMPTY,
// Pawn
Bitboard::EMPTY,
],
color_occupancy: [Square::E1 | Square::H1, Square::E8 | Square::H8],
combined_occupancy: Square::E1 | Square::E8,
castle_rights: [CastleRights::NoSide; 2],
en_passant: None,
half_move_clock: 0,
total_plies: 0,
side: Color::White,
}; };
assert_eq!( assert_eq!(
position.validate().err().unwrap(), position.validate().err().unwrap(),