Move position::tests → testing

Expand information printed in assert_move_list
This commit is contained in:
Eryn Wells 2024-02-25 09:20:45 -08:00
parent 9b7bf3a212
commit 36db46ac18
3 changed files with 59 additions and 35 deletions

58
position/src/testing.rs Normal file
View file

@ -0,0 +1,58 @@
// Eryn Wells <eryn@erynwells.me>
use crate::MakeMoveError;
use chessfriend_moves::{BuildMoveError, BuildMoveResult, Move};
#[macro_export]
macro_rules! assert_move_list {
($generated:expr, $expected:expr, $position:expr) => {
assert_eq!(
$generated,
$expected,
"\n\tMatching: {:?}\n\tGenerated, not expected: {:?}\n\tExpected, not generated: {:?}",
$generated
.intersection(&$expected)
.map(|mv| format!("{}", mv))
.collect::<Vec<String>>(),
$generated
.difference(&$expected)
.map(|mv| format!("{}", mv))
.collect::<Vec<String>>(),
$expected
.difference(&$generated)
.map(|mv| format!("{}", mv))
.collect::<Vec<String>>(),
)
};
}
#[macro_export]
macro_rules! formatted_move_list {
($move_list:expr, $position:expr) => {
$move_list
.iter()
.map(|mv| format!("{}", mv))
.collect::<Vec<String>>()
};
}
pub type TestResult = Result<(), TestError>;
#[derive(Debug, Eq, PartialEq)]
pub enum TestError {
BuildMove(BuildMoveError),
MakeMove(MakeMoveError),
NoLegalMoves,
}
impl From<BuildMoveError> for TestError {
fn from(value: BuildMoveError) -> Self {
TestError::BuildMove(value)
}
}
impl From<MakeMoveError> for TestError {
fn from(value: MakeMoveError) -> Self {
TestError::MakeMove(value)
}
}