Move position::tests → testing
Expand information printed in assert_move_list
This commit is contained in:
parent
9b7bf3a212
commit
36db46ac18
3 changed files with 59 additions and 35 deletions
|
@ -13,7 +13,7 @@ mod sight;
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod tests;
|
mod testing;
|
||||||
|
|
||||||
pub use position::{MoveBuilder as MakeMoveBuilder, Position, PositionBuilder};
|
pub use position::{MoveBuilder as MakeMoveBuilder, Position, PositionBuilder};
|
||||||
pub use r#move::{Castle, MakeMoveError, Move, MoveBuilder};
|
pub use r#move::{Castle, MakeMoveError, Move, MoveBuilder};
|
||||||
|
|
58
position/src/testing.rs
Normal file
58
position/src/testing.rs
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,34 +0,0 @@
|
||||||
// Eryn Wells <eryn@erynwells.me>
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! assert_move_list {
|
|
||||||
($generated:expr, $expected:expr, $position:expr) => {
|
|
||||||
assert_eq!(
|
|
||||||
$generated,
|
|
||||||
$expected,
|
|
||||||
"Difference: {:?}",
|
|
||||||
$generated
|
|
||||||
.symmetric_difference(&$expected)
|
|
||||||
.map(|mv| format!(
|
|
||||||
"{}",
|
|
||||||
$crate::r#move::AlgebraicMoveFormatter::new(mv, &$position)
|
|
||||||
))
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! formatted_move_list {
|
|
||||||
($move_list:expr, $position:expr) => {
|
|
||||||
$move_list
|
|
||||||
.iter()
|
|
||||||
.map(|mv| {
|
|
||||||
format!(
|
|
||||||
"{}",
|
|
||||||
$crate::r#move::AlgebraicMoveFormatter::new(mv, &$position)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
};
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue