[board] Implement a test_position macro that prints a Position after it builds it

Update the sight tests to use test_position!
Remove a stray leftover mut.
Clean up the test imports.
This commit is contained in:
Eryn Wells 2024-01-21 13:06:44 -08:00
parent 3c699b0b3d
commit 704ee2f425
2 changed files with 21 additions and 5 deletions

View file

@ -18,3 +18,17 @@ macro_rules! position {
.build()
};
}
#[cfg(test)]
#[macro_export]
macro_rules! test_position {
[$($color:ident $shape:ident on $square:ident),* $(,)?] => {
{
let pos = $crate::PositionBuilder::new()
$(.place_piece(piece!($color $shape on $square)))*
.build();
println!("{pos}");
pos
}
};
}

View file

@ -174,13 +174,13 @@ mod tests {
}
mod pawn {
use crate::{position, sight::Sight, BitBoard, Position, Square};
use crate::{sight::Sight, BitBoard, Square};
sight_test!(e4_pawn, piece!(White Pawn on E4), bitboard!(D5, F5));
sight_test!(
e4_pawn_one_blocker,
position![
test_position![
White Bishop on D5,
White Pawn on E4,
],
@ -190,11 +190,12 @@ mod tests {
#[test]
fn e4_pawn_two_blocker() {
let pos = position!(
let pos = test_position!(
White Bishop on D5,
White Queen on F5,
White Pawn on E4,
);
let pp = piece!(White Pawn on E4);
let sight = pp.sight_in_position(&pos);
@ -203,11 +204,12 @@ mod tests {
#[test]
fn e4_pawn_capturable() {
let pos = position!(
let pos = test_position!(
Black Bishop on D5,
White Queen on F5,
White Pawn on E4,
);
let pp = piece!(White Pawn on E4);
let sight = pp.sight_in_position(&pos);
@ -216,7 +218,7 @@ mod tests {
#[test]
fn e5_en_passant() {
let mut pos = position!(
let mut pos = test_position!(
White Pawn on E5,
Black Pawn on D5,
);